CMake LSP Implementation.
Alpha Stage, work in progress.
- Builtin command completion
- Documentation for commands and variables on hover
- Formatting (by
cmake-format
)
cmake-language-server
: LSP server
$ pip install cmake-language-server
- Neovim (neoclide/coc.nvim, prabirshrestha/vim-lsp)
"languageserver": {
"cmake": {
"command": "cmake-language-server",
"filetypes": ["cmake"],
"rootPatterns": [
"build/"
],
"initializationOptions": {
"buildDirectory": "build"
}
}
}
if executable('cmake-language-server')
au User lsp_setup call lsp#register_server({
\ 'name': 'cmake',
\ 'cmd': {server_info->['cmake-language-server']},
\ 'root_uri': {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'build/'))},
\ 'whitelist': ['cmake'],
\ 'initialization_options': {
\ 'buildDirectory': 'build',
\ }
\})
endif
buildDirectory
This language server uses CMake's file API to get cached variables. The API communicates using<buildDirectory>/.cmake/api/
.buildDirectory
is relative path to the root uri of the workspace. To configure the build tree, you need to run the cmake command such ascmake .. -DFOO=bar
.