clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
645 stars 114 forks source link

Add separate setting to set `--compile-commands-dir` #644

Open recursivenomad opened 5 months ago

recursivenomad commented 5 months ago

The directory that my compile_commands.json is located in varies per-project, and I would like to be able to set --compile-commands-dir in a per-project VSCode settings.json. The location of compilers varies per-user, and I am currently using the global "clangd.arguments" setting to define the location of my compilers with --query-driver. You cannot have "clangd.arguments" in your project and global settings, as the project settings will override the global settings, thus getting rid of the --query-driver arguments.

To solve this, it would be very helpful if I could define --compile-commands-dir with a separate settings.json entry, therefore enabling us to set the location of compile_commands.json per-project.

Technically, I think it would make sense to append this argument specifically after "clangd.arguments", so that if --compile-commands-dir is already declared in "clangd.arguments", then the project-level --compile-command-dir is supplied last and therefore would be the one clangd uses.

For additional context, please see this discussion in the clangd language server repository.

AlexiousLu commented 2 months ago

I am in the same situation as you, where my compile_commands.json is located variously across different projects.

But I solved this by simply adding configuration in Settings->Workspace->clangd->Arguments, for example, --compile-commands-dir=${workspaceFolder}/build in your discussion. 'Workspace' means the setting is for only current projects you are in and can be differently set in projects.

Hope this is useful for you.