This is CMake extension for Zed editor. It combines uyha/tree-sitter-cmake and Decodetalkers/neocmakelsp (hence why it's "neo"). The tree-sitter grammar is taken from helix repo.
For making clangd and cmake work together do the following:
- Add
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
at the top of theCMakeLists.txt
(somewhere belowproject
); - Reconfigure cmake project. If everything is correct there should be
compile_commands.json
file under build directory. I also advise usingCXX=clang
for better compatibility with clangd; - Go to Zed's
settings.json
: Ctrl+Shift+Popen local settings
/open default settings
; - Find
lsp
section. Inside it paste the following (replacebuild
with your build directory name):
"clangd": {
"arguments": ["-background-index", "-compile-commands-dir=build"]
}
Until adding tasks to the extension is possible here are some templates for CMake project. Note that by default all tasks use build
directory, but you can change it
{
"label": "CMake configure Debug",
"command": "cmake",
"args": ["-DCMAKE_BUILD_TYPE=Debug", "-B", "build/"],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
}
{
"label": "CMake build",
"command": "cmake",
"args": ["--build", "build"],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
}
{
"label": "CMake configure Debug and build",
"command": "cmake -DCMAKE_BUILD_TYPE=Debug -B build/ && cmake --build build/",
"args": [],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
}
[
{
"label": "CMake configure Debug",
"command": "cmake",
"args": ["-DCMAKE_BUILD_TYPE=Debug", "-B", "build/"],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "CMake configure Relase",
"command": "cmake",
"args": ["-DCMAKE_BUILD_TYPE=Release", "-B", "build/"],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "CMake build",
"command": "cmake",
"args": ["--build", "build"],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "CMake configure Debug and build",
"command": "cmake -DCMAKE_BUILD_TYPE=Debug -B build/ && cmake --build build/",
"args": [],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "CMake configure Release and build",
"command": "cmake -DCMAKE_BUILD_TYPE=Release -B build/ && cmake --build build/",
"args": [],
"env": {},
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
}
]