Skip to content
Victor Alvarez edited this page Nov 22, 2018 · 10 revisions

Clangd is an implementation of the Language Server Protocol leveraging Clang. Clangd’s goal is to provide language “smartness” features like code completion, find references, etc. for clients such as C/C++ Editors.

Installation

Most package managers and major distributions provide a way to install tools from clang-tools-extra which includes Clangd. If you can't find instructions for your workspace below, consider checking Installing Clangd section.

macOS Homebrew:

brew install --with-toolchain llvm

For Arch Linux you can just install Clang package which comes with clang-tools-extra:

pacman -Syu clang

Debian-based Linux distributions provide clang-tools package (e.g. Debian package and Ubuntu package):

apt-get install clang-tools

Configuration

let g:LanguageClient_serverCommands = {
  \ 'cpp': ['clangd'],
  \ }

Troubleshooting

If you encounter a bug and you are able to reproduce it, Clangd developers would appreciate a bug submission. Please use LLVM Bugzilla for the bug reports. To help diagnose the problem, you can attach log files and the Mirror File (which stores the LSP input passed to Clangd).

To store stderr output, you can redirect stderr to a file and use LanguageClient#debugInfo() function:

let g:LanguageClient_serverStderr = '/tmp/clangd.stderr'

function SetLSPShortcuts()
  " ...
  " Previous bindings
  " ...
  nnoremap <leader>ll :call LanguageClient#debugInfo()<CR>
endfunction()

Bonus: Building Global Static Index

Clangd can provide global completion when given a global static index. This index is not rebuilt during the editing process which means that if a significant part of the codebase is changed you would have to rebuild it to reflect these changes.

To build the global static index, you can use experimental clangd-indexer tool. If have copied the compile_commands.json to the source directory, call:

clangd-indexer -executor=all-TUs /path/to/project > index.yaml

After the index is produced, you can pass it to Clangd via -yaml-symbol-file:

let g:LanguageClient_serverCommands = {
  \ 'cpp': ['clangd', '-yaml-symbol-file=/path/to/index.yaml',],
  \ }

The global static index infrastructure is experimental, so please be aware that you might encounter some bugs. If you do, please submit a bug report to help make the infrastructure better.

Getting Involved

If you are interested in Clangd development or have any questions, consider using clangd-dev Mailing List.

Clone this wiki locally