
clangd speaks the Language Server Protocol — which means it works inside VS Code, Neovim, Emacs, Helix, or any LSP-aware editor. You get cross-references, diagnostics, and code completion at the speed of a compiler backend, not a separate indexer.
1. Install clangd. On macOS: brew install llvm. On Ubuntu/Debian: apt install clangd. On Windows: use LLVM's pre-built binaries. Make sure clangd is in your $PATH.
2. Generate a compile commands file. If you use CMake: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. For Meson: meson setup build --wipe && meson compile -C build.
3. Point your editor at clangd. In VS Code, install the clangd extension. In Neovim:
require('lspconfig').clangd.setup({
cmd = { 'clangd', '--background-index' },
root_dir = root_pattern('compile_commands.json', '.clangd'),
})Prompt to test it:
Use clangd to find all references to the ConnectionPool class in this codebase and explain what it is used for.
clangd is built on Clang's AST — the same compiler infrastructure your project actually uses. That means:
The background indexer builds a persistent index across sessions. First run on a large project takes a few minutes. After that, jumps to symbol are instant.
| Pros | Cons |
|---|---|
| Real-time diagnostics without blocking | Initial index build takes time on large codebases |
| Type-aware completions far superior to word-based | Requires compile_commands.json for full accuracy |
| Works across translation units | Less polished than Rider or Visual Studio for C++ |
| Free, open source, vendor-neutral | No GUI debugger integration |
clangd is not a replacement for a full IDE — if you need a debugger with a GUI, use CLion or Rider. But for editing C++ in a fast, lightweight environment, clangd is the best LSP server available. It works inside every major editor, requires minimal configuration, and gives you compiler-quality code intelligence. If you are writing C++ without clangd, you are making your life harder than it needs to be.