Here is what clangd can do for you. Screenshots show VSCode; the available features and UI will depend on your editor.
- Errors and warnings
- Code completion
Errors and warnings
clangd runs the clang compiler on your code as you type, and shows diagnostics of errors and warnings in-place.
(Some errors are suppressed: diagnostics that require expanding templates in headers are disabled for performance reasons).
The compiler can suggest fixes for many common problems automatically, and clangd can update the code for you.
If a missing symbol was seen in a file you’ve edited recently, clangd will suggest inserting it.
clangd embeds clang-tidy which provides extra hints about code problems: bug-prone patterns, performance traps, and style issues.
clangd respects your project’s
.clang-tidy file which controls the checks to
run. Not all checks work within clangd.
You’ll see suggestions as you type based on what methods, variables, etc are available in this context.
Abbreviating words may help you find the right result faster. If you type in
camelCase but the function you’re looking for is
snake_case, that’s OK.
Namespace and include insertion
clangd will sometimes suggest results from other files and namespaces. In this
case the correct qualifier and
#include directive will be inserted.
Some editors will show you the parameters of the function you’re calling, as you fill them in.
These features let you navigate your codebase.
They work across the files you’ve opened.
clangd will also automatically index your whole project.
Jump to the definition or declaration of a symbol under the cursor.
(Some editors only expose “find definition” - hit it again to jump to the declaration).
This also works on #include lines, to jump to the included file.
Show all references to a symbol under the cursor.
Some editors will automatically highlight local references to the selected symbol as you move around a file.
clangd informs the editor of the code structure in the current file. Some editors use this to present an outline view:
In VSCode, this also allows jumping to a symbol within the current file.
Searching for symbols within the scope of the whole project is also possible.
Hover over a symbol to see more information about it, such as its type, documentation, and definition.
auto will show the underlying type.
clangd embeds clang-format, which can reformat your code: fixing indentation, breaking lines, and reflowing comments.
clangd respects your project’s
.clang-format file which controls styling
(Format-as-you-type is experimental and doesn’t work well yet).
Rename a symbol under the cursor. All usages of the symbol will be renamed, including declaration, definition and references.
Most symbols are renameable, such as classes, variables, functions and methods.
- References in templates and macro bodies may not be renamed (difficult to analyze in general)
- References in comments and disabled preprocessor sections are not yet renamed
- Related symbols (e.g. overriden methods in a class hierarchy) are not yet renamed
TIP: the rename workflow highly depends on the editor you are using. Some editors, e.g. VSCode, provide a way to preview the rename changes before applying them; while some just apply the changes directly.
The default mode only allows to rename a local symbol (one which is only used in current file).
This mode allows renaming symbols used in several files. It is enabled with the
It uses the project index to find all renamed references quickly, so works best when the index is up-to-date.