clangd / vscode-clangd

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

How to find compile_commands.json for Debug/Release build matching cmake tools? #233

Open emmenlau opened 3 years ago

emmenlau commented 3 years ago

We use cmake tools to build from VSCode. It places compile_commands.json in specific folders, with either Debug or Release in the path. It would be great if the two extensions could work together to resolve the path, is that possible?

I'm not sure what either of the two extensions would need to do to make that work. I guess vscode-clangd would need an environment variable that resolves to Debug or Release? And when switching the build target in cmake tools, vscode-clangd would need to get some notification that the path changed?

i-ky commented 3 years ago

See https://github.com/clangd/vscode-clangd/issues/218#issuecomment-898869786

emmenlau commented 3 years ago

I should have mentioned that I do know this option. But its not exactly what I had in mind. The problem with this option is that we have literally hundreds of projects, and typically have many of them open at the same time. We will need a tree of directories where to copy all the temporary compile_commands.json files. Or we will need to copy the compile_commands.json to the source folder, which in turn pollutes the source tree. All of this is of course possible if no other options are available. But much much nicer would be if there was a way to dynamically resolve compile_commands.json for the currently active build configuration...

HighCommander4 commented 3 years ago

See https://github.com/clangd/clangd/issues/526 for a similar request. At least the workaround described there (to change clangd.arguments to pass a different --compile-commands-dir=<path>) should be viable now.

Clangd has also since introduced the ability to control the location of compile_commands.json via its config file (see the CompilationDatabase key), so another possibility could be modifying the value in the config file.