This extension brings cpp_ls to Zed: a C, C++ and CUDA
language server written from scratch in Rust — no clangd, no libclang, and no compilation database needed to
start. A compile_commands.json (any build system) or CMake's build_database.json is used when the project has
one, and a .cppls.toml in the workspace root describes the project when it does not.
The extension itself is small on purpose: Zed's built-in C and C++ languages keep their tree-sitter grammars,
queries, folding, indentation and text objects, and this extension attaches the language server to both of them. It
ships no grammar, so it adds nothing to your highlighting that Zed did not already have.
| Reading | completion (members after ./->/::, scopes, includes), hover with the deduced type and the doc comment, signature help, go to definition / type definition / implementation, find references, document and workspace symbols, call and type hierarchy, document highlight, folding, selection ranges, inlay hints, code lens |
| Editing | diagnostics (pull and push, 43 codes, each switchable in .cppls.toml), code actions from those diagnostics, rename, formatting and range formatting |
| Extras | Doxygen commands in comments, [`symbol`] references in comments, format-string awareness for printf / std::format / fmt, semantic tokens, CUDA and C23 dialects |
Since the server reads the program rather than a file, half-typed lines are answered like complete ones, and a
modern C++ program (import std;, contracts, static reflection) is parsed as the standard spells it.
- Open Zed, run
zed: extensions, search for C++ Language Server, and install it. - Open a C or C++ file. On first use the extension downloads the server for your platform from
CppCXY/cpp_lsreleases (about 21 MB) and shows the progress in Zed's status bar.
Nothing needs to be installed beforehand. If you would rather use a build of your own, see Which server binary is started.
The first of these that applies wins:
lsp.cppls.binary.pathin your Zed settings — used exactly as written.- A
cpp_lsexecutable on$PATH(cargo install --locked cpp_ls, a system package, a manual build). - The binary an earlier session downloaded and this one can still verify.
- A fresh download of the latest release, unpacked into Zed's extension work directory as
cpp_ls-<version>/cpp_ls.
Only one downloaded version is kept: after an update, the older cpp_ls-* directory is removed. The download is
staged in download/ and renamed into place when complete, so an interrupted download never leaves a half-written
install behind. A failed update does not take away a working install — if GitHub cannot be reached, the newest
installation already on disk is started and the failure is written to Zed's log (zed: open log).
{
"lsp": {
"cppls": {
"binary": {
"path": "/usr/local/bin/cpp_ls",
"arguments": ["--log-level", "debug", "--log-path", "/tmp/cpp_ls.log"],
"env": {}
},
"initialization_options": {},
"settings": {
"exclude": ["**/build/**", "third_party/**"]
}
}
},
"languages": {
"C++": {
"format_on_save": "on",
"formatter": "language_server"
}
}
}binary—pathbypasses the extension entirely.argumentsreplaces the arguments Zed passes (cpp_lsneeds none: it speaks LSP over stdio), and is where--log-level,--log-pathand--configgo.envis added to the shell environment.settings— answered to the server'sworkspace/configurationrequest for its owncpplssection. The one setting the server reads from the client today isexclude: glob patterns it must not analyse, which is the same list your editor uses to hide files. (The extension nests this under the section name for you; writing the{"cppls": {...}}section yourself is also accepted.)initialization_options— forwarded to the server asinitializationOptions.
The project's own configuration lives in the workspace root and is what most settings should be written in: it
travels with the repository, it is read by every client, and it is where the analysis is described. Every key is
optional; see docs/configuration.md for the
whole surface.
[workspace]
exclude = ["**/build/**", "third_party/**"] # what the analysis must not read
source_extensions = ["cuh"] # extensions added to the engine's own list
[compile]
standard = "c++20"
# database = "build/compile_commands.json" # when discovery would not find it
# args = ["-std=c++20", "-Iinclude"] # the project's whole command line
extra_args = ["-DFEATURE=1"]
[compile.cuda]
enable = true # .cu/.cuh read as CUDA, toolkit headers includedFor a project with several compilations, [[compile.target]] describes each one's sources, include directories and
defines. A dependency outside the workspace is a [[library]]. Diagnostics are switched per rule with
[diagnostics] disable = ["missing-include"], and the formatter is chosen with [format] formatter.
The server caches what it has read in .cppls/ under the workspace root (change it with [index] cache_dir); you
will want that directory in .gitignore.
Zed's semantic tokens are off by default. Turn them on globally (or per language) to get the server's names, types, macros, documentation commands and format strings:
{
"semantic_tokens": "combined"
}cpp_ls also sends two token types of its own. Zed has no style for them until you name one:
{
"global_lsp_settings": {
"semantic_token_rules": [
{ "token_type": "declarationKeyword", "style": ["keyword"] },
{ "token_type": "variableTemplate", "style": ["variable"] }
]
}
}The server answers textDocument/formatting and textDocument/rangeFormatting. It runs clang-format from
$PATH when it is there, and falls back to its own formatter when it is not, so format-on-save works on a machine
with nothing installed. To hear nothing about a missing clang-format, set [format] formatter = "cpp_formatter" in
.cppls.toml.
- The first workspace folder is what gets analysed.
cpp_lsopens one workspace root; if you add several folders to a Zed project, the server indexes the first one. .hheaders. A header is C or C++ depending on what includes it, so the server never guesses from the extension alone: it is told the language of the file the client opened. The extension maps Zed's language names to the ids the server expects (C→c,C++→cpp), which is what keeps C++-only rules off a C project's headers.- CUDA. Zed's
C++language already owns.cuand.cuh, so CUDA files are parsed from the first keystroke; the CUDA semantics come from[compile.cuda]in.cppls.toml. - Logs. The server writes a log file by default (its path is printed to stderr at startup) and honours
--log-path noneto stop. Zed's own log (zed: open log) has what the extension did.
cargo build --release --target wasm32-wasip2 # what Zed builds and runs
cargo clippy --release --target wasm32-wasip2 -- -D warnings
cargo fmt --all -- --checkThen run zed: install dev extension and pick this directory. Zed rebuilds the extension when the source changes.
The extension talks to Zed through zed_extension_api 0.7.0 and holds no state that matters: the only decisions
are which binary to start (see above), which arguments to pass, and how to
answer the server's configuration request.
MIT — see LICENSE.
cpp_ls itself is MIT-licensed and lives at CppCXY/cpp_ls.