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

Add a global list of progressHandlers

parent c80a367f
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import {
import {
LanguageClient,
LanguageClientOptions,
NotificationType,
ServerOptions,
State,
Trace,
......@@ -15,6 +16,7 @@ import {
import { AnalysisResultsProvider, Result } from "./analysisResults";
import { ModestCommands } from "./commands";
import { getDocumentVars, initializeTools, ModestSidebarProvider } from "./sidebar";
import { ResultNotification } from "./utils";
export let client: LanguageClient | undefined;
export let provider: ModestSidebarProvider;
......@@ -24,6 +26,7 @@ export let treeView: vscode.TreeView<Result>;
export let extensionUri: vscode.Uri;
export let clientReady: boolean = false;
export let disposalQueue: Array<vscode.Disposable> = [];
export let resultHandlers: Array<(notification: ResultNotification) => void> = [];
export function modestExecutable(): string | undefined {
let executable: string | undefined = vscode.workspace
......@@ -126,7 +129,13 @@ function createClient(): LanguageClient | undefined {
client.onReady().then(() => {
initializeTools();
clientReady = true;
client.onNotification(new NotificationType<ResultNotification>("modest/toolResult"), result => {
resultHandlers.forEach(handler => {
handler(result);
});
});
});
return client;
}
......
......@@ -8,7 +8,7 @@ import {
ProgressType,
TextDocumentIdentifier
} from "vscode-languageclient/node";
import { analysisResultsProvider, client, clientReady, disposalQueue, provider, treeView } from './extension';
import { analysisResultsProvider, client, clientReady, disposalQueue, provider, resultHandlers, treeView } from './extension';
import { ParameterDefinitions, ProgressIndication, ResultNotification, getNonce } from "./utils";
let localToolNames: Array<string> | undefined;
......@@ -125,7 +125,7 @@ function runTool(uri: string, toolName: string, constants: { name: string; value
progress.report({ message: indication.message, increment: indication.progress * 100 });
});
if (progressHandler) { disposalQueue.push(progressHandler); }
let resultHandler = client?.onNotification(new NotificationType<ResultNotification>("modest/toolResult"), data => {
let resultHandler = (data: ResultNotification) => {
if (data.progressToken === jsonObject.progressToken) {
if (data.data && data.data !== "") {
try {
......@@ -146,14 +146,15 @@ function runTool(uri: string, toolName: string, constants: { name: string; value
}
}
progressHandler?.dispose();
resultHandler?.dispose();
resultHandlers.splice(resultHandlers.indexOf(resultHandler), 1);
resolve(null);
}
});
if (resultHandler) { disposalQueue.push(resultHandler); }
};
resultHandlers.push(resultHandler);
disposalQueue.push({
dispose: function () {
vscode.window.showErrorMessage("Language server restarting, operation cancelled");
resultHandlers.splice(resultHandlers.indexOf(resultHandler), 1);
resolve(null);
token.isCancellationRequested = true;
}
......
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