CMake LSP implementation based on Tower and Tree-sitter

Crates.io

It is a CMake lsp based on tower-lsp and treesitter

Install

bash cargo install neocmakelsp

Setup

The config of neocmakelsp is in nvim-lsp-config, so just follow nvim-lsp-config to setup it

neocmakelsp has two start ways: stdio and Tcp. Tcp is for debug. If you want to help me and debug is , you should start it with Tcp way.

Stdio

lua local configs = require("lspconfig.configs") local nvim_lsp = require("lspconfig") if not configs.neocmake then configs.neocmake = { default_config = { cmd = { "neocmakelsp", "--stdio" }, filetypes = { "cmake" }, root_dir = function(fname) return nvim_lsp.util.find_git_ancestor(fname) end, single_file_support = true,-- suggested on_attach = on_attach -- on_attach is the on_attach function you defined init_options = { format = { enable = true } } } } nvim_lsp.neocmake.setup({}) end

Tcp

```lua if not configs.neocmake then configs.neocmake = { defaultconfig = { cmd = vim.lsp.rpc.connect('127.0.0.1','9257'), filetypes = { "cmake" }, rootdir = function(fname) return nvimlsp.util.findgitancestor(fname) end, singlefilesupport = true,-- suggested onattach = onattach -- onattach is the onattach function you defined initoptions = { format = { enable = true } } } } nvim_lsp.neocmake.setup({}) end

```

Help needed

new version will not work on mac and windows, so I need your help

Features

If you want to use watchfile in neovim, use the nightly one, and set

lua capabilities = { workspace = { didChangeWatchedFiles = { dynamicRegistration = true, }, }, }

It will check CMakeCache.txt, and get weather the package is exist

TODO

Search

Search

symbol

Symbol

Complete and symbol support

Complete CompleteFindpackage

OnHover

onHover

GoToDefinition

Show JumpToFile

Tree

TreeShow

Format cli

Note: When formating files, make sure that your .editorconfig file is in your working directory

``` format the file

Usage: neocmakelsp {format|--format|-F} [OPTIONS] ...

Arguments: ... file or folder to format

Options: -o, --override override -h, --help Print help ```

It will read .editorconfig file to format files, just set like

ini [CMakeLists.txt] indent_style = space indent_size = 4

Note

The format do the min things, just do trim and place the first line to the right place by the indent you set, this means

```cmake function(A)

    set(A               
    B
        C
    )

endfunction()

```

it will just become

```cmake

function(A)

set(A
    B
        C
    )

endfunction() ```

It just remove the space in the end, replace \t at the begin of each line to , if set indent_size to space, and format the first line to right place. It does little, but I think it is enough.