Search code examples
pluginsluaneovimlanguage-server-protocol

Issue with cmake-language-server LSP when working with CMake files


I recently finished configuring my neovim environment, mainly for working with python/c/cpp projects, I even managed to configure a dap setup which "kind of" works I guess. My problem is when it comes to syntax highlighting/general usage of the LSP client for CMake, nothing seems to work even though I configured it exactly the same way as other LSPs I'm currently using.

My neovim version is: NVIM v0.8.1 I installed the server using the Mason plugin. The server is correctly installed and appears in :LspInfo but is never attached to any buffer I create.

I created a project with multiple folders including a .git and build folders, which should be triggered as the root dir so the LSP should be attached to the CMakelists.txt file or Makefile file, or at least that's what I understood in the https://github.com/regen100/cmake-language-server description.

My LSP configuration is the same as this one: https://github.com/LunarVim/nvim-basic-ide/blob/master/lua/user/lsp/mason.lua adding to the servers the CMake one. I can provide some more screenshots showing other LSP clients working fine out of the box with their buffers but the CMake being active and not attaching to any CMake file I create.

LSP client not attached

The server is correctly installed and in path with Mason plugin:
The server is correctly installed and in path with Mason plugin

Do you guys have any idea why am I having this issue? Needless to say I'm a total beginner when it comes to vim/neovim stuff, and I recently managed to put together kind of a semi-decent configuration copying plenty of the options Chris and other developers from lunarvim shared in their repos.

I tried creating multiple CMake and Make style files. Plus adding more folder so that the root directory would be detected and the LSP client could be attached to the buffer successfully.


Solution

  • Thanks to @starball I decided to see if I somehow could modify the filetypes requirements for the cmake client. It seems like there are multiple ways of achieving that, for the record the first one is more for a more general neovim configuration search for config.filetypes link.

    And for my specific setup I did the following:

    1. Add a cmake.lua file under the path /lua/user/lsp/settings/
    2. Configure the desired CMake filetypes Configuration used

    Result in the previously defined buffer, as well as some other .cmake files:

    LSP Client successfully attached to buffers