Skip to content

Commit 0d1aa41

Browse files
committed
drop undefined return type, and apply suggested cancellation logic
1 parent 76ec4f7 commit 0d1aa41

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import * as fs from 'fs';
2727
import * as os from 'os';
2828
import { SourceFileConfiguration, SourceFileConfigurationItem, Version, WorkspaceBrowseConfiguration } from 'vscode-cpptools';
2929
import { IntelliSenseStatus, Status } from 'vscode-cpptools/out/testApi';
30-
import { CloseAction, DidOpenTextDocumentParams, ErrorAction, LanguageClientOptions, NotificationType, Position, Range, RequestType, TextDocumentIdentifier } from 'vscode-languageclient';
30+
import { CloseAction, DidOpenTextDocumentParams, ErrorAction, LanguageClientOptions, NotificationType, Position, Range, RequestType, ResponseError, TextDocumentIdentifier } from 'vscode-languageclient';
3131
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
3232
import * as nls from 'vscode-nls';
3333
import { DebugConfigurationProvider } from '../Debugger/configurationProvider';
@@ -799,7 +799,7 @@ export interface Client {
799799
setShowConfigureIntelliSenseButton(show: boolean): void;
800800
addTrustedCompiler(path: string): Promise<void>;
801801
getIncludes(maxDepth: number): Promise<GetIncludesResult>;
802-
getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult | undefined>;
802+
getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult>;
803803
}
804804

805805
export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
@@ -2214,12 +2214,20 @@ export class DefaultClient implements Client {
22142214
return this.languageClient.sendRequest(IncludesRequest, params);
22152215
}
22162216

2217-
public async getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult | undefined> {
2217+
public async getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult> {
22182218
await withCancellation(this.ready, token);
2219-
const result = await this.languageClient.sendRequest(CppContextRequest, null, token);
2219+
let result: ChatContextResult;
2220+
try {
2221+
result = await this.languageClient.sendRequest(CppContextRequest, null, token);
2222+
} catch (e: any) {
2223+
// From <https://microsoft.github.io/language-server-protocol/specification#responseMessage>
2224+
// RequestCancelled = -32800, ServerCancelled = -32802,
2225+
if (e instanceof ResponseError && (e.code === -32800 /*RequestCancelled*/ || e.code === -32802 /*ServerCancelled*/)) {
2226+
throw new vscode.CancellationError();
2227+
}
22202228

2221-
// sendRequest() won't throw on cancellation, but will return an
2222-
// unexpected object with an error code and message.
2229+
throw e;
2230+
}
22232231
if (token.isCancellationRequested) {
22242232
throw new vscode.CancellationError();
22252233
}

0 commit comments

Comments
 (0)