Darek
Darek

Reputation: 221

Visual Studio Code clangd extension configuration

I am trying to integrate clangd with VS Code using vscode-clangd extension, but I am having problem with configuring include paths...

I created additional config in VS Code settings:

"clangd.path": "path_to_clangd/bin/clangd",
"clangd.arguments": [
    "-compile-commands-dir=path_to_commands/compile_commands.json"
]

but the extension reports lots of missing includes errors.

I have also tried:

    "-compile-commands-dir=path_to_commands"

but this also didn't work.

Does anyone knows how to configure this extension at all? I am unable to find any documentation at this point.

Regards

Upvotes: 8

Views: 26100

Answers (3)

jackw
jackw

Reputation: 61

This is my answer, it works:

    "clangd.path": "/Users/jiewang/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/11.0.0/clangd_11.0.0/bin/clangd",
    "clangd.arguments": [
        "--compile-commands-dir=${workspaceFolder}/build",
        "--completion-style=detailed",
        "--header-insertion=never"
    ],

Upvotes: 6

Sunding Wei
Sunding Wei

Reputation: 2234

Your path should be directory to compile_commands.json, not file, and you need to restart the clangd by the vscode-clangd extension

settings.json

{
    "cmake.buildDirectory": "${workspaceFolder}/debug",
    "clangd.arguments": [
        "-background-index",
        "-compile-commands-dir=debug"
    ],
}

Restart

  1. change a bit of .clang-tidy file under your project root directory, if no, create one with something
  2. the vscode-clangd will prompt you to restart the clangd
  3. check the clangd process, it should something similar to
❯ ps -Af | grep clangd
awei     285478 282126  0 10:42 ?        00:00:03 /opt/llvm-10.0.0/bin/clangd -background-index -compile-commands-dir=debug

Upvotes: 11

eladcohen
eladcohen

Reputation: 31

It seems that the compile_commands.json has to be in the Folder root directory for the extension to find it.

I just add a symlink:

ln -s /path-to-build-dir/compile_commands.json /path-to-src-root-dir/

Upvotes: 3

Related Questions