Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clangd config check in checkCompileCommandsConfig() #10

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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