Provides C/C++ language IDE features for VS Code using clangd:
- code completion
- compile errors and warnings
- go-to-definition and cross references
- include management
- code formatting
- simple refactorings
The extension requires the
clangd language server.
You will be prompted to download it if'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).
can usually be generated by your build system
(e.g. by setting
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 when building with CMake,
many other tools).
It should live at the top of your source tree: symlink or copy it there.
Suggestions will appear as you type names, or after
Because clangd uses a full C++ parser, code completion has access to precise
Errors, warnings, and clang-tidy
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
Go-to-definition and find-references work across your code, using a project-wide
Ctrl-P # to quickly navigate to a symbol by name.
Code completion works across your codebase and adds
#include directives where
• shows includes that will be inserted.
clangd can also suggest inserting missing #includes, where they cause errors.
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 .clang-format file is controlled by the project's
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
auto types 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 email@example.com.
If you've found a bug, please file at https://github.com/clangd/clangd/issues.