kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Neovim LSP with Linux Kernel
@ 2023-09-19  7:45 Maciej Wieczór-Retman
  2023-09-19  9:24 ` Ricardo B. Marliere
  0 siblings, 1 reply; 4+ messages in thread
From: Maciej Wieczór-Retman @ 2023-09-19  7:45 UTC (permalink / raw)
  To: kernelnewbies

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.

-- 
Kind regards
Maciej Wieczór-Retman

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Neovim LSP with Linux Kernel
  2023-09-19  7:45 Neovim LSP with Linux Kernel Maciej Wieczór-Retman
@ 2023-09-19  9:24 ` Ricardo B. Marliere
  2023-09-19 10:45   ` Maciej Wieczór-Retman
  0 siblings, 1 reply; 4+ messages in thread
From: Ricardo B. Marliere @ 2023-09-19  9:24 UTC (permalink / raw)
  To: Maciej Wieczór-Retman; +Cc: kernelnewbies

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


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Neovim LSP with Linux Kernel
  2023-09-19  9:24 ` Ricardo B. Marliere
@ 2023-09-19 10:45   ` Maciej Wieczór-Retman
  2023-09-19 12:46     ` Ricardo B. Marliere
  0 siblings, 1 reply; 4+ messages in thread
From: Maciej Wieczór-Retman @ 2023-09-19 10:45 UTC (permalink / raw)
  To: Ricardo B. Marliere; +Cc: kernelnewbies

On 2023-09-19 at 06:24:24 -0300, Ricardo B. Marliere wrote:
>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?

Yes, quite often lately. Does it affect the indexing? I'll try using
output directory for .o files and binaries and I'll clean that less, maybe
that will help. Thanks.

>(...)
>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
>

I see you're using mason-lspconfig. Is the default nvim-lspconfig worse
somehow? I picked it because it seemed pretty simple and I wanted to
start with something straight forward but maybe mason handles some stuff
better?

-- 
Kind regards
Maciej Wieczór-Retman

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Neovim LSP with Linux Kernel
  2023-09-19 10:45   ` Maciej Wieczór-Retman
@ 2023-09-19 12:46     ` Ricardo B. Marliere
  0 siblings, 0 replies; 4+ messages in thread
From: Ricardo B. Marliere @ 2023-09-19 12:46 UTC (permalink / raw)
  To: Maciej Wieczór-Retman; +Cc: kernelnewbies

On 23/09/19 12:45PM, Maciej Wieczór-Retman wrote:
> On 2023-09-19 at 06:24:24 -0300, Ricardo B. Marliere wrote:
> >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?
> 
> Yes, quite often lately. Does it affect the indexing? I'll try using
> output directory for .o files and binaries and I'll clean that less, maybe
> that will help. Thanks.

I think this is what's causing the constant re-indexing, then. Maybe use
a 'static' tree-dir just for browsing the code using the LSP? The output
directory is a good idea, I'll try it out aswell - thanks!
> 
> >(...)
> >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
> >
> 
> I see you're using mason-lspconfig. Is the default nvim-lspconfig worse
> somehow? I picked it because it seemed pretty simple and I wanted to
> start with something straight forward but maybe mason handles some stuff
> better?

Mason is just a nice frontend for installing LSPs, DAPs, Linters and
Formatters. I use it because sometimes I like to explore the available
tooling :)

I shared that snippet only to show the usecase of setting up all
installed servers and starting clangd only if there is a
compile_commands.json available. Thought it could be helpful.

Good luck,
-	Ricardo

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-19 12:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19  7:45 Neovim LSP with Linux Kernel Maciej Wieczór-Retman
2023-09-19  9:24 ` Ricardo B. Marliere
2023-09-19 10:45   ` Maciej Wieczór-Retman
2023-09-19 12:46     ` Ricardo B. Marliere

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).