Skip to content

Commit 3c65a2e

Browse files
Pass the cancellationtoken to the client request registered by provider (#1668)
Signed-off-by: Jinbo Wang <[email protected]>
1 parent ec6a5c2 commit 3c65a2e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/providerDispatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class ClientHoverProvider implements HoverProvider {
5151
textDocument: languageClient.code2ProtocolConverter.asTextDocumentIdentifier(document),
5252
position: languageClient.code2ProtocolConverter.asPosition(position)
5353
};
54-
const hoverResponse = await languageClient.sendRequest(HoverRequest.type, params);
54+
const hoverResponse = await languageClient.sendRequest(HoverRequest.type, params, token);
5555
return languageClient.protocol2CodeConverter.asHover(hoverResponse);
5656
}
5757
}
@@ -86,7 +86,7 @@ function createDocumentSymbolProvider(): DocumentSymbolProvider {
8686
const params = {
8787
textDocument: languageClient.code2ProtocolConverter.asTextDocumentIdentifier(document),
8888
};
89-
const symbolResponse = await languageClient.sendRequest(DocumentSymbolRequest.type, params);
89+
const symbolResponse = await languageClient.sendRequest(DocumentSymbolRequest.type, params, token);
9090
if (!symbolResponse || !symbolResponse.length) {
9191
return [];
9292
}

src/standardLanguageClient.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind } from "vscode";
3+
import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind, CancellationToken } from "vscode";
44
import { Commands } from "./commands";
55
import { serverStatus, ServerStatusKind } from "./serverStatus";
66
import { prepareExecutable, awaitServerConnection } from "./javaServerStarter";
@@ -263,15 +263,26 @@ export class StandardLanguageClient {
263263
}
264264
}));
265265

266-
context.subscriptions.push(commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile: boolean) => {
266+
context.subscriptions.push(commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile: boolean, token?: CancellationToken) => {
267267
return window.withProgress({ location: ProgressLocation.Window }, async p => {
268268
if (typeof isFullCompile !== 'boolean') {
269269
const selection = await window.showQuickPick(['Incremental', 'Full'], { placeHolder: 'please choose compile type:' });
270270
isFullCompile = selection !== 'Incremental';
271271
}
272272
p.report({ message: 'Compiling workspace...' });
273273
const start = new Date().getTime();
274-
const res = await this.languageClient.sendRequest(CompileWorkspaceRequest.type, isFullCompile);
274+
let res: CompileWorkspaceStatus;
275+
try {
276+
res = token ? await this.languageClient.sendRequest(CompileWorkspaceRequest.type, isFullCompile, token)
277+
: await this.languageClient.sendRequest(CompileWorkspaceRequest.type, isFullCompile);
278+
} catch (error) {
279+
if (error && error.code === -32800) { // Check if the request is cancelled.
280+
res = CompileWorkspaceStatus.CANCELLED;
281+
} else {
282+
throw error;
283+
}
284+
}
285+
275286
const elapsed = new Date().getTime() - start;
276287
const humanVisibleDelay = elapsed < 1000 ? 1000 : 0;
277288
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)