vim

Martynas Maciulevičius 2024-08-06T11:38:08.370629Z

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?

Oliver Marshall 2024-08-08T09:29:24.345199Z

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 šŸ¤”

Martynas Maciulevičius 2024-08-08T09:32:52.629799Z

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

Martynas Maciulevičius 2024-08-08T09:37:21.429329Z

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.

Oliver Marshall 2024-08-08T09:38:22.169759Z

I don't think neovim is supposed to send the list of sources to the lsp server.

Martynas Maciulevičius 2024-08-08T09:38:36.952839Z

list of sourcesSorry, file changes and the file itself

Oliver Marshall 2024-08-08T09:39:34.202569Z

Sorry, do you mean it dosn't auto-format files that aren't opened?

Martynas Maciulevičius 2024-08-08T09:39:42.992469Z

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.

Martynas Maciulevičius 2024-08-08T09:40:05.795119Z

> 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"

Oliver Marshall 2024-08-08T09:40:29.163519Z

Yeah, that seems wrong to me on the lsp server side

Oliver Marshall 2024-08-08T09:40:49.514639Z

It should just read all the other files in the project

Martynas Maciulevičius 2024-08-08T09:43:36.507559Z

> It should just read all the other files in the project Doesn't this imply a bad architecture?

Oliver Marshall 2024-08-08T09:43:59.909759Z

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 šŸ™‚

Oliver Marshall 2024-08-08T09:44:26.299389Z

Doesn't this imply a bad architecture?I'd argue the opposite

Martynas Maciulevičius 2024-08-08T09:45:25.879809Z

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.

Oliver Marshall 2024-08-08T09:45:29.006459Z

Ideally lsp should be the thing that understands the language and the how it's projects are setup Neovim should "just edit text"

Oliver Marshall 2024-08-08T09:46:41.412239Z

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.

Martynas Maciulevičius 2024-08-08T09:47:19.678619Z

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.

Oliver Marshall 2024-08-08T09:48:21.011799Z

Why would it have to rescan a directory? It should just scan once on startup and then only rescan when a file is changed

Oliver Marshall 2024-08-08T09:50:17.535219Z

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?

Oliver Marshall 2024-08-08T09:51:02.580489Z

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?

Martynas Maciulevičius 2024-08-08T09:51:37.088489Z

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.

Oliver Marshall 2024-08-08T09:51:51.843799Z

I believe that rust-analyzer (from the brief times that I've used it) scanned all the files on startup for example

Martynas Maciulevičius 2024-08-08T09:52:13.517349Z

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.

Oliver Marshall 2024-08-08T09:53:28.273589Z

That's software for you šŸ˜…, can't avoid the edge cases forever

Oliver Marshall 2024-08-08T09:54:01.385629Z

Anyway, a minimal.lua + reproduction would help see where the problem is

Martynas Maciulevičius 2024-08-08T13:59:13.775149Z

Here it is. The temp config file is a pretty good tool. https://gitlab.com/invertisment/arduino-lsp-server-silent-failure

Martynas Maciulevičius 2024-08-08T14:17:29.389639Z

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.

Oliver Marshall 2024-08-07T07:06:05.165889Z

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 :)

Martynas Maciulevičius 2024-08-08T06:41:35.177619Z

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.