-
Notifications
You must be signed in to change notification settings - Fork 185
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
Show popup with code actions when hovering over lightbulb icon #1929
Show popup with code actions when hovering over lightbulb icon #1929
Conversation
Well, the icon is not really clickable, sorry for the clickbait title ;) It should show a small hover popup when you hover over the gutter icon. Doesn't it work for you? I think what happened in your GIF, is that when you clicked on the icon, it selected the full line and the caret moved to the next line. Because of that, the lightbulb went away (the popup should only show when there is currently a lightbulb at the same place where you hover over the gutter). I've tested also with multiple code actions on a line, and then it should open the command palette when you click the link, just like how it works for the annotations and the "normal" hover popups. |
Yeah, the title got me confused.
It does work when I hover over the icon. :) |
By the way, to give a bit more context; initially I intended to show all available code actions for the entire line when hovering over the lightbulb icon. But then I realized that the icon is not necessarily shown in the line where the diagnostics are, but rather where the selection starts. This is a result of how the code actions are requested for the combined covering region of the selection & diagnostic: Lines 527 to 529 in 19a01aa
If the selection starts at a previous line, then the lightbulb will be shown at the line where the selection begins, and not at the line where the diagnostic is / begins. Therefore I used the exact same logic when showing the available code actions on gutter hover. But I wonder whether LSP is doing the correct thing in general by combining the regions, when the code actions are requested from the server. It seems that this can cause possible issues when a code action is executed, too. Look at the following example: This is when I execute a code action with an empty selection, using the Lua server (everything works as expected): Now I execute the same code action, but with a selection starting at a previous line. Notice how the line comment from the code action gets inserted at a wrong position (at the line in front of the selection). Is this a bug in the Lua server, or should LSP better use only the region where the diagnostics are, when requesting code actions? What do you think in general about the popup when hovering the gutter icon? We could also add the same for the diagnostic icons, i.e. a popup could show all the diagnostics which are contained in that line, but of course without all the additional symbol information which is often there in the normal hover popups. |
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 do think the code for building the minihtml should be shared between the two features, can you make that happen?
Yes, I will try to do that. |
Looks like as server issue to me. It should know where the diagnostic is located and where the comment should be inserted so it doesn't make sense that it chooses to insert it at the first line of the selection. And for reference, it returns the edit in the initial code action response already. For example:
|
The code to create the minihtml for the code actions is reused from hover.py now, and I removed the additional request when hovering over the lightbulb, because it wasn't really necessary. There is still a bit of duplication of the code for handling of clicking on the link, but I think sharing this code would need some bigger refactoring of LspHoverCommand. |
I always wondered why this wasn't implemented yet, I would expect the dynamic lightbulbs to be interactive
I think it is a nice little addition, but feel free to close if popups from mouse hover over the gutter are not desired.
Most of the code is copied from hover.py, so maybe it would be possible / better to refactor the code a bit to reduce duplication, if we want to proceed to merge this.