Skip to content

Commit

Permalink
Check for known LSP error code
Browse files Browse the repository at this point in the history
  • Loading branch information
benmcmorran committed Sep 27, 2024
1 parent 5b193a6 commit 1fb788c
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2209,26 +2209,14 @@ export class DefaultClient implements Client {
public async getIncludes(maxDepth: number, token: vscode.CancellationToken): Promise<GetIncludesResult> {
const params: GetIncludesParams = { maxDepth: maxDepth };
await this.ready;
return this.languageClient.sendRequest(IncludesRequest, params, token);
return DefaultClient.withLspCancellationHandling(
() => this.languageClient.sendRequest(IncludesRequest, params, token), token);
}

public async getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult> {
await withCancellation(this.ready, token);
let result: ChatContextResult;
try {
result = await this.languageClient.sendRequest(CppContextRequest, null, token);
} catch (e: any) {
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
throw new vscode.CancellationError();
}

throw e;
}
if (token.isCancellationRequested) {
throw new vscode.CancellationError();
}

return result;
return DefaultClient.withLspCancellationHandling(
() => this.languageClient.sendRequest(CppContextRequest, null, token), token);
}

/**
Expand Down Expand Up @@ -2310,6 +2298,26 @@ export class DefaultClient implements Client {
this.dispatching.resolve();
}

private static async withLspCancellationHandling<T>(task: () => Promise<T>, token: vscode.CancellationToken): Promise<T> {
let result: T;

try {
result = await task();
} catch (e: any) {
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
throw new vscode.CancellationError();
} else {
throw e;
}
}

if (token.isCancellationRequested) {
throw new vscode.CancellationError();
}

return result;
}

private callTaskWithTimeout<T>(task: () => Thenable<T>, ms: number, cancelToken?: vscode.CancellationTokenSource): Promise<T> {
let timer: NodeJS.Timeout;

Expand Down

0 comments on commit 1fb788c

Please sign in to comment.