Skip to content

Commit

Permalink
drop undefined return type, and apply suggested cancellation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lukka committed Sep 5, 2024
1 parent ed21456 commit f3da72a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as fs from 'fs';
import * as os from 'os';
import { SourceFileConfiguration, SourceFileConfigurationItem, Version, WorkspaceBrowseConfiguration } from 'vscode-cpptools';
import { IntelliSenseStatus, Status } from 'vscode-cpptools/out/testApi';
import { CloseAction, DidOpenTextDocumentParams, ErrorAction, LanguageClientOptions, NotificationType, Position, Range, RequestType, TextDocumentIdentifier, TextDocumentPositionParams } from 'vscode-languageclient';
import { CloseAction, DidOpenTextDocumentParams, ErrorAction, LanguageClientOptions, NotificationType, Position, Range, RequestType, ResponseError, TextDocumentIdentifier, TextDocumentPositionParams } from 'vscode-languageclient';
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
import * as nls from 'vscode-nls';
import { DebugConfigurationProvider } from '../Debugger/configurationProvider';
Expand Down Expand Up @@ -801,7 +801,7 @@ export interface Client {
setShowConfigureIntelliSenseButton(show: boolean): void;
addTrustedCompiler(path: string): Promise<void>;
getIncludes(maxDepth: number): Promise<GetIncludesResult>;
getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult | undefined>;
getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult>;
}

export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
Expand Down Expand Up @@ -2244,12 +2244,20 @@ export class DefaultClient implements Client {
return this.languageClient.sendRequest(IncludesRequest, params);
}

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

// sendRequest() won't throw on cancellation, but will return an
// unexpected object with an error code and message.
throw e;
}
if (token.isCancellationRequested) {
throw new vscode.CancellationError();
}
Expand Down

0 comments on commit f3da72a

Please sign in to comment.