Skip to content

Commit 751fd74

Browse files
authored
Add a command to fetch the includes graph for a TU (#12085)
1 parent 3dfa607 commit 751fd74

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,16 @@ interface DidChangeActiveEditorParams {
536536
selection?: Range;
537537
}
538538

539+
interface GetIncludesParams
540+
{
541+
maxDepth: number;
542+
}
543+
544+
interface GetIncludesResult
545+
{
546+
includedFiles: string[];
547+
}
548+
539549
// Requests
540550
const InitializationRequest: RequestType<CppInitializationParams, string, void> = new RequestType<CppInitializationParams, string, void>('cpptools/initialize');
541551
const QueryCompilerDefaultsRequest: RequestType<QueryDefaultCompilerParams, configs.CompilerDefaults, void> = new RequestType<QueryDefaultCompilerParams, configs.CompilerDefaults, void>('cpptools/queryCompilerDefaults');
@@ -553,6 +563,7 @@ const ExtractToFunctionRequest: RequestType<ExtractToFunctionParams, WorkspaceEd
553563
const GoToDirectiveInGroupRequest: RequestType<GoToDirectiveInGroupParams, Position | undefined, void> = new RequestType<GoToDirectiveInGroupParams, Position | undefined, void>('cpptools/goToDirectiveInGroup');
554564
const GenerateDoxygenCommentRequest: RequestType<GenerateDoxygenCommentParams, GenerateDoxygenCommentResult | undefined, void> = new RequestType<GenerateDoxygenCommentParams, GenerateDoxygenCommentResult, void>('cpptools/generateDoxygenComment');
555565
const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> = new RequestType<CppPropertiesParams, void, void>('cpptools/didChangeCppProperties');
566+
const IncludesRequest: RequestType<GetIncludesParams, GetIncludesResult, void> = new RequestType<GetIncludesParams, GetIncludesResult, void>('cpptools/getIncludes');
556567

557568
// Notifications to the server
558569
const DidOpenNotification: NotificationType<DidOpenTextDocumentParams> = new NotificationType<DidOpenTextDocumentParams>('textDocument/didOpen');
@@ -781,6 +792,7 @@ export interface Client {
781792
getShowConfigureIntelliSenseButton(): boolean;
782793
setShowConfigureIntelliSenseButton(show: boolean): void;
783794
addTrustedCompiler(path: string): Promise<void>;
795+
getIncludes(maxDepth: number): Promise<GetIncludesResult>;
784796
}
785797

786798
export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
@@ -2190,6 +2202,12 @@ export class DefaultClient implements Client {
21902202
await this.languageClient.sendNotification(DidOpenNotification, params);
21912203
}
21922204

2205+
public async getIncludes(maxDepth: number): Promise<GetIncludesResult> {
2206+
const params: GetIncludesParams = { maxDepth: maxDepth };
2207+
await this.ready;
2208+
return this.languageClient.sendRequest(IncludesRequest, params);
2209+
}
2210+
21932211
/**
21942212
* a Promise that can be awaited to know when it's ok to proceed.
21952213
*
@@ -4012,4 +4030,5 @@ class NullClient implements Client {
40124030
getShowConfigureIntelliSenseButton(): boolean { return false; }
40134031
setShowConfigureIntelliSenseButton(show: boolean): void { }
40144032
addTrustedCompiler(path: string): Promise<void> { return Promise.resolve(); }
4033+
getIncludes(): Promise<GetIncludesResult> { return Promise.resolve({} as GetIncludesResult); }
40154034
}

Extension/src/LanguageServer/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ export function registerCommands(enabled: boolean): void {
401401
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ExtractToFreeFunction', enabled ? () => onExtractToFunction(true, false) : onDisabledCommand));
402402
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ExtractToMemberFunction', enabled ? () => onExtractToFunction(false, true) : onDisabledCommand));
403403
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ExpandSelection', enabled ? (r: Range) => onExpandSelection(r) : onDisabledCommand));
404+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.getIncludes', enabled ? (maxDepth: number) => getIncludes(maxDepth) : onDisabledCommand));
404405
}
405406

406407
function onDisabledCommand() {
@@ -1305,3 +1306,7 @@ export async function preReleaseCheck(): Promise<void> {
13051306
}
13061307
}
13071308
}
1309+
1310+
export async function getIncludes(maxDepth: number): Promise<any> {
1311+
return clients.ActiveClient.getIncludes(maxDepth);
1312+
}

0 commit comments

Comments
 (0)