ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

LSP-clangd

by sublimelsp ST4

C/C++ support for Sublime's LSP plugin provided through clangd.

Labels lsp, c++

Details

Installs

  • Total 30K
  • Win 13K
  • Mac 5K
  • Linux 12K
Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31 Aug 30
Windows 3 20 15 16 15 25 14 12 23 11 11 13 11 13 12 10 33 22 10 14 20 17 11 24 13 14 18 8 18 10 14 16 9 12 14 14 20 11 14 11 10 19 16 14 24 15
Mac 0 7 3 5 6 3 4 5 0 3 6 7 7 5 4 4 6 5 10 3 5 8 5 2 3 4 5 3 3 2 8 7 4 3 1 2 4 12 1 7 6 5 5 6 5 8
Linux 0 6 8 9 14 13 16 10 19 15 14 12 8 16 12 13 13 18 18 11 14 10 17 13 13 15 10 20 14 15 13 15 18 18 18 11 12 17 19 12 11 12 9 16 14 14

Readme

Source
raw.​githubusercontent.​com

LSP-clangd

C/C++ and Objective-C/C++ support for Sublime's LSP plugin provided through clangd.

Installation

  • Install LSP and LSP-clangd from 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.txt and other build systems.

Configuration

Here are some ways to configure the package and the language server.

  • From Preferences > Package Settings > LSP > Servers > LSP-clangd
  • From the command palette: Preferences: LSP-clangd Settings
  • Project-specific configuration. From the command palette run Project: Edit Project and 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).