Skip to content
Snippets Groups Projects
Commit da9beca6 authored by Stekelenburg, A.V. (Alexander, Student )'s avatar Stekelenburg, A.V. (Alexander, Student )
Browse files

Make the run button send the run tool command

parent c6818f63
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,17 @@
}
});
const runButton = document.getElementById("run-button");
runButton.addEventListener("click", event => {
const state = vscode.getState();
for (const file of state.constants) {
if (file.uri === state.currentUri) {
vscode.postMessage({type: "runTool", uri: state.currentUri, toolName: toolDropDown.options[toolDropDown.selectedIndex].value, constants: file.constants, options: []}); // TODO: Actually send option values
break;
}
}
});
function fillTools(tools) {
const select = document.querySelector("#tools");
......
......@@ -205,20 +205,20 @@ export function activate(context: ExtensionContext) {
(res: Result) => copyToClipboard(res.getValue())
);
vscode.commands.registerCommand(
vscode.commands.registerCommand(
"analysisResults.copyItem",
(res: Result) => copyToClipboard(`${res.getLabel()}: ${res.getValue()}`)
);
vscode.commands.registerCommand(
vscode.commands.registerCommand(
"analysisResults.load",
() => loadResults(analysisResultsProvider)
);
vscode.commands.registerCommand(
"analysisResults.export",
() => exportResults(analysisResultsProvider)
);
vscode.commands.registerCommand(
"analysisResults.export",
() => exportResults(analysisResultsProvider)
);
}
function initializeTools() {
......@@ -267,6 +267,18 @@ function getOptions(toolName: string) {
});
}
function runTool(uri: string, toolName: string, constants: { name: string; value: string; }[], options: {name: string; value: string;}[]) {
let jsonObject = {
"TextDocument": TextDocumentIdentifier.create(uri),
"ToolName": toolName,
"Constants": constants,
"Options": options,
};
client?.sendRequest<string>("modest/runTool", jsonObject).then(data => {
console.log(data);
});
}
export function deactivate(): Thenable<void> | undefined {
if (!client) {
......@@ -281,23 +293,23 @@ function copyToClipboard(text: string) {
}
function loadResults(provider: AnalysisResultsProvider) {
vscode.window.showOpenDialog().then(fileUri => {
if (fileUri) {
var fpath = fileUri[0].fsPath;
provider.setJsonPath(fpath);
vscode.window.showInformationMessage(`Opened ${fpath.split("/").pop()}.`);
} else {
vscode.window.showInformationMessage(`Could not open file.`);
}
});
vscode.window.showOpenDialog().then(fileUri => {
if (fileUri) {
var fpath = fileUri[0].fsPath;
provider.setJsonPath(fpath);
vscode.window.showInformationMessage(`Opened ${fpath.split("/").pop()}.`);
} else {
vscode.window.showInformationMessage(`Could not open file.`);
}
});
}
function exportResults(provider: AnalysisResultsProvider) {
vscode.window.showSaveDialog().then(f => {
if (f) {
fs.writeFileSync(f.path, JSON.stringify(provider.getJsonObject()));
}
});
vscode.window.showSaveDialog().then(f => {
if (f) {
fs.writeFileSync(f.path, JSON.stringify(provider.getJsonObject()));
}
});
}
class ModestSidebarProvider implements vscode.WebviewViewProvider {
......@@ -305,7 +317,7 @@ class ModestSidebarProvider implements vscode.WebviewViewProvider {
private _view?: vscode.WebviewView;
constructor(private readonly _extensionUri: vscode.Uri) {}
constructor(private readonly _extensionUri: vscode.Uri) { }
resolveWebviewView(
webviewView: vscode.WebviewView,
......@@ -344,6 +356,12 @@ class ModestSidebarProvider implements vscode.WebviewViewProvider {
getOptions(data.toolName);
break;
}
case 'runTool': {
console.log(data);
runTool(data.uri, data.toolName, data.constants, data.options);
break;
}
}
});
}
......@@ -367,7 +385,7 @@ class ModestSidebarProvider implements vscode.WebviewViewProvider {
const styleVSCodeUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'vscode.css'));
const styleMainUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'main.css'));
const styleCodicons = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'node_modules', 'vscode-codicons', 'dist', 'codicon.css'));
const fontCodicons = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'node_modules', 'vscode-codicons', 'dist', 'codicon.ttf'));
const fontCodicons = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'node_modules', 'vscode-codicons', 'dist', 'codicon.ttf'));
// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment