Skip to content
C++

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)

clangd
LLVM Project · Apache 2.0 · Active development

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)

Full guide
ccls
Community · MIT · Slower updates

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: true

Code Formatters

clang-format
LLVM · Apache 2.0 · Ships with Clang

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
Full guide
uncrustify
Community · GPL v2 · C-family + Java

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