Skip to content

Commit

Permalink
Small visual tweak for signature help popup (#2358)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann authored Nov 9, 2023
1 parent be3c5a4 commit 00ce15c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugin/core/signature_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def select_signature(self, forward: bool) -> None:

def _render_intro(self) -> str:
fmt = '<p><div style="font-size: 0.9rem"><b>{}</b> of <b>{}</b> overloads ' + \
"(use ↑ ↓ to navigate, press Esc to hide):</div></p>"
'(use <kbd>↑</kbd> <kbd>↓</kbd> to navigate, press <kbd>Esc</kbd> to hide):</div></p>'
return fmt.format(
self._active_signature_index + 1,
len(self._signatures),
Expand Down
21 changes: 16 additions & 5 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,27 +606,30 @@ def text_document_code_action_params(
}


# Workaround for a limited margin-collapsing capabilities of the minihtml.
# Workaround for limited margin-collapsing capabilities of the minihtml.
LSP_POPUP_SPACER_HTML = '<div class="lsp_popup--spacer"></div>'


def show_lsp_popup(
view: sublime.View,
contents: str,
*,
location: int = -1,
md: bool = False,
flags: int = 0,
css: Optional[str] = None,
wrapper_class: Optional[str] = None,
body_id: Optional[str] = None,
on_navigate: Optional[Callable[..., None]] = None,
on_hide: Optional[Callable[..., None]] = None
) -> None:
css = css if css is not None else lsp_css().popups
wrapper_class = wrapper_class if wrapper_class is not None else lsp_css().popups_classname
contents += LSP_POPUP_SPACER_HTML
body_wrapper = '<body id="{}">{{}}</body>'.format(body_id) if body_id else '<body>{}</body>'
mdpopups.show_popup(
view,
contents,
body_wrapper.format(contents),
css=css,
md=md,
flags=flags,
Expand All @@ -638,12 +641,20 @@ def show_lsp_popup(
on_hide=on_hide)


def update_lsp_popup(view: sublime.View, contents: str, md: bool = False, css: Optional[str] = None,
wrapper_class: Optional[str] = None) -> None:
def update_lsp_popup(
view: sublime.View,
contents: str,
*,
md: bool = False,
css: Optional[str] = None,
wrapper_class: Optional[str] = None,
body_id: Optional[str] = None
) -> None:
css = css if css is not None else lsp_css().popups
wrapper_class = wrapper_class if wrapper_class is not None else lsp_css().popups_classname
contents += LSP_POPUP_SPACER_HTML
mdpopups.update_popup(view, contents, css=css, md=md, wrapper_class=wrapper_class)
body_wrapper = '<body id="{}">{{}}</body>'.format(body_id) if body_id else '<body>{}</body>'
mdpopups.update_popup(view, body_wrapper.format(contents), css=css, md=md, wrapper_class=wrapper_class)


FORMAT_STRING = 0x1
Expand Down
1 change: 1 addition & 0 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ def _show_sighelp_popup(self, content: str, point: int) -> None:
content,
flags=sublime.COOPERATE_WITH_AUTO_COMPLETE,
location=point,
body_id='lsp-signature-help',
on_hide=self._on_sighelp_hide,
on_navigate=self._on_sighelp_navigate)

Expand Down
7 changes: 7 additions & 0 deletions popups.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
.lsp_popup h6 {
font-size: 1rem;
}
.lsp_popup kbd {
font-size: 0.8rem;
line-height: 0.8rem;
color: var(--mdpopups-fg);
background-color: color(var(--mdpopups-bg) lightness(+ 5%));
border-color: color(var(--mdpopups-fg) alpha(0.25));
}
.highlight {
border-width: 0;
border-radius: 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_signature_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_overloads(self) -> None:
r'''
<p>
<div style="font-size: 0\.9rem">
<b>2</b> of <b>2</b> overloads \(use ↑ ↓ to navigate, press Esc to hide\):
<b>2</b> of <b>2</b> overloads \(use <kbd>↑</kbd> <kbd>↓</kbd> to navigate, press <kbd>Esc</kbd> to hide\):
</div>
</p>
<div class="highlight"><pre><span style="color: #\w{6}">f\(</span>
Expand Down

0 comments on commit 00ce15c

Please sign in to comment.