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

Fix a bug where constants were deleted and allow tool run to be awaited asynchronously

parent dac0e0e3
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@
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
vscode.postMessage({ type: "runTool", uri: state.currentUri, toolName: toolDropDown.options[toolDropDown.selectedIndex].value, constants: file.constants, options: [] }); // TODO: Actually send option values
break;
}
}
......@@ -60,7 +60,7 @@
}
const oldState = vscode.getState() || { tools: [], constants: [], options: [] };
vscode.setState({ tools: tools, constants: oldState.constants, options: oldState.options });
vscode.setState({ tools: tools, constants: oldState.constants, options: oldState.options, currentUri: oldState.currentUri });
}
function addConstantItem(ul, name, value) {
......@@ -131,9 +131,9 @@
const oldState = vscode.getState();
for (const file of constants) {
for (const constant of file.constants) {
const index = oldState.constants.findIndex(x => x.uri === file.uri);
if (index !== -1) {
const index = oldState.constants.findIndex(x => x.uri === file.uri);
if (index !== -1) {
for (const constant of file.constants) {
const oldConstantIndex = oldState.constants[index].constants.findIndex(x => x.name === constant.name);
if (oldConstantIndex !== -1) {
constant.value = oldState.constants[index].constants[oldConstantIndex].value;
......@@ -142,7 +142,14 @@
}
}
constantsUl.innerHTML = "";
for (const file of oldState.constants) {
const index = constants.findIndex(x => x.uri === file.uri);
if (index === -1) {
constants.push(file);
}
}
constantsUl.innerHTML = "";
for (const file of constants) {
if (file.uri === uri) {
for (const constant of file.constants) {
......
......@@ -10,13 +10,17 @@ import {
} from "vscode";
import * as vscode from "vscode";
import {
CancellationTokenSource,
DocumentFormattingParams,
DocumentFormattingRegistrationOptions,
DocumentFormattingRequest,
FormattingOptions,
LanguageClient,
LanguageClientOptions,
NotificationType,
ProgressType,
ProtocolNotificationType,
ProtocolNotificationType0,
ServerOptions,
TextDocumentIdentifier,
TextEdit,
......@@ -211,7 +215,7 @@ export function activate(context: ExtensionContext) {
(res: Result) => copyToClipboard(`${res.getLabel()}: ${res.getValue()}`)
);
vscode.commands.registerCommand(
vscode.commands.registerCommand(
"analysisResults.openInEditor",
(res: Result) => openInEditor(analysisResultsProvider, res)
);
......@@ -278,6 +282,11 @@ interface ProgressIndication {
progress: number
}
interface ResultNotification {
progressToken: string,
data: string
}
function runTool(uri: string, toolName: string, constants: { name: string; value: string; }[], options: { name: string; value: string; }[]) {
let jsonObject = {
textDocument: TextDocumentIdentifier.create(uri),
......@@ -287,13 +296,20 @@ function runTool(uri: string, toolName: string, constants: { name: string; value
progressToken: uri + toolName + constants + options + Date.now()
};
vscode.window.activeTextEditor?.document.save();
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, cancellable: false, title: "Running modest tool" }, async (progress, token) => {
let progressHandler = client?.onProgress(new ProgressType<ProgressIndication>(), jsonObject.progressToken, indication => {
progress.report({ message: indication.message, increment: indication.progress * 100 });
});
await client?.sendRequest<string>("modest/runTool", jsonObject).then(data => {
analysisResultsProvider.setJsonString(data);
progressHandler?.dispose();
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, cancellable: false, title: "Running " + toolName }, async (progress, token) => {
await new Promise<null>(async (resolve, _) => {
let progressHandler = client?.onProgress(new ProgressType<ProgressIndication>(), jsonObject.progressToken, indication => {
progress.report({ message: indication.message, increment: indication.progress * 100 });
});
let resultHandler = client?.onNotification(new NotificationType<ResultNotification>("modest/toolResult"), data => {
if (data.progressToken === jsonObject.progressToken) {
analysisResultsProvider.setJsonString(data.data);
progressHandler?.dispose();
resultHandler?.dispose();
resolve(null);
}
});
await client?.sendRequest<string>("modest/runTool", jsonObject, token);
});
});
}
......
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