You can use Cpp Language Server (cpp_ls) to get C, C++ and CUDA support:
- no build system is required: a
compile_commands.jsonis used for exact per-file flags when it exists, and a.cppls.tomlfile in the workspace root can name the language standard, the include paths and the defines; - completion, hover, signature help, definition, references, rename, call hierarchy, workspace symbols, inlay hints, semantic tokens, folding, selection ranges, formatting and diagnostics are provided by the server.
cpp_ls is distributed as one asset per OS and architecture in the
GitHub releases, and the LSP4IJ template installs the right one for you.
-
Select
Cpp Language Serveras the template from the available options. This will populate the command field with a default command (cpp_ls, orcpp_ls.exeon Windows), the file type mappings, thecpplssettings and the installer. -
Install the language server from the
Installertab, by clicking theCheck / Run Installationlink:Check Installationtests whethercpp_lshas already been installed in$USER_HOME$/.lsp4ij/lsp/cpp_ls.Run Installationdownloads the asset which matches your OS and architecture, extracts it in$USER_HOME$/.lsp4ij/lsp/cpp_ls, and updates the server command to the extracted executable.Check / Run Installationdoes both, which is the simplest choice on a fresh installation.
The assets which the installer selects are:
OS Architecture Asset Windows x64 cpp_ls-win32-x64.zipWindows x86 cpp_ls-win32-ia32.zipWindows arm64 cpp_ls-win32-arm64.zipLinux x64 (glibc 2.17 or newer) cpp_ls-linux-x64-glibc.2.17.tar.gzLinux aarch64 (glibc 2.17 or newer) cpp_ls-linux-aarch64-glibc.2.17.tar.gzLinux riscv64 cpp_ls-linux-riscv64.tar.gzmacOS Apple Silicon cpp_ls-darwin-arm64.tar.gzmacOS Intel cpp_ls-darwin-x64.tar.gzThe archives contain a single executable at their root:
cpp_ls.exeon Windows,cpp_lson Linux and macOS.If you prefer to install it yourself, download the asset which matches your OS and architecture, extract it, and set the command in the
Servertab to the extracted executable.The installer selects the
-glibc.2.17assets on Linux, since they run on every distribution which provides glibc 2.17 or newer. On a musl based distribution (Alpine), downloadcpp_ls-linux-musl.tar.gzyourself, and set the command to the extractedcpp_lsexecutable. -
Optional: customize the
Mappingstab. The template maps:*.c,*.ito theclanguage id,*.cpp,*.h,*.hpp,*.cc,*.cxx,*.inl,*.ipp,*.ixx,*.mpp,*.mxx, etc to thecpplanguage id,*.cu,*.cuhto thecuda-cpplanguage id.
-
Optional: customize the settings in the
Configurationtab (Serversub-tab), see Settings below. -
Click OK to apply the changes. You should now have
C,C++andCUDAsupport enabled in your IDE, with the Cpp Language Server integrated, and you should see the language server in the LSP console.
cpp_ls talks LSP over its standard input and output, so the command needs no argument:
cpp_lson Linux and macOS.cpp_ls.exeon Windows.
Useful options, to add to the command if needed:
--log-level(error,warn,info(the default),debug,trace) and--log-path(the file to log to;none, the default, disables file logging) to diagnose a problem;--communication stdio(the default) and--communication tcp --port ${port}to choose how the server talks LSP. For TCP, also setTransporttoSocketwithStart the language server, LSP4IJ connects to it, sincecpp_lslistens on the port, andPorttoAutoor a port; see Transport.
LSP4IJ sends the name of the IDE as its client info, which the server recognizes for the IntelliJ based IDEs it
knows; --editor intellij can be added to the command to force this mode.
The server reads its settings from the cppls section, which LSP4IJ answers from the template settings.json:
{
"cppls": {
"exclude": [
"**/build/**",
"**/third_party/**"
]
}
}cppls.exclude is the list of glob patterns of the files and folders which the server must not analyse (a build
tree, a vendored copy, generated sources). An empty list means that only the server's own rules apply.
A project can also provide a .cppls.toml file at its root for the language standard, the include paths, the
defines, per-path rules and the diagnostic switches, and a compile_commands.json file for the exact per-file
flags. See the configuration documentation for
the details.