Skip to content

Commit

Permalink
Handle CancellationError gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Jul 11, 2024
1 parent c39f548 commit ff3e0b2
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/lsptoolshost/services/projectContextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,13 @@ export class ProjectContextService {
this._source.cancel();
this._source = new vscode.CancellationTokenSource();

try {
const contextList = await this.getProjectContexts(uri, this._source.token);
if (!contextList) {
return;
}

const context = contextList._vs_projectContexts[contextList._vs_defaultIndex];
this._contextChangeEmitter.fire({ uri, context });
} catch {
// This request was cancelled
const contextList = await this.getProjectContexts(uri, this._source.token);
if (!contextList) {
return;
}

const context = contextList._vs_projectContexts[contextList._vs_defaultIndex];
this._contextChangeEmitter.fire({ uri, context });
}

private async getProjectContexts(
Expand All @@ -69,10 +65,18 @@ export class ProjectContextService {
const uriString = UriConverter.serialize(uri);
const textDocument = TextDocumentIdentifier.create(uriString);

return this._languageServer.sendRequest(
VSGetProjectContextsRequest.type,
{ _vs_textDocument: textDocument },
token
);
try {
return this._languageServer.sendRequest(
VSGetProjectContextsRequest.type,
{ _vs_textDocument: textDocument },
token
);
} catch (error) {
if (error instanceof vscode.CancellationError) {
return undefined;
}

throw error;
}
}
}

0 comments on commit ff3e0b2

Please sign in to comment.