@@ -790,7 +790,7 @@ export interface Client {
790790 getShowConfigureIntelliSenseButton ( ) : boolean ;
791791 setShowConfigureIntelliSenseButton ( show : boolean ) : void ;
792792 addTrustedCompiler ( path : string ) : Promise < void > ;
793- getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
793+ getIncludes ( maxDepth : number , token : vscode . CancellationToken ) : Promise < GetIncludesResult > ;
794794 getChatContext ( token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
795795}
796796
@@ -2206,29 +2206,17 @@ export class DefaultClient implements Client {
22062206 await this . languageClient . sendNotification ( DidOpenNotification , params ) ;
22072207 }
22082208
2209- public async getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > {
2209+ 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 ) ;
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
@@ -4110,6 +4118,6 @@ class NullClient implements Client {
41104118 getShowConfigureIntelliSenseButton ( ) : boolean { return false ; }
41114119 setShowConfigureIntelliSenseButton ( show : boolean ) : void { }
41124120 addTrustedCompiler ( path : string ) : Promise < void > { return Promise . resolve ( ) ; }
4113- getIncludes ( ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
4121+ getIncludes ( maxDepth : number , token : vscode . CancellationToken ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
41144122 getChatContext ( token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
41154123}
0 commit comments