-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add menu item to disable/enable hover popups #2316
Conversation
Hello! I tried it out a bit, and yes, it does indeed cover the functionality I was requesting in #2315. That's great news! Huge thanks to you! I've bound the Regarding the design, this is a workable solution. I do need to use it a bit longer, but I can foresee one possible inconvenience, which is why I placed the switch hotkey option as the second point in #2315: You don't always remember the current state. Additionally, given that the current implementation enables/disables hovers per window, it's hard to remember the state of it in each window. An indicator in the status bar could be helpful, but only if it is in a bright, screaming color that could be spotted out of the corner of the eye (and it should be persistent, similar to a branch indicator). I need to see how it goes, but I can already say for sure that it closes much-needed functionality. After further testing, this pull request should definitely be merged into the main branch. In terms of covering my use case, I would like to emphasize that it would still be beneficial if there was an option to bind the LSP hover popup trigger to a hotkey. This way, both the built-in hover popup and the LSP server popup could be accessed when needed without the need to toggle any settings. Nonetheless, if the last mentioned thing is challenging or impossible to implement, here are a couple of other ideas that could cover the points in #2315 in a slightly more convenient manner (the last suggestion is an enhancement on top of your newly introduced solution):
|
I would be very much against this, imo there are already too many things in the status bar enabled by default. It could be possible to make the toggle work globally, instead of per window, but iirc the "LSP: Show Inlay Hints" toggle is also per window (and also most of the built-in options under the "View" menu). So I made this one work per window too, for consistency. The LSP popups are enabled by default for new windows or after a restart of ST, because I think that in most situations and for most people the LSP popups are welcome.
This should already be possible via
Not possible, there can always only be a single popup visible. The "show_definitions" popup is implemented in
Hm, perhaps this could be possible to implement, but with the ST API you can only check whether there is some popup visible, but not which one or where it comes from. Also we can't retrigger the |
One thing I realized is that when the LSP popups are disabled, this will also prevent the "Follow Link"/"Open in Browser" popup for documentLinkProvider, which may or may not be part of a regular hover popup. But with the current implementation of having those links shown as part of the regular popups, I think there is no way around that. Also since the LSP client doesn't have any information about what the hovered text (in this case a link) is, we can't really know if ST built-in "show_definitions" would show a popup for the hovered text. So we couldn't decide whether it is desired or not to show a popup/tooltip over links, which could potentially block the built-in popups. |
To have it persist after restart, it would need it to be stored somewhere, i.e. we need a new global LSP setting The decision to make the toggle work per window was mainly driven to be consistent with the inlay hints toggle.
I'm a bit confused if I understand correctly what you mean, but this should actually be the exact point that this PR tries to solve. Make sure to remove the
Yes, diagnostics are part of the hover popups and they will not be shown when LSP popups are toggled off. There is no way around that. The only solution I could think of would need heavy changes in ST core to rewrite the And your first recording (with hover capability disabled) even looks a bit buggy to me, because there is a short flicker of the built-in ST popup before the diagnostics popup will be shown, or it's random which one is shown. This is because both the built-in
I can't reproduce that on my side. In fact, it does reset the view's setting to the original value (unless there is some bug in that code, which I have missed):
Yes, this is the point of this PR :D |
True, flickering can be seen, but it happens quite rarely, and still, this behavior helped to have both sublime "show_definitions" and the LSP diagnostics available at the same time, with my previous kind of setup. By the way, it's not random; the diagnostics always pops up last, for sure. I used it like this for two years.
Sorry, you're right, on this branch it works just fine! This way, it definitely satisfies my needs and fits my use cases, and I can disregard all other thoughts and ideas that I mentioned. Even regarding the absence of error/warning diagnostics popups when LSP-mouse-hover-popups are disabled: now I can view the same message if I invoke So, to be understood correctly, here's my workflow setup right now on the current branch:
One little suggestion: since the Everything else is good, I will stay on this branch with the setup described and eagerly wait until it will be merged into the master. Cheers! |
omg😁 just realized that this one:
is not actually satisfied since I need to re-disable it each time after restarting the ST. Well, I understand the arguments, and I don't know what would be better for most of the users (global or window-based disabling). So, the only option that comes to my mind is to think about adding two features: toggle LSP hover for the view/window AND toggle it globally. This way, no one will be harmed :) |
Are there any other opinions or objections about this PR? I think there are three possible design choices:
I would actually be in favor of (2) and think that the global toggle for the functionalities (popups and inlay hints) would be a better design, but since the inlay hints toggle was implemented per window in the end I guess I'm in the minority here. But it's not very important to me and people probably don't like changes. For (3) I think that it's not really needed, even if it means a bit on inconvenience for a (probably very small) amount of users. Regarding the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just gonna address the last comment since there is way too much discussions here to be able to follow all that.
I prefer per-window switch for inlay hints rather than global. That's because while that feature is annoying due ST issues, there are some projects where it can be more useful.
So if we are are consistent, this should also be per-window.
If we'd want to have a global switch for it then I'd just make the code respect show_popup_on_hover
.
plugin/core/constants.py
Outdated
# TODO: Move all constants into this file, so that all other modules can import them without causing import loops | ||
|
||
HOVER_HIGHLIGHT_KEY = "lsp_hover_highlight" | ||
HOVER_PROVIDER_COUNT_KEY = "lsp_hover_provider_count" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I like the idea of having all constants in a single file. I think the constants are easier to manage when they are together with relevant piece of the code.
Maybe there is a place for some global constants but I wouldn't make it a rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can mark all local / file-specific constants with a leading underscore and only move constants which are shared between multiple files into a common place like this?
We basically already have a part of this in views.py
, but it's questionable to me why that file is named views
and I think it would be better to only have imports from .protocol
and .typing
in the file which collects all the shared constants.
A built-in setting with this name doesn't seem to exist (I think it was a bit of a misunderstanding in one of the issues). Or should it suggest to intruduce a new LSP setting with that name? I would be okay with the per-window toggle for the features, even though it's not the optimal solution in my opinion. |
So I was going to do a final review pass on it but then I've noticed that this setting doesn't work like the corresponding Inlay Hints toggle. That is, it is not stored per window. Was this conscious decision to make it different from the Inlay Hints toggle? |
I haven't looked at this PR for a while, but I think it should be intended to work per window at the moment. If it doesn't, then that would be a bug. But at my side it seems to work as expected; when I disable the menu item no LSP popups are shown in the window, even when I switch to files with a different server running. And when I open another window, I can disable/enable the popups independently of the current state from the first window. Do you have some steps how I could reproduce a case where it doesn't work? |
The setting works per-window but it's not stored in window settings like the inlay hints equivalent so it doesn't survive ST restart. |
Interesting, I didn't know you could do that. PR updated and I think it should work now. |
Here is an idea.
Closes #2315
Closes #1967
Closes #1840
It adds a menu item under the "View" main menu which can be used to temporarily disable LSP hover popups. This takes effect per window, like several of the other built-in items from the "View" menu (Side Bar, Minimap, Status Bar, ...).
If desired, it's also possible to setup a key binding for the
lsp_toggle_hover_popups
command, but this command is only available if there is a session (LSP server) currently running for the active view, which can provide hover popups.@rusproject If you like to try it out and report back if this is a good or bad design or whether there are any bugs, testing of this PR by setting up LSP from this Git branch would be welcome.
This PR should also fix a bug that the View's "show_definitions" setting was unconditionally (re)set to
true
, instead of the actual user value from the global preferences file, when (all) LSP servers with hoverProvider are being disabled. Proper implementation now added viareset_show_definitions
method.