Skip to content

Commit d298adf

Browse files
committed
Remove other cancel handling.
1 parent a39b6ca commit d298adf

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

812812
export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
@@ -2228,11 +2228,10 @@ 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 this.languageClient.sendRequest(IncludesRequest, params);
22362235
}
22372236

22382237
public async getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise<ChatContextResult> {
@@ -2242,11 +2241,10 @@ export class DefaultClient implements Client {
22422241
() => this.languageClient.sendRequest(CppContextRequest, params, token), token);
22432242
}
22442243

2245-
public async getProjectContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise<ProjectContextResult> {
2244+
public async getProjectContext(uri: vscode.Uri): Promise<ProjectContextResult> {
22462245
const params: TextDocumentIdentifier = { uri: uri.toString() };
2247-
await withCancellation(this.ready, token);
2248-
return DefaultClient.withLspCancellationHandling(
2249-
() => this.languageClient.sendRequest(ProjectContextRequest, params, token), token);
2246+
await this.ready;
2247+
return this.languageClient.sendRequest(ProjectContextRequest, params);
22502248
}
22512249

22522250
/**
@@ -2340,11 +2338,8 @@ export class DefaultClient implements Client {
23402338
throw e;
23412339
}
23422340
}
2343-
2344-
// Don't cancel if the result has already been computed, because the result might still be usable
2345-
// without needing to send an unnecessary re-request, which is the case for the callback to registerRelatedFilesProvider.
23462341
if (token.isCancellationRequested) {
2347-
return result; // throw new vscode.CancellationError();
2342+
throw new vscode.CancellationError();
23482343
}
23492344

23502345
return result;
@@ -4153,7 +4148,7 @@ class NullClient implements Client {
41534148
getShowConfigureIntelliSenseButton(): boolean { return false; }
41544149
setShowConfigureIntelliSenseButton(show: boolean): void { }
41554150
addTrustedCompiler(path: string): Promise<void> { return Promise.resolve(); }
4156-
getIncludes(maxDepth: number, token: vscode.CancellationToken): Promise<GetIncludesResult> { return Promise.resolve({} as GetIncludesResult); }
4151+
getIncludes(maxDepth: number): Promise<GetIncludesResult> { return Promise.resolve({} as GetIncludesResult); }
41574152
getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise<ChatContextResult> { return Promise.resolve({} as ChatContextResult); }
4158-
getProjectContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise<ProjectContextResult> { return Promise.resolve({} as ProjectContextResult); }
4153+
getProjectContext(uri: vscode.Uri): Promise<ProjectContextResult> { return Promise.resolve({} as ProjectContextResult); }
41594154
}

Extension/src/LanguageServer/copilotProviders.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export async function registerRelatedFilesProvider(): Promise<void> {
3838
for (const languageId of ['c', 'cpp', 'cuda-cpp']) {
3939
api.registerRelatedFilesProvider(
4040
{ extensionId: util.extensionContext.extension.id, languageId },
41-
async (uri: vscode.Uri, context: { flags: Record<string, unknown> }, token: vscode.CancellationToken) => {
41+
async (uri: vscode.Uri, context: { flags: Record<string, unknown> }) => {
4242
const start = performance.now();
4343
const telemetryProperties: Record<string, string> = {};
4444
const telemetryMetrics: Record<string, number> = {};
4545
try {
46-
const getIncludesHandler = async () => (await getIncludesWithCancellation(1, token))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [];
46+
const getIncludesHandler = async () => (await getIncludes(1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [];
4747
const getTraitsHandler = async () => {
48-
const projectContext = await getProjectContext(uri, context, token);
48+
const projectContext = await getProjectContext(uri, context);
4949

5050
if (!projectContext) {
5151
return undefined;
@@ -154,9 +154,9 @@ export async function registerRelatedFilesProvider(): Promise<void> {
154154
}
155155
}
156156

157-
async function getIncludesWithCancellation(maxDepth: number, token: vscode.CancellationToken): Promise<GetIncludesResult> {
157+
async function getIncludes(maxDepth: number): Promise<GetIncludesResult> {
158158
const activeClient = getActiveClient();
159-
const includes = await activeClient.getIncludes(maxDepth, token);
159+
const includes = await activeClient.getIncludes(maxDepth);
160160
const wksFolder = activeClient.RootUri?.toString();
161161

162162
if (!wksFolder) {

Extension/src/LanguageServer/lmTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ function filterCompilerArguments(compiler: string, compilerArguments: string[],
127127
return result;
128128
}
129129

130-
export async function getProjectContext(uri: vscode.Uri, context: { flags: Record<string, unknown> }, token: vscode.CancellationToken): Promise<ProjectContext | undefined> {
130+
export async function getProjectContext(uri: vscode.Uri, context: { flags: Record<string, unknown> }): Promise<ProjectContext | undefined> {
131131
const telemetryProperties: Record<string, string> = {};
132132
const telemetryMetrics: Record<string, number> = {};
133133
try {
134-
const projectContext = await checkDuration<ProjectContextResult | undefined>(async () => await getClients()?.ActiveClient?.getProjectContext(uri, token) ?? undefined);
134+
const projectContext = await checkDuration<ProjectContextResult | undefined>(async () => await getClients()?.ActiveClient?.getProjectContext(uri) ?? undefined);
135135
telemetryMetrics["duration"] = projectContext.duration;
136136
if (!projectContext.result) {
137137
return undefined;

Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
130130
});
131131

132132
const arrangeChatContextFromCppTools = ({ chatContextFromCppTools, isCpp, isHeaderFile }:
133-
{ chatContextFromCppTools?: ChatContextResult; isCpp?: boolean; isHeaderFile?: boolean } =
134-
{ chatContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false }
133+
{ chatContextFromCppTools?: ChatContextResult; isCpp?: boolean; isHeaderFile?: boolean } =
134+
{ chatContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false }
135135
) => {
136136
activeClientStub.getChatContext.resolves(chatContextFromCppTools);
137137
sinon.stub(util, 'isCpp').returns(isCpp ?? true);
138138
sinon.stub(util, 'isHeaderFile').returns(isHeaderFile ?? false);
139139
};
140140

141141
const arrangeProjectContextFromCppTools = ({ projectContextFromCppTools, isCpp, isHeaderFile }:
142-
{ projectContextFromCppTools?: ProjectContextResult; isCpp?: boolean; isHeaderFile?: boolean } =
143-
{ projectContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false }
142+
{ projectContextFromCppTools?: ProjectContextResult; isCpp?: boolean; isHeaderFile?: boolean } =
143+
{ projectContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false }
144144
) => {
145145
activeClientStub.getProjectContext.resolves(projectContextFromCppTools);
146146
sinon.stub(util, 'isCpp').returns(isCpp ?? true);
@@ -200,7 +200,7 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
200200
}
201201
});
202202

203-
const result = await getProjectContext(mockTextDocumentStub.uri, context, new vscode.CancellationTokenSource().token);
203+
const result = await getProjectContext(mockTextDocumentStub.uri, context);
204204

205205
ok(result, 'result should not be undefined');
206206
ok(result.language === 'C++');
@@ -364,7 +364,7 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
364364
}
365365
});
366366

367-
const result = await getProjectContext(mockTextDocumentStub.uri, { flags: {} }, new vscode.CancellationTokenSource().token);
367+
const result = await getProjectContext(mockTextDocumentStub.uri, { flags: {} });
368368

369369
ok(telemetryStub.calledOnce, 'Telemetry should be called once');
370370
ok(telemetryStub.calledWithMatch('ProjectContext', sinon.match({

0 commit comments

Comments
 (0)