From 00ce15c40fccf81a218aa35c364667abd28b522c Mon Sep 17 00:00:00 2001
From: jwortmann
Date: Thu, 9 Nov 2023 23:27:52 +0100
Subject: [PATCH] Small visual tweak for signature help popup (#2358)
---
plugin/core/signature_help.py | 2 +-
plugin/core/views.py | 21 ++++++++++++++++-----
plugin/documents.py | 1 +
popups.css | 7 +++++++
tests/test_signature_help.py | 2 +-
5 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/plugin/core/signature_help.py b/plugin/core/signature_help.py
index 23a34105d..a15e2e499 100644
--- a/plugin/core/signature_help.py
+++ b/plugin/core/signature_help.py
@@ -105,7 +105,7 @@ def select_signature(self, forward: bool) -> None:
def _render_intro(self) -> str:
fmt = '{} of {} overloads ' + \
- "(use ↑ ↓ to navigate, press Esc to hide):
"
+ '(use ↑ ↓ to navigate, press Esc to hide):'
return fmt.format(
self._active_signature_index + 1,
len(self._signatures),
diff --git a/plugin/core/views.py b/plugin/core/views.py
index a55d1a239..39e5ad07d 100644
--- a/plugin/core/views.py
+++ b/plugin/core/views.py
@@ -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 = ''
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 = '{{}}'.format(body_id) if body_id else '{}'
mdpopups.show_popup(
view,
- contents,
+ body_wrapper.format(contents),
css=css,
md=md,
flags=flags,
@@ -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 = '{{}}'.format(body_id) if body_id else '{}'
+ mdpopups.update_popup(view, body_wrapper.format(contents), css=css, md=md, wrapper_class=wrapper_class)
FORMAT_STRING = 0x1
diff --git a/plugin/documents.py b/plugin/documents.py
index 33afd3a57..5f7e9b5c6 100644
--- a/plugin/documents.py
+++ b/plugin/documents.py
@@ -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)
diff --git a/popups.css b/popups.css
index 592044102..4e43362b0 100644
--- a/popups.css
+++ b/popups.css
@@ -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;
diff --git a/tests/test_signature_help.py b/tests/test_signature_help.py
index e10372212..8de8d43f6 100644
--- a/tests/test_signature_help.py
+++ b/tests/test_signature_help.py
@@ -202,7 +202,7 @@ def test_overloads(self) -> None:
r'''
- 2 of 2 overloads \(use ↑ ↓ to navigate, press Esc to hide\):
+ 2 of 2 overloads \(use ↑ ↓ to navigate, press Esc to hide\):