From afb208dabbe747706b1c9b95b9f21a0aa39f5f00 Mon Sep 17 00:00:00 2001 From: Luca <681992+lukka@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:30:51 -0800 Subject: [PATCH] get isense client by uri (#13059) --- Extension/src/LanguageServer/client.ts | 9 +++++---- Extension/src/LanguageServer/copilotProviders.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index d1f0cb8c90..47e5d28219 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -527,6 +527,7 @@ interface DidChangeActiveEditorParams { } interface GetIncludesParams { + fileUri: string; maxDepth: number; } @@ -827,7 +828,7 @@ export interface Client { setShowConfigureIntelliSenseButton(show: boolean): void; addTrustedCompiler(path: string): Promise; getCopilotHoverProvider(): CopilotHoverProvider | undefined; - getIncludes(maxDepth: number): Promise; + getIncludes(uri: vscode.Uri, maxDepth: number): Promise; getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise; getProjectContext(uri: vscode.Uri): Promise; filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void; @@ -2291,8 +2292,8 @@ export class DefaultClient implements Client { * the UI results and always re-requests (no caching). */ - public async getIncludes(maxDepth: number): Promise { - const params: GetIncludesParams = { maxDepth: maxDepth }; + public async getIncludes(uri: vscode.Uri, maxDepth: number): Promise { + const params: GetIncludesParams = { fileUri: uri.toString(), maxDepth }; await this.ready; return this.languageClient.sendRequest(IncludesRequest, params); } @@ -4235,7 +4236,7 @@ class NullClient implements Client { setShowConfigureIntelliSenseButton(show: boolean): void { } addTrustedCompiler(path: string): Promise { return Promise.resolve(); } getCopilotHoverProvider(): CopilotHoverProvider | undefined { return undefined; } - getIncludes(maxDepth: number): Promise { return Promise.resolve({} as GetIncludesResult); } + getIncludes(uri: vscode.Uri, maxDepth: number): Promise { return Promise.resolve({} as GetIncludesResult); } getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise { return Promise.resolve({} as ChatContextResult); } getProjectContext(uri: vscode.Uri): Promise { return Promise.resolve({} as ProjectContextResult); } filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void { } diff --git a/Extension/src/LanguageServer/copilotProviders.ts b/Extension/src/LanguageServer/copilotProviders.ts index a78fdfa5b6..ce232865fa 100644 --- a/Extension/src/LanguageServer/copilotProviders.ts +++ b/Extension/src/LanguageServer/copilotProviders.ts @@ -10,7 +10,7 @@ import * as util from '../common'; import * as logger from '../logger'; import * as telemetry from '../telemetry'; import { GetIncludesResult } from './client'; -import { getActiveClient } from './extension'; +import { getClients } from './extension'; import { getCompilerArgumentFilterMap, getProjectContext } from './lmTool'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); @@ -46,7 +46,7 @@ export async function registerRelatedFilesProvider(): Promise { const telemetryProperties: Record = {}; const telemetryMetrics: Record = {}; try { - const getIncludesHandler = async () => (await getIncludes(1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? []; + const getIncludesHandler = async () => (await getIncludes(uri, 1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? []; const getTraitsHandler = async () => { const projectContext = await getProjectContext(uri, context); @@ -157,10 +157,10 @@ export async function registerRelatedFilesProvider(): Promise { } } -async function getIncludes(maxDepth: number): Promise { - const activeClient = getActiveClient(); - const includes = await activeClient.getIncludes(maxDepth); - const wksFolder = activeClient.RootUri?.toString(); +async function getIncludes(uri: vscode.Uri, maxDepth: number): Promise { + const client = getClients().getClientFor(uri); + const includes = await client.getIncludes(uri, maxDepth); + const wksFolder = client.RootUri?.toString(); if (!wksFolder) { return includes;