-
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
Allow user to send textDocument/hover with range if needed #1898
Conversation
This a better alternative to scalameta/metals-sublime#45 and this implementation is just a workaround until microsoft/language-server-protocol#377 is part of the LSP spec
@@ -210,14 +229,14 @@ def _show_hover(self, listener: AbstractViewListener, point: int, only_diagnosti | |||
|
|||
if contents: | |||
if self.view.is_popup_visible(): | |||
update_lsp_popup(self.view, contents) |
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.
There could be already a pop due a hover which is in a different location from the selection. So we should close it to show the new popup at the right place
I would much prefer the solution I've mentioned in the metals repo. With my suggestion everything would work without any extra code in the metals package (apart for the override to enable a flag) and without accessing (semi) internal stuff. With changes here, things still won't work automatically on mouse hover. |
And since that feature has a high chance of getting into the spec (it seems), it would be very simple to just remove the flag later and have the feature enabled by default if it's done properly from the start. |
I think from the LSP-* side it doesn't really matter if there is a need to send an explicit argument with the command or setting some flag. What ever works best for you and @rwols
Line 415 in c1e25f0
|
What do you think has to be changed here? I would think we can always send a point to |
I thought the check would be done there before calling |
Why can't we send the
or would this break some servers? |
|
This client puts the range in the |
That is somehow worse 😅 |
@@ -72,6 +72,11 @@ class InsertTextMode: | |||
'position': Position, | |||
}, total=True) | |||
|
|||
TextDocumentRangeParams = TypedDict('TextDocumentRangeParams', { |
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.
There is no TextDocumentRangeParams
in the lsp spec,
so I would move the TextDocumentRangeParams
type from protocol.py to plugin/core/views.py
I went through @rchl suggestion, and I think it is ok. def request_symbol_hover_async(self, listener: AbstractViewListener, point: int) -> None:
hover_promises = [] # type: List[Promise[ResolvedHover]]
document_position = text_document_position_params(self.view, point)
for session in listener.sessions_async('hoverProvider'):
+ hover_supports_range = session._plugin.get_experimental_flags().get('hover_supports_range', False)
+ if hover_supports_range:
+ hover_range = None
+ for region in self.view.sel():
+ if region.contains(point):
+ hover_range = region_to_range(self.view, region).to_lsp()
+ if hover_range:
+ document_position['position'] = hover_range
hover_promises.append(session.send_request_task(
Request("textDocument/hover", document_position, self.view)
)) @rchl is this what you imagined? |
Yep. Only with a getter for |
So you all prefer adding a |
Why can’t this be a server capability? Then we don’t need any new methods on AbstractPlugin |
@rchl what was your suggestion on the Metals repo? I looked and didn't find it.
Yea, this would break for Metals. In. Metals we do something very simple in this case and just check if there is a position if so, take it, or else grab the range https://github.com/scalameta/metals/blob/main/metals/src/main/scala/scala/meta/internal/metals/HoverExtension.scala, so having both would break this logic.
The approach we ended up taking on this was to keep it all as simple as possible. We didn't foresee how this would be problematic at all for the clients, since nothing changes except you now can send in a range or a position given a hover. It seemed to be quite easy to do in VS Code and even easier for Neovim. For example to support this in https://github.com/scalameta/nvim-metals/pull/232/files I know that doesn't help here, but just mentioning it since because it was so easy in the other editors, we didn't really think about it being problematic. If a client doesn't know about it or can't support it, then nothing changes at all for them. If they can support it, great. Then once this becomes part of the spec, then we can add that and clients can then use it via that, and then after a while we'll probably sunset the
I don't know Sublime internals at all, but can you elaborate on how this would help here? |
The main problem is that this client LSP package is used a lot of users against other LSP servers besides Metals. So the best option is to send a range only when the server explicitly says during initialization that it accepts a range as an argument. I can make a PR into Metals adding that flag, just want to confirm the idea first. |
Ahhhh sorry! I didn't realize this conversation was on the sublime LSP repo and not the Sublime Metals repo!!
Well I'm still not sure this is best right? Since they are both valid and used differently. If the user just wants a hover, then do the normal hover and send the single position. The selection range is a whole different feature, so I'd recommend keeping the hover as is, but then making the range a different binding to be used only when the user explicitly wants it.
Yea, I mean if it's just setting a flag then sure, I don't see an issue with that. However, it will be removed in the future when it's in the spec, which then makes me worry that adding it into Sublime LSP only for Metals is a bit extreme. Is there any way to do this only contained in the Metals package without touching core? |
This is what I tried in: scalameta/metals-sublime#45 but as a user you end up with two different commands, the default
That is fine, once it is in the spec, LSP and hopefully metals would handle the hover the official way. This just a temporary solution.
|
It's been a while since I looked, but I believe in IntelliJ these are two separate commands as well? I think users may actually be used to this since again, the behavior is different, it's two different features in reality. But with that being said, having the same command is useful, but I'd still want to be able to do both. |
The approach with I am ok with both approaches and Metals for sure can set a custom capability, that might also be useful for neovim or emacs. |
Redone here: #1900 |
This a better alternative to scalameta/metals-sublime#45 and this implementation is just a workaround until microsoft/language-server-protocol#377 is part of the LSP spec
On the LSP-* packages the users just have to set
{"keys": ["ctrl+h"], "command": "lsp_hover", "args": {"use_selection": true}}
a key binding