LinuxCommandLibrary

clangd

Provide C/C++ language server features

TLDR

Display available options

$ clangd --help
copy

List of available options
$ clangd --help-list
copy

Display version
$ clangd --version
copy

SYNOPSIS

clangd [options...] [path-to-compile-commands.json]

PARAMETERS

--help
    Print detailed help message and exit

--version
    Print version information and exit

--compile-commands-dir=<dir>
    Directory containing compile_commands.json

--compile-commands-dir=<-|path>
    Path to compile_commands.json (stdin if '-')

--header-insertion=<iwyu|never>
    Control header insertion in completions (default: iwyu)

--background-index
    Continuously index project in background

--clang-tidy
    Enable clang-tidy diagnostics

--completion-style=<detailed|bundled>
    Completion item format (default: detailed)

--check=<path>
    Perform syntax check on specific file

--crash-privacy=<leak|anonymize|none>
    Control crash report privacy

--log=<verbose|info|error|debug>
    Set logging verbosity

--path-mappings=<local-path>=<remote-path>
    Map local to remote paths for open files

--j=<N>
    Set number of parallel jobs (default: CPU cores)

--pch-storage=<disk|memory>
    Precompiled header storage (default: disk)

--suggest-missing-includes
    Suggest missing includes in diagnostics

DESCRIPTION

Clangd is a high-performance Language Server Protocol (LSP) implementation for C, C++, and Objective-C, part of the LLVM/Clang project. It delivers editor features like autocompletion, real-time diagnostics, go-to-definition, find references, code formatting, and refactoring.

Clangd leverages the Clang compiler's parser for precise semantic analysis, supporting massive codebases with incremental processing and background indexing. It requires a compile_commands.json file (generated by CMake, Bear, or similar) to understand build configurations. Editors like VS Code, Vim, Emacs, and Neovim integrate it via plugins.

Unlike full compilers, clangd focuses solely on editing assistance, enabling fast startup (often under 100ms) and low resource usage. It supports advanced features like expression evaluation under cursor and clang-tidy integration for static analysis.

CAVEATS

Requires compile_commands.json for full accuracy; fallback to header search paths otherwise. Not a compiler—use for editing only. High memory use on very large projects without indexing.

CONFIGURATION

Project settings via .clangd YAML file in repo root or parent dirs; supports compile flags, index options, diagnostics suppression.

BUILDING

Built from LLVM source: cmake -G Ninja -DLLVM_ENABLE_PROJECTS=clang-tools-extra .. && ninja clangd

HISTORY

Developed by LLVM team starting 2016 to replace slower libclang LSP servers. Integrated into Clang/LLVM releases since 2019; now default C++ LSP in many editors. Actively maintained with frequent updates.

SEE ALSO

clang(1), clang-format(1), clang-tidy(1), ccls(1)

Copied to clipboard