0

I'm trying to setup clangd with Neovim built-in LSP Config and it is working fine. Problem is, usually I compile everything with the flags -Wall -Wextra -Werror, how can I make clangd use these flags when analyzing code and prompt for errors?

Thanks in advance :)

2 Answers2

0

clangd automatically reads the compilation database from a file called compile_commands.json, and reuses compiler flags from there. No need to do anything special in Neovim. For example, a compile_commands.json file could look like:

[{
  "directory": ".",
  "file": "test.cpp",
  "arguments": ["g++", "-c", "test.cpp", "-Wall", "-Wextra", "-Werror"]
}]

Usually you'll want to generate this file as part of your build process. CMake can do that out of the box, or you can use clang -MJ compile_commands.json.

johannes
  • 371
  • 1
  • 3
0

clangd accepts global configuration via $XDG_CONFIG_HOME/clangd/config.yaml. You can add Compile Flags with:

CompileFlags:
    Add: [-Wall, -Wextra, -Werror]