|
1 | 1 | 'use strict';
|
2 | 2 |
|
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"; |
4 | 4 | import { Commands } from "./commands";
|
5 | 5 | import { serverStatus, ServerStatusKind } from "./serverStatus";
|
6 | 6 | import { prepareExecutable, awaitServerConnection } from "./javaServerStarter";
|
@@ -263,15 +263,26 @@ export class StandardLanguageClient {
|
263 | 263 | }
|
264 | 264 | }));
|
265 | 265 |
|
266 |
| - context.subscriptions.push(commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile: boolean) => { |
| 266 | + context.subscriptions.push(commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile: boolean, token?: CancellationToken) => { |
267 | 267 | return window.withProgress({ location: ProgressLocation.Window }, async p => {
|
268 | 268 | if (typeof isFullCompile !== 'boolean') {
|
269 | 269 | const selection = await window.showQuickPick(['Incremental', 'Full'], { placeHolder: 'please choose compile type:' });
|
270 | 270 | isFullCompile = selection !== 'Incremental';
|
271 | 271 | }
|
272 | 272 | p.report({ message: 'Compiling workspace...' });
|
273 | 273 | 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 | + |
275 | 286 | const elapsed = new Date().getTime() - start;
|
276 | 287 | const humanVisibleDelay = elapsed < 1000 ? 1000 : 0;
|
277 | 288 | return new Promise((resolve, reject) => {
|
|
0 commit comments