Skip to content

Commit

Permalink
Add clangd config check in checkCompileCommandsConfig()
Browse files Browse the repository at this point in the history
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 <yanggang@byosoft.com.cn>
  • Loading branch information
YangGangUEFI authored and gapalomi committed Dec 16, 2024
1 parent 71803d7 commit 8e6eab4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ui/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function infoMissingCompileInfo(){
}

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

export async function updateCompilesCommandCpp():Promise<Boolean>{
return new Promise<Boolean>(async (resolve, reject) => {
return vscode.window.showInformationMessage("c_cpp_properties.json points to wrong compile_commands.json", "Fix").then(async selection => {
return vscode.window.showInformationMessage("c_cpp_properties.json/settings.json points to wrong compile_commands.json", "Fix").then(async selection => {
if (selection === "Fix"){
resolve(true);
}else{
Expand Down
22 changes: 21 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export async function itsPcdSelected(document: vscode.TextDocument, position: vs

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

const expectedPath = path.join("${workspaceFolder}", ".edkCode", "compile_commands.json");
if (fs.existsSync(cCppPropertiesPath)) {
Expand All @@ -412,7 +413,26 @@ export async function checkCompileCommandsConfig(){
fs.writeFileSync(cCppPropertiesPath, JSON.stringify(cProperties,null,4));
}
}
}else{
} else if (clangdExtension) {
const expectedArgument = "--compile-commands-dir=${workspaceFolder}/.edkCode/";
const clangdConfiguration = vscode.workspace.getConfiguration('clangd');
const clangdArguments = clangdConfiguration.get<string[]>('arguments') || [];
const existingIndex = clangdArguments.findIndex(arg => arg.startsWith('--compile-commands-dir='));
let updatedArguments = [...clangdArguments];
if (existingIndex === -1) {
let update = await updateCompilesCommandCpp();
if (update) {
updatedArguments.push(expectedArgument);
await clangdConfiguration.update('arguments', updatedArguments, vscode.ConfigurationTarget.Workspace);
}
} else if (!clangdArguments.includes(expectedArgument)) {
let update = await updateCompilesCommandCpp();
if (update) {
updatedArguments[existingIndex] = expectedArgument;
await clangdConfiguration.update('arguments', updatedArguments, vscode.ConfigurationTarget.Workspace);
}
}
} else {
infoMissingCompilesCommandCpp();
}
}
Expand Down

0 comments on commit 8e6eab4

Please sign in to comment.