C++ LSP Servers & Formatters
clangd and ccls for Language Server Protocol, clang-format and uncrustify for code formatting — how they work and which to choose.
Language Server Protocol (LSP)
The recommended C++ LSP. Backed by the LLVM team, ships with every LLVM/Clang release, integrates clang-tidy diagnostics inline.
- Best completion quality — uses Clang AST
- Inline clang-tidy hints and fixes
- Go-to-definition across headers and templates
- Hover documentation from Doxygen/comments
- Rename refactoring
- Inlay hints (parameter names, auto types)
- Background indexing — no wait time on open
- Remote indexing (clangd remote)
VS Code setup
Extension: "clangd" (llvm-vs-code-extensions.vscode-clangd)
Disable: C/C++ IntelliSense (conflicts)
An alternative Clang-based LSP. Historically had better call hierarchy and memory usage. Today clangd has caught up in most areas.
- Lower memory usage than early clangd versions
- Call hierarchy (callers/callees)
- Semantic highlighting
- Cross-reference queries
- Supports old Clang versions
- Less actively maintained than clangd
- No clang-tidy integration
- Fewer features than modern clangd
Verdict: Choose clangd. ccls had its moment (2018-2020) but clangd has surpassed it.
clangd configuration (.clangd in project root)
CompileFlags:
Add: [-std=c++23, -Wall, -Wextra]
CompilationDatabase: build/
Diagnostics:
ClangTidy:
Add: [modernize-*, bugprone-*, performance-*]
Remove: [modernize-use-trailing-return-type]
UnusedIncludes: Strict
InlayHints:
Enabled: true
ParameterNames: true
DeducedTypes: true
Hover:
ShowAKA: trueCode Formatters
The de-facto standard C++ formatter. Understands C++ syntax (not just text), produces consistent output across all major style guides.
- Syntax-aware — never breaks code
- Built-in styles: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft
- Highly configurable .clang-format file
- IDE integration in every major editor
- Format-on-save support everywhere
- Git pre-commit hook trivial to add
Highly configurable C/C++/C#/Java formatter. 700+ configuration options. Used in projects that need very specific style rules beyond what clang-format supports.
- 700+ fine-grained options
- Supports C, C++, C#, Java, Objective-C
- Some transformations clang-format can't do
- Configuration is complex and fragile
- Less IDE integration than clang-format
- Occasionally produces subtly wrong output
- Not syntax-aware like clang-format
Verdict:Use clang-format unless you have a very specific style requirement it can't handle. The 700 options in uncrustify are mostly a maintenance burden.
Minimal .clang-format starter
BasedOnStyle: Google IndentWidth: 4 ColumnLimit: 100 AllowShortFunctionsOnASingleLine: Inline AllowShortIfStatementsOnASingleLine: false BraceWrapping: AfterFunction: true AfterControlStatement: false IncludeBlocks: Regroup SortIncludes: CaseSensitive