I'm using rust-analyzer with nvim-lsp and need some help figuring out how to configure it. I want it to run when I save a file (which it does), but don't want it to keep running while I edit a file. Being surrounded by errors when I'm in the process of writing (obviously unfinished) code is distracting to me.
Is there a config option to override the latter behavior? From the doc I'm just not sure which of the many options are relevant here, and whether I can override them selectively, or have to define all of them once I don't rely on the implicit defaults.
I would say that this needs to be a client-option (hiding errors while user is typing), as, fundamentally, the LSP model is that the code is just in some state, there’s no real „do something on save“ concept (there a fake one though )
There’s config to disable cargo check on save (checkOnSave.enable) and a separate one to disable “native” diagnostics (diagnostics.enable).
I see. So what you're saying is that if implemented, it would be on the lsp component built into nvim, right? I take it the LSP model doesn't prevent the client from only firing server queries on save (the "fake one"), making the behavior I desire feasible?
Yep, the LSP only has knowledge of "code has changed from the current state to a new state". (There's two ways it's allowed to do this: replace a whole file, or incremental edits.)
The LSP client can then, if it wants to, decide how quickly or how slowly to send updates to the server. At the very least, it's probably pragmatic to debounce updates for "while the user is typing" based on whatever that editor's heuristics are.
A more "correct" solution, though, is to not debounce edits all the way to the "save" action, but to just not display results until they're relevant. This is mainly due to incrementality and allowing the server to respond quicker.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.