Skip to content

Commit

Permalink
Fixup hover popup behavior
Browse files Browse the repository at this point in the history
- We used show_popup two times, but it's a smoother experience to use
  show_popup and then update_popup.
- There's a bug in ST where it thinks the view is modified when doing
  a show_popup or an add_regions call with an edit token. Workaround
  this by running sublime.set_timeout.
  See: sublimehq/sublime_text#3424
  • Loading branch information
rwols committed Jun 22, 2020
1 parent b30487b commit 5f34996
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions plugin/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ def request_symbol_hover(self, point: int) -> None:

def handle_code_actions(self, responses: Dict[str, List[CodeActionOrCommand]], point: int) -> None:
self._actions_by_config = responses
sublime.set_timeout(lambda: self.show_hover(point))
self.show_hover(point)

def handle_response(self, response: Optional[Any], point: int) -> None:
self._hover = response
sublime.set_timeout(lambda: self.show_hover(point))
self.show_hover(point)

def symbol_actions_content(self) -> str:
actions = []
Expand Down Expand Up @@ -175,6 +175,9 @@ def hover_content(self) -> str:
return minihtml(self.view, content, allowed_formats=FORMAT_MARKED_STRING | FORMAT_MARKUP_CONTENT)

def show_hover(self, point: int) -> None:
sublime.set_timeout(lambda: self._show_hover(point))

def _show_hover(self, point: int) -> None:
contents = self.diagnostics_content() + self.hover_content()
if contents and settings.show_symbol_action_links:
contents += self.symbol_actions_content()
Expand All @@ -183,16 +186,24 @@ def show_hover(self, point: int) -> None:
_test_contents.append(contents) # for testing only

if contents:
mdpopups.show_popup(
self.view,
contents,
css=popups.stylesheet,
md=False,
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
location=point,
wrapper_class=popups.classname,
max_width=800,
on_navigate=lambda href: self.on_hover_navigate(href, point))
if self.view.is_popup_visible():
mdpopups.update_popup(
self.view,
contents,
css=popups.stylesheet,
md=False,
wrapper_class=popups.classname)
else:
mdpopups.show_popup(
self.view,
contents,
css=popups.stylesheet,
md=False,
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
location=point,
wrapper_class=popups.classname,
max_width=800,
on_navigate=lambda href: self.on_hover_navigate(href, point))

def on_hover_navigate(self, href: str, point: int) -> None:
for goto_kind in goto_kinds:
Expand Down

0 comments on commit 5f34996

Please sign in to comment.