@@ -804,9 +804,9 @@ export interface Client {
804804 getShowConfigureIntelliSenseButton ( ) : boolean ;
805805 setShowConfigureIntelliSenseButton ( show : boolean ) : void ;
806806 addTrustedCompiler ( path : string ) : Promise < void > ;
807- getIncludes ( maxDepth : number , token : vscode . CancellationToken ) : Promise < GetIncludesResult > ;
807+ getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
808808 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
809- getProjectContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ProjectContextResult > ;
809+ getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
810810}
811811
812812export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -2228,11 +2228,11 @@ export class DefaultClient implements Client {
22282228 await this . languageClient . sendNotification ( DidOpenNotification , params ) ;
22292229 }
22302230
2231- public async getIncludes ( maxDepth : number , token : vscode . CancellationToken ) : Promise < GetIncludesResult > {
2231+ public async getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > {
22322232 const params : GetIncludesParams = { maxDepth : maxDepth } ;
22332233 await this . ready ;
2234- return DefaultClient . withLspCancellationHandling (
2235- ( ) => this . languageClient . sendRequest ( IncludesRequest , params , token ) , token ) ;
2234+ return DefaultClient . withoutLspCancellationHandling (
2235+ ( ) => this . languageClient . sendRequest ( IncludesRequest , params ) ) ;
22362236 }
22372237
22382238 public async getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > {
@@ -2242,11 +2242,11 @@ export class DefaultClient implements Client {
22422242 ( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
22432243 }
22442244
2245- public async getProjectContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ProjectContextResult > {
2245+ public async getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > {
22462246 const params : TextDocumentIdentifier = { uri : uri . toString ( ) } ;
2247- await withCancellation ( this . ready , token ) ;
2248- return DefaultClient . withLspCancellationHandling (
2249- ( ) => this . languageClient . sendRequest ( ProjectContextRequest , params , token ) , token ) ;
2247+ await this . ready ;
2248+ return DefaultClient . withoutLspCancellationHandling (
2249+ ( ) => this . languageClient . sendRequest ( ProjectContextRequest , params ) ) ;
22502250 }
22512251
22522252 /**
@@ -2348,6 +2348,27 @@ export class DefaultClient implements Client {
23482348 return result ;
23492349 }
23502350
2351+ // This is used to avoid processing unnecessary LSP cancel requests during a Copilot completion
2352+ // when the result could still be used in 2 minutes in its cache before it sends another request.
2353+ private static async withoutLspCancellationHandling < T > ( task : ( ) => Promise < T > ) : Promise < T > {
2354+ let result : T ;
2355+
2356+ try {
2357+ result = await task ( ) ;
2358+ } catch ( e : any ) {
2359+ if ( e instanceof ResponseError && e . code === ServerCancelled ) {
2360+ // This can occur if the user switches files and makes edits fast enough.
2361+ // It doesn't seem like a very important scenario, so cancelling seems fine, even though
2362+ // not cancelling would allow the value to be cached if the user switches back to that file.
2363+ throw new vscode . CancellationError ( ) ;
2364+ } else {
2365+ throw e ;
2366+ }
2367+ }
2368+
2369+ return result ;
2370+ }
2371+
23512372 private callTaskWithTimeout < T > ( task : ( ) => Thenable < T > , ms : number , cancelToken ?: vscode . CancellationTokenSource ) : Promise < T > {
23522373 let timer : NodeJS . Timeout ;
23532374
@@ -4151,7 +4172,7 @@ class NullClient implements Client {
41514172 getShowConfigureIntelliSenseButton ( ) : boolean { return false ; }
41524173 setShowConfigureIntelliSenseButton ( show : boolean ) : void { }
41534174 addTrustedCompiler ( path : string ) : Promise < void > { return Promise . resolve ( ) ; }
4154- getIncludes ( maxDepth : number , token : vscode . CancellationToken ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
4175+ getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
41554176 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
4156- getProjectContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4177+ getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
41574178}
0 commit comments