Skip to content

Commit f49d185

Browse files
authored
Add command-variable provider for ${command:cmsis-csolution.getInfoPath
1 parent d03da93 commit f49d185

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,11 @@
777777
"command": "cmsis-csolution.getCbuildRunFile",
778778
"title": "Path to cbuild-run.yml File of Active Target"
779779
},
780+
{
781+
"category": "CMSIS",
782+
"command": "cmsis-csolution.getInfoPath",
783+
"title": "Path to output directory of active clangd information"
784+
},
780785
{
781786
"command": "cmsis-csolution.list.find",
782787
"title": "Search"
@@ -891,6 +896,10 @@
891896
"command": "cmsis-csolution.copyHeaderFile",
892897
"when": "false"
893898
},
899+
{
900+
"command": "cmsis-csolution.getInfoPath",
901+
"when": "false"
902+
},
894903
{
895904
"command": "cmsis-csolution.createSolution"
896905
},

src/solutions/clangd-manager.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,21 @@ describe('ClangdManager', () => {
344344
expect(mockFs.exists).toHaveBeenCalledWith(expect.lowercaseEquals(expectedClangdPath));
345345
expect(mockFs.writeUtf8File).toHaveBeenCalledWith(expect.lowercaseEquals(expectedClangdPath), 'Diagnostics:\n Suppress: [\'*\']');
346346
});
347+
348+
it('returns out directory for the active clangd context', async () => {
349+
mockConfigurationProvider.getConfigVariable.mockReturnValue(true);
350+
mockConfigurationProvider.setConfigVariable.mockReturnValue(Promise.resolve());
351+
352+
mockSolutionManager.onUpdatedCompileCommandsEmitter.fire();
353+
await waitTimeout();
354+
355+
const infoPath = await mockCommandsProvider.mockRunRegistered<string>(ClangdManager.getInfoPathCommandId);
356+
expect(path.normalize(infoPath)).toEqual(path.join(path.dirname(activeContexts[0].projectPath!), 'out'));
357+
});
358+
359+
it('returns an empty string when no active clangd context exists', async () => {
360+
const infoPath = await mockCommandsProvider.mockRunRegistered<string>(ClangdManager.getInfoPathCommandId);
361+
expect(infoPath).toEqual('');
362+
});
363+
347364
});

src/solutions/clangd-manager.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const clangDActiveContextKey = `${manifest.PACKAGE_NAME}.activeClangdCont
7070
export class ClangdManager {
7171
public static readonly setClangdContextCommandId = `${manifest.PACKAGE_NAME}.setClangdContext`;
7272
public static readonly unsetClangdContextCommandId = `${manifest.PACKAGE_NAME}.unsetClangdContext`;
73+
public static readonly getInfoPathCommandId = `${manifest.PACKAGE_NAME}.getInfoPath`;
7374

7475
private readonly debouncedUpdateClangdConfig;
7576
private readonly restartClangd;
@@ -95,6 +96,7 @@ export class ClangdManager {
9596
this.configurationProvider.onChangeConfiguration(this.debouncedUpdateClangdConfig, CONFIG_CLANGD_GENERATE_SETUP);
9697
this.commandsProvider.registerCommand(ClangdManager.setClangdContextCommandId, this.setGlobalContext, this);
9798
this.commandsProvider.registerCommand(ClangdManager.unsetClangdContextCommandId, this.unsetGlobalContext, this);
99+
this.commandsProvider.registerCommand(ClangdManager.getInfoPathCommandId, this.getInfoPath, this);
98100
}
99101

100102
private get globalContext() {
@@ -128,6 +130,24 @@ export class ClangdManager {
128130
// Do nothing
129131
}
130132

133+
private getInfoPath(): string {
134+
return this.resolveInfoPath();
135+
}
136+
137+
private resolveInfoPath(): string {
138+
const csolution = this.solutionManager.getCsolution();
139+
const globalContextProjectPath = this.globalContext;
140+
141+
if (!csolution || !globalContextProjectPath) {
142+
return '';
143+
}
144+
145+
const context = csolution.getContextDescriptor(globalContextProjectPath);
146+
const outDir = context ? csolution.cbuildIdxFile?.cbuildFiles?.get(context.projectName)?.outDir : undefined;
147+
148+
return outDir ?? '';
149+
}
150+
131151
private async updateWorkspaceClangdConfig(compileCommands: URI | undefined) {
132152
const clangd_arguments = [];
133153
if (compileCommands) {

0 commit comments

Comments
 (0)