diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 2b1b8125b..04dcaba70 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -529,7 +529,7 @@ interface GetIncludesParams { maxDepth: number; } -interface GetIncludesResult { +export interface GetIncludesResult { includedFiles: string[]; } diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index 972c0e8b8..47a7cd034 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -20,7 +20,7 @@ import * as util from '../common'; import { getCrashCallStacksChannel } from '../logger'; import { PlatformInformation } from '../platform'; import * as telemetry from '../telemetry'; -import { Client, DefaultClient, DoxygenCodeActionCommandArguments, openFileVersions } from './client'; +import { Client, DefaultClient, DoxygenCodeActionCommandArguments, GetIncludesResult, openFileVersions } from './client'; import { ClientCollection } from './clientCollection'; import { CodeActionDiagnosticInfo, CodeAnalysisDiagnosticIdentifiersAndUri, codeAnalysisAllFixes, codeAnalysisCodeToFixes, codeAnalysisFileToCodeActions } from './codeAnalysis'; import { CppBuildTaskProvider } from './cppBuildTaskProvider'; @@ -282,7 +282,7 @@ export async function activate(): Promise { api.registerRelatedFilesProvider( { extensionId: util.extensionContext.extension.id, languageId }, async (_uri: vscode.Uri, _context: { flags: Record }, token: vscode.CancellationToken) => - ({ entries: (await clients.ActiveClient.getIncludes(1, token))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [] }) + ({ entries: (await getIncludesWithCancellation(1, token))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [] }) ); } } catch { @@ -1413,13 +1413,28 @@ export async function preReleaseCheck(): Promise { } } -export async function getIncludes(maxDepth: number): Promise { - const tokenSource = new vscode.CancellationTokenSource(); - const includes = await clients.ActiveClient.getIncludes(maxDepth, tokenSource.token); - tokenSource.dispose(); +export async function getIncludesWithCancellation(maxDepth: number, token: vscode.CancellationToken): Promise { + const includes = await clients.ActiveClient.getIncludes(maxDepth, token); + const wksFolder = clients.ActiveClient.RootUri?.toString(); + + if (!wksFolder) { + return includes; + } + + includes.includedFiles = includes.includedFiles.filter(header => vscode.Uri.file(header).toString().startsWith(wksFolder)); return includes; } +async function getIncludes(maxDepth: number): Promise { + const tokenSource = new vscode.CancellationTokenSource(); + try { + const includes = await getIncludesWithCancellation(maxDepth, tokenSource.token); + return includes; + } finally { + tokenSource.dispose(); + } +} + async function getCopilotApi(): Promise { const copilotExtension = vscode.extensions.getExtension('github.copilot'); if (!copilotExtension) {