LSP-clangd
C/C++ support for Sublime's LSP plugin provided through clangd.
Installations minus removals
Upgrades
- 28,309 installs
- 73 stars
Links
Versions
3.1.0
(ST4070+)
·
LSP-clangd
C/C++ and Objective-C/C++ support for Sublime's LSP plugin provided through clangd.
Installation
- Install LSP and
LSP-clangdfrom Package Control - (Optional) Install clangd using your package manager or let this package install clangd for you
Usage
By default, clangd will assume your code is built as clang some_file.cc, and you’ll probably get errors about missing #included files, etc.
For complex projects, clangd needs to know your build flags. This can be done using a compile_commands.json or compile_flags.txt file.
For CMake-based projects a compile_commands.json file can be generated using the -DCMAKE_EXPORT_COMPILE_COMMANDS=1 flag.
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..
# compile_commands.json will be written to your build directory.
If your build directory is equivalent to the root of the project or <project_root>/build then clangd will find it. Otherwise, symlink or copy it to the root of your project.
See clangd Project Setup for more information on using
compile_commands.json,compile_flags.txtand other build systems.
Configuration
Here are some ways to configure the package and the language server.
From
Preferences > Package Settings > LSP > Servers > LSP-clangdFrom the command palette:
Preferences: LSP-clangd SettingsProject-specific configuration. From the command palette run
Project: Edit Projectand add your settings in:{ "settings": { "LSP": { "LSP-clangd": { "initialization_options": { // Put your settings here eg. // "clangd.header-insertion": "iwyu", } } } } }
Note
Since LSP-clangd 2.0.0 the key used in project settings is LSP-clangd. Overrides under the old clangd key are ignored.
Using a project-specific clangd binary
Top-level settings like binary can also be overridden per project. For example, to use a clangd binary bundled with the project's toolchain:
{
"settings": {
"LSP": {
"LSP-clangd": {
"binary": "custom",
"initialization_options": {
"custom_command": ["${folder}/toolchain/bin/clangd"],
}
}
}
}
}
Variables such as ${folder} (the first folder of the project) are expanded in custom_command. The clangd.* settings are still appended to the custom command as command-line arguments.
Sublime Commands
| Sublime Command | Description |
|---|---|
lsp_clangd_switch_source_header |
Switch between the main source file (.cpp) and header (.h). |