Skip to content

leg0/neocmakelsp

 
 

Repository files navigation

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

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
        }
    }
    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
        }
    }
    nvim_lsp.neocmake.setup({})
end

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

Search

symbol

Symbol

Complete and symbol support

Complete CompleteFindpackage

OnHover

onHover

GoToDefinition

Show JumpToFile

Tree

TreeShow

Format cli

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 .editconfig file to format files, just set like

[CMakeLists.txt]
indent_style = tab
indent_size = 2

If you don't want to format a part, just comment Not Format Me before that block

About

Another cmake lsp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 68.1%
  • CMake 31.5%
  • Lua 0.4%