diff --git a/plugin/hover.py b/plugin/hover.py index e0b1257f2..2a3528750 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -37,6 +37,7 @@ from .session_view import HOVER_HIGHLIGHT_KEY from functools import partial import html +import mdpopups import sublime @@ -99,6 +100,7 @@ class LspHoverCommand(LspTextCommand): def __init__(self, view: sublime.View) -> None: super().__init__(view) self._base_dir = None # type: Optional[str] + self._image_resolver = None def run( self, @@ -311,6 +313,13 @@ def _show_hover(self, listener: AbstractViewListener, point: int, only_diagnosti location=point, on_navigate=lambda href: self._on_navigate(href, point), on_hide=lambda: self.view.erase_regions(HOVER_HIGHLIGHT_KEY)) + self._image_resolver = mdpopups.resolve_images( + contents, mdpopups.worker_thread_resolver, partial(self._on_images_resolved, contents)) + + def _on_images_resolved(self, original_contents: str, contents: str) -> None: + self._image_resolver = None + if contents != original_contents and self.view.is_popup_visible(): + update_lsp_popup(self.view, contents) def _on_navigate(self, href: str, point: int) -> None: if href.startswith("subl:"): diff --git a/stubs/mdpopups.pyi b/stubs/mdpopups.pyi index e8f95d70f..51954b939 100644 --- a/stubs/mdpopups.pyi +++ b/stubs/mdpopups.pyi @@ -85,3 +85,16 @@ def scope2style( selected: bool = False, explicit_background: bool = False ) -> str: ... + + +def worker_thread_resolver( + url: str, + done: Callable[[bytes], None] +) -> None: ... + + +def resolve_images( + minihtml: str, + resolver: Callable[[str, Callable[[bytes], None]], None], + on_done: Callable[[str], None] +) -> Optional[object]: ...