Neovim LSP with Linux Kernel

Ricardo B. Marliere ricardo at marliere.net
Tue Sep 19 05:24:24 EDT 2023


On 23/09/19 09:45AM, Maciej Wieczór-Retman wrote:
> Hi,
> I'm using neovim for a long time now and I've been using ccls as the LSP
> for anything in C. It's working very well with userspace programs (with
> "bear -- make" to generate compile_commands.json) but it seems to take
> up a lot of CPU power whenever I reboot and open any kernel code.
> 
> The kernel provides it's own way to get compile_commands.json and I
> understand that ccls needs a bit of time to index these thousands of
> files.
> 
> But does anyone know if there is a way to avoid indexing files so often?
> Or maybe is there a better LSP for C? I couldn't really find anything
> else and I'm running Arch Linux which suggests it's the recommended one
> for C.

Hey there Maciej!

I've been using clangd with no problems, the indexing is expensive but
after that it's a breeze. Are you cleaning your tree very often?

(...)
local lspconfig = require("lspconfig")
local get_servers = require("mason-lspconfig").get_installed_servers
for _, server_name in ipairs(get_servers()) do
  if server_name == "clangd" then
    local compile_commands = vim.fn.getcwd() .. "/compile_commands.json"
    if vim.fn.filereadable(compile_commands) == 1 then
      lspconfig[server_name].setup({
        on_attach = LSPAttach,
        capabilities = LSPCapabilities,
        offset_encoding = "utf-16",
      })
    end
  else
    lspconfig[server_name].setup({
      on_attach = LSPAttach,
      capabilities = LSPCapabilities,
      offset_encoding = "utf-16",
    })
  end
end




More information about the Kernelnewbies mailing list