Features

Here is what clangd can do for you. Screenshots show VSCode; the available features and UI will depend on your editor.

Contents#contents

Errors and warnings#errors-and-warnings

clangd runs the clang compiler on your code as you type, and shows diagnostics of errors and warnings in-place.

screenshot: clang errors

(Some errors are suppressed: diagnostics that require expanding templates in headers are disabled for performance reasons).

Fixes#fixes

The compiler can suggest fixes for many common problems automatically, and clangd can update the code for you.

screenshot: apply fix

If a missing symbol was seen in a file you’ve edited recently, clangd will suggest inserting it.

screenshot: include-fixer fix

clang-tidy checks#clang-tidy-checks

clangd embeds clang-tidy which provides extra hints about code problems: bug-prone patterns, performance traps, and style issues.

screenshot: apply clang-tidy fix

clangd respects your project’s .clang-tidy file which controls the checks to run. Not all checks work within clangd.

Code completion#code-completion

You’ll see suggestions as you type based on what methods, variables, etc are available in this context.

screenshot: code completion

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#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.

screenshot: code completion insert ns

Signature help#signature-help

Some editors will show you the parameters of the function you’re calling, as you fill them in.

screenshot: signature help

Populate switch statement#populate-switch-statement

Populates the switch statement of an enum type with all its enumerations.

screenshot: populate switch statement

Generate member wise constructor#generate-member-wise-constructor

Creates an member wise constructor for a C++ class.

screenshot: generate member wise constructor

Generate default copy & move constructors#generate-default-copy--move-constructors

Generates declaration for missing move/ copy constructor/ assignments.

screenshot: generate special functions

Cross-references#cross-references

These features let you navigate your codebase.

They work across the files you’ve opened.

clangd will also automatically index your whole project.

Find definition/declaration#find-definitiondeclaration

Jump to the definition or declaration of a symbol under the cursor.

screenshot: go to def

(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.

Find references#find-references

Show all references to a symbol under the cursor.

screenshot: find references

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:

screenshot: outline

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.

screenshot: navigation

Hover#hover

Hover over a symbol to see more information about it, such as its type, documentation, and definition.

screenshot: hover

Hovering over auto will show the underlying type.

Formatting#formatting

clangd embeds clang-format, which can reformat your code: fixing indentation, breaking lines, and reflowing comments.

screenshot: format selection

clangd respects your project’s .clang-format file which controls styling options.

Format-as-you-type is experimental and doesn’t work well yet.

Refactoring#refactoring

Rename#rename

Rename a symbol under the cursor. All usages of the symbol will be renamed, including declaration, definition and references.

screenshot: rename

Most symbols are renameable, such as classes, variables, functions and methods.

Renaming a symbol will affect usages of the name across the project.

Known limitations

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.

Inline using namespace#inline-using-namespace

Removes using namespace declaration and expand the namespace to the declaration.

screenshot: inline using namespace

Extract namespace#extract-namespace

Extract namespace declaration as using.

screenshot: extract namespace

Expand auto declaration#expand-auto-declaration

Expands the real type of an auto declaration.

Expand Marco#expand-marco

Expand the macro in-place.

Extract variable#extract-variable

Extract expression result to a dummy variable.

Extract function#extract-function

Extract expression as a function.

Convert to raw string literal#convert-to-raw-string-literal

Convert a ordinary string literal to a raw string literal.

screenshot: convert to raw string

Define Inline#define-inline

Moves definition of a function/method to its declaration location.

Define Outline#define-outline

Moves definition of a function/method to an appropriate implementation file.

Warp in NSLocalizedString#warp-in-nslocalizedstring

Wrap Objective-C string literals in NSLocalizedString macros.

✏️