@@ -27,7 +27,7 @@ import * as fs from 'fs';
27
27
import * as os from 'os' ;
28
28
import { SourceFileConfiguration , SourceFileConfigurationItem , Version , WorkspaceBrowseConfiguration } from 'vscode-cpptools' ;
29
29
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' ;
31
31
import { LanguageClient , ServerOptions } from 'vscode-languageclient/node' ;
32
32
import * as nls from 'vscode-nls' ;
33
33
import { DebugConfigurationProvider } from '../Debugger/configurationProvider' ;
@@ -799,7 +799,7 @@ export interface Client {
799
799
setShowConfigureIntelliSenseButton ( show : boolean ) : void ;
800
800
addTrustedCompiler ( path : string ) : Promise < void > ;
801
801
getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
802
- getChatContext ( token : vscode . CancellationToken ) : Promise < ChatContextResult | undefined > ;
802
+ getChatContext ( token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
803
803
}
804
804
805
805
export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -2214,12 +2214,20 @@ export class DefaultClient implements Client {
2214
2214
return this . languageClient . sendRequest ( IncludesRequest , params ) ;
2215
2215
}
2216
2216
2217
- public async getChatContext ( token : vscode . CancellationToken ) : Promise < ChatContextResult | undefined > {
2217
+ public async getChatContext ( token : vscode . CancellationToken ) : Promise < ChatContextResult > {
2218
2218
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
+ }
2220
2228
2221
- // sendRequest() won't throw on cancellation, but will return an
2222
- // unexpected object with an error code and message.
2229
+ throw e ;
2230
+ }
2223
2231
if ( token . isCancellationRequested ) {
2224
2232
throw new vscode . CancellationError ( ) ;
2225
2233
}
0 commit comments