Skip to content

Commit 1fb788c

Browse files
committed
Check for known LSP error code
1 parent 5b193a6 commit 1fb788c

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,26 +2209,14 @@ export class DefaultClient implements Client {
22092209
public async getIncludes(maxDepth: number, token: vscode.CancellationToken): Promise<GetIncludesResult> {
22102210
const params: GetIncludesParams = { maxDepth: maxDepth };
22112211
await this.ready;
2212-
return this.languageClient.sendRequest(IncludesRequest, params, token);
2212+
return DefaultClient.withLspCancellationHandling(
2213+
() => this.languageClient.sendRequest(IncludesRequest, params, token), token);
22132214
}
22142215

22152216
public async getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult> {
22162217
await withCancellation(this.ready, token);
2217-
let result: ChatContextResult;
2218-
try {
2219-
result = await this.languageClient.sendRequest(CppContextRequest, null, token);
2220-
} catch (e: any) {
2221-
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
2222-
throw new vscode.CancellationError();
2223-
}
2224-
2225-
throw e;
2226-
}
2227-
if (token.isCancellationRequested) {
2228-
throw new vscode.CancellationError();
2229-
}
2230-
2231-
return result;
2218+
return DefaultClient.withLspCancellationHandling(
2219+
() => this.languageClient.sendRequest(CppContextRequest, null, token), token);
22322220
}
22332221

22342222
/**
@@ -2310,6 +2298,26 @@ export class DefaultClient implements Client {
23102298
this.dispatching.resolve();
23112299
}
23122300

2301+
private static async withLspCancellationHandling<T>(task: () => Promise<T>, token: vscode.CancellationToken): Promise<T> {
2302+
let result: T;
2303+
2304+
try {
2305+
result = await task();
2306+
} catch (e: any) {
2307+
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
2308+
throw new vscode.CancellationError();
2309+
} else {
2310+
throw e;
2311+
}
2312+
}
2313+
2314+
if (token.isCancellationRequested) {
2315+
throw new vscode.CancellationError();
2316+
}
2317+
2318+
return result;
2319+
}
2320+
23132321
private callTaskWithTimeout<T>(task: () => Thenable<T>, ms: number, cancelToken?: vscode.CancellationTokenSource): Promise<T> {
23142322
let timer: NodeJS.Timeout;
23152323

0 commit comments

Comments
 (0)