Skip to content

Commit 8e6eab4

Browse files
YangGangUEFIgapalomi
authored andcommitted
Add clangd config check in checkCompileCommandsConfig()
if vscode-clangd installed but `--compile-commands-dir=` is not setting or setting is not "${workspaceFolder}/.edkCode/", then update clangd.arguments to include: "--compile-commands-dir=${workspaceFolder}/.edkCode/". if vscode-clangd is not installed, still call infoMissingCompilesCommandCpp() Signed-off-by: Yang Gang <[email protected]>
1 parent 71803d7 commit 8e6eab4

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/ui/messages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function infoMissingCompileInfo(){
2222
}
2323

2424
export function infoMissingCompilesCommandCpp(){
25-
void vscode.window.showInformationMessage("Build contains compile_commands.json but C++ is not configured", "Help").then(async selection => {
25+
void vscode.window.showInformationMessage("Build contains compile_commands.json but vscode-cpptools/vscode-clangd is not configured/installed", "Help").then(async selection => {
2626
if (selection === "Help"){
2727
await vscode.env.openExternal(vscode.Uri.parse("https://github.com/intel/Edk2Code/wiki/Index-source-code#compile_commandsjson"));
2828
}
@@ -31,7 +31,7 @@ export function infoMissingCompilesCommandCpp(){
3131

3232
export async function updateCompilesCommandCpp():Promise<Boolean>{
3333
return new Promise<Boolean>(async (resolve, reject) => {
34-
return vscode.window.showInformationMessage("c_cpp_properties.json points to wrong compile_commands.json", "Fix").then(async selection => {
34+
return vscode.window.showInformationMessage("c_cpp_properties.json/settings.json points to wrong compile_commands.json", "Fix").then(async selection => {
3535
if (selection === "Fix"){
3636
resolve(true);
3737
}else{

src/utils.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ export async function itsPcdSelected(document: vscode.TextDocument, position: vs
398398

399399
export async function checkCompileCommandsConfig(){
400400
let cCppPropertiesPath = path.join(gWorkspacePath, ".vscode", "c_cpp_properties.json");
401+
const clangdExtension = vscode.extensions.getExtension('llvm-vs-code-extensions.vscode-clangd');
401402

402403
const expectedPath = path.join("${workspaceFolder}", ".edkCode", "compile_commands.json");
403404
if (fs.existsSync(cCppPropertiesPath)) {
@@ -412,7 +413,26 @@ export async function checkCompileCommandsConfig(){
412413
fs.writeFileSync(cCppPropertiesPath, JSON.stringify(cProperties,null,4));
413414
}
414415
}
415-
}else{
416+
} else if (clangdExtension) {
417+
const expectedArgument = "--compile-commands-dir=${workspaceFolder}/.edkCode/";
418+
const clangdConfiguration = vscode.workspace.getConfiguration('clangd');
419+
const clangdArguments = clangdConfiguration.get<string[]>('arguments') || [];
420+
const existingIndex = clangdArguments.findIndex(arg => arg.startsWith('--compile-commands-dir='));
421+
let updatedArguments = [...clangdArguments];
422+
if (existingIndex === -1) {
423+
let update = await updateCompilesCommandCpp();
424+
if (update) {
425+
updatedArguments.push(expectedArgument);
426+
await clangdConfiguration.update('arguments', updatedArguments, vscode.ConfigurationTarget.Workspace);
427+
}
428+
} else if (!clangdArguments.includes(expectedArgument)) {
429+
let update = await updateCompilesCommandCpp();
430+
if (update) {
431+
updatedArguments[existingIndex] = expectedArgument;
432+
await clangdConfiguration.update('arguments', updatedArguments, vscode.ConfigurationTarget.Workspace);
433+
}
434+
}
435+
} else {
416436
infoMissingCompilesCommandCpp();
417437
}
418438
}

0 commit comments

Comments
 (0)