Skip to content

Commit 5b193a6

Browse files
committed
Add cancellation token to react to Copilot API changes
1 parent 2431425 commit 5b193a6

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,10 +2206,10 @@ 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 this.languageClient.sendRequest(IncludesRequest, params, token);
22132213
}
22142214

22152215
public async getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult> {
@@ -4110,6 +4110,6 @@ class NullClient implements Client {
41104110
getShowConfigureIntelliSenseButton(): boolean { return false; }
41114111
setShowConfigureIntelliSenseButton(show: boolean): void { }
41124112
addTrustedCompiler(path: string): Promise<void> { return Promise.resolve(); }
4113-
getIncludes(): Promise<GetIncludesResult> { return Promise.resolve({} as GetIncludesResult); }
4113+
getIncludes(maxDepth: number, token: vscode.CancellationToken): Promise<GetIncludesResult> { return Promise.resolve({} as GetIncludesResult); }
41144114
getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult> { return Promise.resolve({} as ChatContextResult); }
41154115
}

Extension/src/LanguageServer/extension.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import { makeLspRange, rangeEquals, showInstallCompilerWalkthrough } from './uti
3636
interface CopilotApi {
3737
registerRelatedFilesProvider(
3838
providerId: { extensionId: string; languageId: string },
39-
callback: (uri: vscode.Uri) => Promise<{ entries: vscode.Uri[]; traits?: { name: string; value: string }[] }>
40-
): void;
39+
callback: (uri: vscode.Uri, token: vscode.CancellationToken) => Promise<{ entries: vscode.Uri[]; traits?: { name: string; value: string }[] }>
40+
): vscode.Disposable;
4141
}
4242

4343
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
@@ -270,8 +270,8 @@ export async function activate(): Promise<void> {
270270
for (const languageId of ['c', 'cpp', 'cuda-cpp']) {
271271
api.registerRelatedFilesProvider(
272272
{ extensionId: util.extensionContext.extension.id, languageId },
273-
async (_uri: vscode.Uri) =>
274-
({ entries: (await clients.ActiveClient.getIncludes(1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [] })
273+
async (_uri: vscode.Uri, token: vscode.CancellationToken) =>
274+
({ entries: (await clients.ActiveClient.getIncludes(1, token))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [] })
275275
);
276276
}
277277
} catch {
@@ -1403,7 +1403,9 @@ export async function preReleaseCheck(): Promise<void> {
14031403
}
14041404

14051405
export async function getIncludes(maxDepth: number): Promise<any> {
1406-
const includes = await clients.ActiveClient.getIncludes(maxDepth);
1406+
const tokenSource = new vscode.CancellationTokenSource();
1407+
const includes = await clients.ActiveClient.getIncludes(maxDepth, tokenSource.token);
1408+
tokenSource.dispose();
14071409
return includes;
14081410
}
14091411

0 commit comments

Comments
 (0)