vscode-clangd
vscode-clangd copied to clipboard
Specify that compile_commands.json requires absolute paths
I might just be dumb, but I spent an hour trying to figure out why my compile_commands.json wasn't being used before realizing it required the file paths to be absolute. This should probably be in the readme. (Or not a requirement...)
The compile_commands.json spec says:
All paths specified in the
commandorfilefields must be either absolute or relative todirectory.
Were you seeing clangd impose a stricter requirement than this (i.e. directory was absolute, file was relative to it, and it still did not work)?
I was just using . as the directory.
Ok, I see.
compile_commands.json is typically generated by a tool (such as CMake or Bear), so following the spec is generally the responsibility of the tool author. But it is of course possible to write it manually as well.
Clangd does link to the compile_commands.json spec on the Getting Started page already, but perhaps we could add a note such as "if you're writing compile_commands.json manually, be sure to follow its spec, including in particular the requirement for absolute paths".
I think, that the problem is, that relative paths are resolved from the execution path of clangd, not from the --compile-commands-dir=<string> specified path.
This must be changed by clangd in my opinion. But to fix it for the plugin, we need an execution path setting, to change the path, where clangd is executed.
https://github.com/clangd/clangd/issues/864