Skip to content

Commit b6585af

Browse files
committed
Squash folding ranges cancellation bug
1 parent d07b8b4 commit b6585af

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

server/src/project/workspace.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ class WorkspaceEvents {
302302
const cancellableOnDocSymbol = returnDefaultOnCancelClientRequest(
303303
(p: DocumentSymbolParams, t) => this.onDocumentSymbolAsync(p, t), [], 'Document Symbols');
304304

305-
const cancellableOnFoldingRanges = returnDefaultOnCancelClientRequest(
306-
(p: FoldingRangeParams, t) => this.onFoldingRangesAsync(p, t), [], 'Folding Range');
307-
308305
connection.onCodeAction(async (params, token) => this.onCodeActionRequest(params, token));
309306
connection.onCompletion(params => this.onCompletion(params));
310307
connection.onCompletionResolve(item => this.onCompletionResolve(item));
@@ -319,7 +316,7 @@ class WorkspaceEvents {
319316
connection.onRenameRequest((params, token) => this.onRenameRequest(params, token));
320317

321318
if (hasWorkspaceConfigurationCapability(Services.server)) {
322-
connection.onFoldingRanges(async (params, token) => await cancellableOnFoldingRanges(params, token));
319+
connection.onFoldingRanges(async (params, token) => await this.onFoldingRangesAsync(params, token));
323320
}
324321

325322
connection.onRequest((method: string, params: object | object[] | any) => {
@@ -395,18 +392,33 @@ class WorkspaceEvents {
395392
return document?.languageServerSymbolInformation() ?? [];
396393
}
397394

398-
private async onFoldingRangesAsync(params: FoldingRangeParams, token: CancellationToken): Promise<FoldingRange[]> {
395+
private async onFoldingRangesAsync(params: FoldingRangeParams, token: CancellationToken): Promise<FoldingRange[] | undefined> {
399396
const logger = Services.logger;
400397
logger.debug('[Event] onFoldingRanges');
398+
399+
// Don't do any work if we don't have to.
400+
if (token.isCancellationRequested) {
401+
logger.debug('Cancellation requested before start for Folding Ranges.');
402+
return;
403+
}
404+
401405
let document: BaseProjectDocument | undefined;
402406
try {
403-
document = await this.getParsedProjectDocument(params.textDocument.uri, 0, token);
407+
const normalisedUri = params.textDocument.uri.toFilePath().toFileUri();
408+
document = await this.getParsedProjectDocument(normalisedUri, 0, token);
404409
} catch (error) {
405410
// Swallow parser cancellations and rethrow anything else.
406411
if (error instanceof ParseCancellationException) {
407412
throw error;
408413
}
409414
}
415+
416+
// Check again if we're cancelled.
417+
if (token.isCancellationRequested) {
418+
logger.debug('Cancellation requested before start for Folding Ranges.');
419+
return;
420+
}
421+
410422
const result = document?.languageServerFoldingRanges();
411423
for (const foldingRange of result ?? []) {
412424
logger.debug(`${JSON.stringify(foldingRange.range)} '${foldingRange.openWord}..${foldingRange.closeWord}'`, 1);

0 commit comments

Comments
 (0)