Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Toggle showing of diagnostics #2161

Open
mcclure opened this issue Jan 2, 2023 · 8 comments
Open

Feature request: Toggle showing of diagnostics #2161

mcclure opened this issue Jan 2, 2023 · 8 comments

Comments

@mcclure
Copy link

mcclure commented Jan 2, 2023

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

@rchl
Copy link
Member

rchl commented Jan 2, 2023

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.

@rwols
Copy link
Member

rwols commented Jan 2, 2023

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.

@rchl
Copy link
Member

rchl commented Jan 2, 2023

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

@mcclure
Copy link
Author

mcclure commented Jan 2, 2023

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

@ta946
Copy link

ta946 commented Feb 9, 2024

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?

@rchl rchl changed the title Feature request: Temporarily dismiss LSP Feature request: Toggle showing of diagnostics Mar 5, 2024
@rchl
Copy link
Member

rchl commented Jul 23, 2024

As mentioned in sublimelsp/LSP-ruff#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 ;))

@jwortmann
Copy link
Member

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

self.do_document_diagnostic_async(view, version)
if self.session.config.diagnostics_mode == "workspace" and \
not self.session.workspace_diagnostics_pending_response and \
self.session.has_capability('diagnosticProvider.workspaceDiagnostics'):
self._workspace_diagnostics_debouncer_async.debounce(
self.session.do_workspace_diagnostics_async, timeout_ms=WORKSPACE_DIAGNOSTICS_TIMEOUT)

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.

@pineapplemachine
Copy link

pineapplemachine commented Jul 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants