-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is needed to handle scalameta/metals#3060 It should be handle by LSP package once microsoft/language-server-protocol#377 is resolved
- Loading branch information
1 parent
e5d3786
commit d806c9a
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
// Show Type annotation on code selection | ||
// { | ||
// "command": "lsp_metals_hover_range", | ||
// "keys": ["UNBOUND"] | ||
// } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from LSP.plugin.core.registry import LspTextCommand | ||
from LSP.plugin.core.typing import Union | ||
from LSP.plugin.core.protocol import Request, Range, TextDocumentIdentifier, Error, Hover | ||
from LSP.plugin.core.views import first_selection_region, text_document_identifier, region_to_range, FORMAT_MARKED_STRING, FORMAT_MARKUP_CONTENT, minihtml, update_lsp_popup, show_lsp_popup | ||
import sublime | ||
|
||
HoverOrError = Union[Hover, Error] | ||
|
||
class LspMetalsHoverRangeCommand(LspTextCommand): | ||
session_name = "metals" | ||
|
||
def run(self, edit: sublime.Edit) -> None: | ||
session = self.session_by_name() | ||
if not session: | ||
return | ||
view = self.view | ||
region = first_selection_region(view) | ||
begin = region.begin() | ||
document_range = { | ||
"textDocument": text_document_identifier(view), | ||
"range": region_to_range(view, region).to_lsp() | ||
} | ||
|
||
def on_response(response: HoverOrError): | ||
if isinstance(response, Error): | ||
sublime.status_message('Hover error: {}'.format(response)) | ||
|
||
if response: | ||
content = (response.get('contents') or '') if isinstance(response, dict) else '' | ||
formated = minihtml(self.view, content, allowed_formats=FORMAT_MARKED_STRING | FORMAT_MARKUP_CONTENT) | ||
if self.view.is_popup_visible(): | ||
update_lsp_popup(self.view, formated) | ||
else: | ||
show_lsp_popup( | ||
self.view, | ||
formated, | ||
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, | ||
location=begin | ||
) | ||
|
||
def on_error(error: Error): | ||
sublime.status_message('Hover error: {}'.format(error)) | ||
|
||
session.send_request( | ||
Request("textDocument/hover", document_range, self.view), | ||
on_response, | ||
on_error | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters