57 releases

0.6.22 Apr 3, 2024
0.6.20 Mar 7, 2024
0.6.19 Jan 17, 2024
0.6.17 Dec 3, 2023
0.2.4 Jul 17, 2022

#4 in Text editors

Download history 633/week @ 2024-01-01 541/week @ 2024-01-08 1288/week @ 2024-01-15 785/week @ 2024-01-22 648/week @ 2024-01-29 611/week @ 2024-02-05 693/week @ 2024-02-12 620/week @ 2024-02-19 636/week @ 2024-02-26 1330/week @ 2024-03-04 1097/week @ 2024-03-11 826/week @ 2024-03-18 749/week @ 2024-03-25 1415/week @ 2024-04-01 992/week @ 2024-04-08 986/week @ 2024-04-15

4,246 downloads per month

MIT license

3.5MB
3.5K SLoC

CMake LSP implementation based on Tower and Tree-sitter

Crates.io

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

Install

cargo install neocmakelsp

Setup For neovim

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

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
                }
                scan_cmake_in_package = true -- default is true
            }
        }
    }
    nvim_lsp.neocmake.setup({})
end

Tcp

if not configs.neocmake then
    configs.neocmake = {
        default_config = {
            cmd = vim.lsp.rpc.connect('127.0.0.1','9257'),
            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

Setup for helix

Tcp (good for debug)

[[language]]
name = "neocmake"
auto-format = true
language-servers = [{ name = "neocmakelsp" }]

[language-server.neocmakelsp]
command = "nc"
args = ["localhost", "9257"]

Stdio

[[language]]
name = "cmake"
auto-format = true
language-servers = [{ name = "neocmakelsp" }]

[language-server.neocmakelsp]
command = "neocmakelsp"
args = ["--stdio"]

Help needed

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

Features

  • watchfile
  • complete
  • symbol_provider
  • On hover
  • Format
  • GO TO Definitation
    • find_package
    • include
  • Search cli
  • Get the project struct
  • It is also a cli tool to format

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

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

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

TODO

  • Undefined function check

Show

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] <FormatPath>...

Arguments:
  <FormatPath>...  file or folder to format

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

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

[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

function(A)

        set(A               
        B
            C
        )

    endfunction()

it will just become


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.

Dependencies

~14–28MB
~411K SLoC