Kylin Clangd
This extension helps developers write, understand and improve C/C++ code by providing:
.clangd
, .clang-format
, .clang-tidy
file support. Create these three files in workspace folder if doesn't exist when this extension activated. and support auto completion, schema validation when edit these files.
- 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.
Changes made to the original vscode-clangd extension
Add some settings to control the clangd server more flexibly.
clangd.headerInsertion
: set to iwyu
to insert include-what-you-use header, set to never
to disable header insertion.
clangd.enableClangTidyDiagnostic
: enable clang-tidy diagnostics. enable this option will create a .clang-tidy
file in workspace
Add a command clangd.createClangdConfigFile
to create three files: .clangd
, .clang-tidy
, and .clang-format
in the workspace folder. These files have default configurations that can be modified as needed. You can input Create clangd configuration file
in the command palette to execute this command.
Add auto completion, schema validation for .clangd
, .clang-tidy
and .clang-format
files (You must have extension redhat.vscode-yaml
installed to enable schema validation).
Adapted for Kylin/openKylin system and Kylin-IDE
Feedback
Please report bugs or feature requests for this extension at Kylin Clangd OpenKylin Repository.
Requirements
- Please install clangd, the newer the better. The extension requires clangd 9 or later.
.clangd
file support requires clangd 11 or later.
- Please install extension
redhat.vscode-yaml
to enable schema validation for .clangd
, .clang-format
, .clang-tidy
files.
Setup
clangd
server
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.
Project setup
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.
Features
Suggestions will appear as you type in these files, you can also press ctrl + space to bring up the suggestion list.
Code completion
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.
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 file).
Cross-references
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.
Hover and inlay hints
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).
Include management
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.
Refactoring
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
auto
types and macros
- use raw strings
- rename (bound to
<F2>
, rather than a contextual code action)