clangd helps developers write, understand and improve C/C++ code by providing:
- code completion
- compile errors and warnings
- go-to-definition and cross references
- hover information and inlay hints
- include management
- code formatting
- simple refactorings
Full documentation for clangd is at clangd.llvm.org.
The extension requires the clangd language server.
You will be prompted to download it if it's not found on your PATH.
(Automatic installation is possible on x86-64 Linux, Windows, and Mac).
If you have an old version of clangd installed on your system already, you can run "Check for clangd language server update" from the command palette.
clangd is based on the clang C++ compiler, and understands even complex C++
code. However, you must tell clangd how your project is built (compile flags).
A compile_commands.json file
can usually be generated by your build system
(e.g. with CMake, by setting -DCMAKE_EXPORT_COMPILE_COMMANDS=1).
See Project Setup in the clangd documentation for details and alternatives.
The clangd server also supports a number of feature customizations using its config file.
The extension provides a few configuration options on top of the server-side configuration provided by clangd.
Variable substitution is supported in settings such as
clangd.arguments, clangd.path, clangd.fallbackFlags, and clangd.trace.
For example, to look for compile_commands.json in a build directory under
the workspace root, add this to .vscode/settings.json:
{
"clangd.arguments": ["--compile-commands-dir=${workspaceFolder}/build"]
}| Variable | Expands to |
|---|---|
${workspaceFolder}, ${workspaceRoot}, ${cwd} |
The workspace root path. If no workspace root is available, these use the active file's directory, then the extension process's working directory as a fallback. |
${workspaceFolderBasename} |
The name of the workspace root directory, if available. |
${userHome} |
The user's home directory. |
${env:NAME} |
The value of the environment variable NAME, or an empty string if it is unset. |
${config:setting.name} |
The value of a VS Code setting, if it is a string. |
${command:commandId} |
The result of running the named VS Code command. Use a command that returns a string. |
While these substitutions are intended to mirror the VS Code variables reference, not everything listed there is supported.
The extension leaves unresolved placeholders unchanged. It expands variables in string values, including those in arrays, in a single pass. A replacement that contains another placeholder is left as returned.
Substitution only applies to the extension's clangd.* settings. It is not performed by clangd itself (e.g. in .clangd config files or compilation databases).
Suggestions will appear as you type names, or after . or ->.
Because clangd uses a full C++ parser, code completion has access to precise
type information.
Code errors are shown as you type (both as red squiggle underlines, and in the "Problems" panel). These are the same as produced by the clang compiler, and suggested fixes can automatically be applied.
Most clang-tidy checks are supported (these can be enabled using a .clang-tidy file).
Go-to-definition and find-references work across your code, using a project-wide index.
Press Ctrl-P # to quickly navigate to a symbol by name.
Clangd can describe almost any entity if you hover the mouse (or press Ctrl-KI).
Inlay hints for parameters and deduced types can be shown temporarily or
permanently (the editor.inlayHints.enabled setting controls this).
Code completion works across your codebase and adds #include directives where
needed. The • shows includes that will be inserted.
clangd can suggest inserting missing #includes, where they cause errors. It can warn on unused includes.
clangd uses the clang-format engine. You can format a file or the selection.
When "Format on Type" is enabled in the settings, pressing enter will cause
clangd to format the old line and semantically reindent.
The style used for formatting (and certain other operations) is controlled by the project's .clang-format file.
Note that if you prefer to use something other than clangd for formatting, you can
choose a different formatter with the "editor.defaultFormatter" setting.
clangd supports some local refactorings. When you select an expression or declaration, the lightbulb menu appears and you can choose a code action.
Current refactorings include:
- extract variable/function
- expand
autotypes and macros - use raw strings
- rename (bound to
<F2>, rather than a contextual code action)
clangd is part of the LLVM project.
If you'd like to help out, reach out to clangd-dev@lists.llvm.org.
If you've found a bug in this extension, please file it at https://github.com/clangd/vscode-clangd/issues. If you've found a bug in clangd, please file at https://github.com/clangd/clangd/issues.






