I'm doing some arduino things via nvim and I'm tired of needing to format my code by hand because the arduino-language-server doesn't work properly.
There are no LSP messages in the log and I can't debug the issue so I'm trying to find a workaround.
It's some kind of a silent failure because it works for single-file projects but once I load my 500 LOC proejct with multiple .ino files then it fails -- it's as if arduino-language-server is a toy environment somehow.
I tried to run ccls side-by-side but then it starts to mess with how symbols are resolved and it's not ideal.
Currently I think about running a CCLS instance under some kind of LSP proxy that would silence the messages of ccls and retain only the auto code formatting.
Is this possible? Is there a name for this kind of LSP server?
Sorry, I'm not quite sure what you mean? Do you mean you have to open every file in the project in nvim and then start the lsp? Because if so that definitely sounds like a bug in the lsp. I've worked on plenty of projects using lsp and this has never been a requirement for me š¤
This is how it works:
1. Open my .ino source file
2. Go to NvimTree menu, open each file by hand
3. Move some code around (format something in a bad way)
4. Save
5. Auto-format plugin invokes LSP's save function
6. Content changes (yay, formatting worked!)
7. Save is complete
Case when it doesn't work:
1. Open my .ino source file
2. Don't load other files from the editor
3. Move some code around (format something in a bad way)
4. Save
5. Auto-format plugin invokes LSP's save function
6. Content remains the same (badly formatted code)
7. Save is complete
Basically this means that when NVIM doesn't send the sources to the LSP server then the LSP server has an incomplete view. And if the LSP server refuses to format code with this incomplete view then this lazy file loading is painful.
I don't think neovim is supposed to send the list of sources to the lsp server.
list of sourcesSorry, file changes and the file itself
Sorry, do you mean it dosn't auto-format files that aren't opened?
From what I understand LSP server doesn't go into the filesystem and edit my file on my behalf. This means that the editor is what has the editing right.
> Sorry, do you mean it dosn't auto-format files that aren't opened? Auto-format for opened files doesn't work if the LSP server decides it doesn't have a "complete picture"
Yeah, that seems wrong to me on the lsp server side
It should just read all the other files in the project
> It should just read all the other files in the project Doesn't this imply a bad architecture?
Would you mind putting together a minimal reproduction?
Telescope has a good https://github.com/nvim-telescope/telescope.nvim/blob/3b1600d0fd5172ad9fae00987362ca0ef3d8895d/.github/ISSUE_TEMPLATE/bug_report.yml?plain=1#L81 for a minimal.lua file that you can run with nvim -nu minimal.lua
If I can't help with your issue it'll at least go a long way in helping others help you š
Doesn't this imply a bad architecture?I'd argue the opposite
What I meant by it is that the LSP server has to read the filesystem but also receive things from the editor. This seems to be a possible consistency issue for me.
Ideally lsp should be the thing that understands the language and the how it's projects are setup Neovim should "just edit text"
I don't really know enough about the implementation/protocol of lsp servers to comment on if there would be inconsistency or not. I could see it not being an issue though.
If the LSP server decides to rescan the directory and the editor has a work-in-progress state then that state could get overwritten. It could for instance happen on startup when the editor reads its own cache of some sort -- like LibreOffice restore does.
Why would it have to rescan a directory? It should just scan once on startup and then only rescan when a file is changed
I'm not sure what you mean by your LibreOffice example. Do you mean: on startup the lsp server scans the files then during that scan you edit a file and save it?
That seems unlikely as I think the scanning should be pretty quick, and even if not you could setup a listener for file changes while you do your initial scan right?
LSP server could scan on startup but that version is stale. Instead the editor was shut down previously and saved its own cached version and now the LSP server is trying to overwrite this restored version with their own freshly read old file contents.
I believe that rust-analyzer (from the brief times that I've used it) scanned all the files on startup for example
I'd also like the LSP servers to scan everything. It would save a lot of trouble. I was trying to say it's not a silver bullet and there still will be bugs.
That's software for you š , can't avoid the edge cases forever
Anyway, a minimal.lua + reproduction would help see where the problem is
Here it is. The temp config file is a pretty good tool. https://gitlab.com/invertisment/arduino-lsp-server-silent-failure
The project is valid and will actually properly compile. And run. And work. No issues at all. It's simply empty. I'll add this note to the repository.
I haven't heard of that type of lsp server before, but it sounds very doable. Before you go down that route, I think you can disable features by manually setting the capabilities of the server in neovim but I've not tested it so ymmv. There are some proxies that log the lsp messages so I maybe that would help you debug. It may also be worthwhile submitting an issue to the Arduino lsp repo to help them improve things :)
I found a case when the arduino LSP server works. If I open the project and load every buffer from the sources then the LSP server doesn't bug. This means that it's actually not a bug in arduino LSP but in NVIM. Do you know if there is a setting or plugin that loads every file in a git repository? I'm struggling to find something like it.