LSP icon indicating copy to clipboard operation
LSP copied to clipboard

Feature request: Toggle showing of diagnostics

Open mcclure opened this issue 2 years ago • 8 comments

Is your feature request related to a problem? Please describe.

I have a tendency to hit ctrl-S to save very frequently and without thinking about it. Sometimes this results in LSP coming up before its help is particularly helpful. Sometimes, the annotations it provides are obtrusive:

image

If I was looking for a bug, this outline would be quite helpful, so I don't want to turn off these annotations. But sometimes I don't need it yet. If I am still working on the function it is just distracting.

Describe the solution you'd like

I would like a Sublime Text "command" I could map to a key shortcut, which temporarily dismisses everything LSP, as if I had not yet saved. Remove all annotations, and hide the diagnostics panel. However I don't want this dismissal to be modal, IE, I don't want to have to turn it back on again. I just want it to remove itself until I next hit save and it brings itself back up again.

Describe alternatives you've considered

LSP was initially my alternative :) I used to use rust-enhanced which has even more obtrusive annotations.

The ESC key already hides the bottom pane; there could be an option for it to hide annotations as well.

I guess one additional possible alternative would be a keystroke to hide LSP annotations altogether, a feature I think already exists. But if I did this I am afraid (ok, I am certain) I would forget to turn them back on again and then they would not be there when I needed them.

Notes

I think this should also hide "Inlay Hints" once that feature is added(?).

mcclure avatar Jan 02 '23 19:01 mcclure

I have a tendency to hit ctrl-S to save very frequently and without thinking about it. Sometimes this results in LSP coming up before its help is particularly helpful.

But diagnostics typically come up on typing so I'm not sure why is there an implication here that this is a "on save"-only problem.

In any case, your suggested solution sounds very corner-case and manual and not that universally useful to be honest. I think you could look at suggestion in #2117 which might also solve your use case if implemented.

rchl avatar Jan 02 '23 21:01 rchl

I think you could achieve this with a plugin in your User/ folder that could, for example, toggle the show_diagnostics_severity_level setting in the User/LSP.sublime-settings file between 0 and 4.

rwols avatar Jan 02 '23 21:01 rwols

Though that would result in restarting the server which can be slow for Rust.

rchl avatar Jan 02 '23 21:01 rchl

But diagnostics typically come up on typing so I'm not sure why is there an implication here that this is a "on save"-only problem.

I only started using LSP today. So this sounds like the problem is actually worse than I thought? D: I assumed diagnostics were shown on save because of the show_diagnostics_panel_on_save setting.

In any case, your suggested solution sounds very corner-case and manual and not that universally useful to be honest. I think you could look at suggestion in #2117 which might also solve your use case if implemented.

I don't think 2117 exactly solves the problem because I might write half a function and then stare at it for a minute or leave the computer to go get a glass of water or something.

It seems like "Don't show me stuff until I'm ready to look at it" is not that unreasonable a request, and saving the file is a good way of signaling I'm ready to look at it (except for my tendency to save when I shouldn't).

mcclure avatar Jan 02 '23 22:01 mcclure

I second this. Was just going to open an issue asking if this was possible

I use LSP-pyright, and while im coding there are alot of false positives or just simply alot of real errors. It can make it abit hard to read the code to understand it before I can start working on improving it.

I wrote a command to toggle show_diagnostics_severity_level between 0 & 4. But that restarts the server and takes a decent amount of time before it shows any result (which leaves me waiting to see if there was any issues or if its still loading as i have no way of differentiating)

It would be really helpful to be able to disable highlighting without restarting the server to make reading the code easier, then quickly toggling it back on to handle the errors. Is it even possible?

ta946 avatar Feb 09 '24 05:02 ta946

As mentioned in https://github.com/sublimelsp/LSP-ruff/issues/67, in VSCode ecosystem the extensions sometimes provide option like `lint: onSave | onType'. For servers that support pull model for diagnostics, the client could decide when to update the diagnostics so in that cases we would at least be able to do something.

(though initial post mentions hammering "save" at random times so it would probably not help that case ;))

rchl avatar Jul 23 '24 10:07 rchl

For the diagnostics pull model it doesn't seem that difficult to implement an option for requesting diagnostics only on save, instead of after each change. We would just need to add a check of such a user setting before doing the request at https://github.com/sublimelsp/LSP/blob/f98334571229215ffed9d7a02b8a9ccfd9d4093a/plugin/session_buffer.py#L347-L352 and then also add similar code either in the DocumentSyncListener.on_post_save_async or directly in the LspSaveCommand.

However, this would also mean that diagnostics are not automatically cleared anymore when you just fixed an error in the code (except for if you select and remove the entire line/block). Not sure whether this behavior would be better than the current situation, or how it is handled in other editors. But I guess an option can't hurt, so that users could choose their preferred behavior. I thought about this problem before, and I think ideally we would want to add new diagnostics only after a delay (or on save), but always immediately clear diagnostics which were removed. However, the problem is that either the LSP specs would need a new feature of incremental diagnostics updates (with "deltas" like for semantic tokens), or each diagnostic would need to have some kind of ID, so that we could know which of the diagnostics are old and which are new. The range and message (the only required fields) are not really sufficient for that to decide, because they might change even after small buffer updates and even if the diagnostic should be considered to be the same one.

By the way, I have a PR open at #2448 which would not restart servers anymore when the show_diagnostics_severity_level setting gets changed, but there haven't been any reviews yet.

jwortmann avatar Jul 23 '24 14:07 jwortmann

I was just searching issues to see if someone had suggested this before - more control over when diagnostics are shown would be very valuable to me, too. The option to show new diagnostics only after a timer would help a bit, only on save would be a significant improvement. (And at least to me, it would be nice but it's not really important that diagnostics are immediately cleared vs. only cleared on saving again.) A reasonable way to toggle diagnostics and show them only when I'm ready to deal with them would also be a big help to me, ideally with the ability to bind this to a hotkey.

It is extremely distracting to me to have error or warning indicators and underlines showing up in code while I am actively typing it. The diagnostics are very helpful in catching errors, but I do not want to see them appearing and disappearing while I am still in the middle of typing something.

pineapplemachine avatar Jul 31 '24 10:07 pineapplemachine