clangd / vscode-clangd

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

Specify that compile_commands.json requires absolute paths #204

Open RenaKunisaki opened 3 years ago

RenaKunisaki commented 3 years ago

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...)

HighCommander4 commented 3 years ago

The compile_commands.json spec says:

All paths specified in the command or file fields must be either absolute or relative to directory.

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)?

RenaKunisaki commented 3 years ago

I was just using . as the directory.

HighCommander4 commented 3 years ago

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".

Febbe commented 3 years ago

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.

Febbe commented 3 years ago

https://github.com/clangd/clangd/issues/864