Skip to content

Commit

Permalink
Add support for remote images in hover popups (#2341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann authored Oct 18, 2023
1 parent c06d811 commit e1555aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugin/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from .session_view import HOVER_HIGHLIGHT_KEY
from functools import partial
import html
import mdpopups
import sublime


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:"):
Expand Down
13 changes: 13 additions & 0 deletions stubs/mdpopups.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...

0 comments on commit e1555aa

Please sign in to comment.