From 4873e5f9c7840115d15d4c7c754949e5c582f5cd Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Mon, 16 Oct 2017 14:15:14 +0200 Subject: [PATCH 1/7] simplify documentation popup --- plugin/configuration.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin/configuration.py b/plugin/configuration.py index 0ee4311ef..c39d25b12 100644 --- a/plugin/configuration.py +++ b/plugin/configuration.py @@ -116,9 +116,6 @@ def run(self): Visit [langserver.org](https://langserver.org) to find out if a language server exists for this language.""" -setup_css = ".mdpopups .lsp_documentation { margin: 20px; font-family: sans-serif; font-size: 1.2rem; line-height: 2}" - - class LspSetupLanguageServerCommand(sublime_plugin.WindowCommand): def run(self): view = self.window.active_view() @@ -137,7 +134,16 @@ def run(self): mdpopups.show_popup( view, "\n".join([title, content]), - css=setup_css, + css=''' + .lsp_documentation { + margin: 1rem 1rem 0.5rem 1rem; + font-family: system; + } + .lsp_documentation h1, + .lsp_documentation p { + margin: 0 0 0.5rem 0; + } + ''', md=True, wrapper_class="lsp_documentation", max_width=800, From 153d2bd742b4e15c23fdbfca86dbd8920ef23f40 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Mon, 16 Oct 2017 14:15:45 +0200 Subject: [PATCH 2/7] shared popup styling and whitespace processing --- plugin/core/popups.py | 25 +++++++++++++++++++++++++ plugin/hover.py | 24 ++++++++---------------- plugin/signature_help.py | 25 +++++++------------------ 3 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 plugin/core/popups.py diff --git a/plugin/core/popups.py b/plugin/core/popups.py new file mode 100644 index 000000000..6201f9ef0 --- /dev/null +++ b/plugin/core/popups.py @@ -0,0 +1,25 @@ +popup_class = "lsp_popup" + +popup_css = ''' + .lsp_popup { + margin: 0.5rem 0.5rem 0 0.5rem; + } + .lsp_popup .highlight { + border-width: 0; + border-radius: 0; + } + .lsp_popup p { + margin-bottom: 0.5rem; + padding: 0 0.5rem; + font-family: system; + } +''' + + +def preserve_whitespace(contents: str) -> str: + """Preserve empty lines and whitespace for markdown conversion.""" + contents = contents.strip(' \t\r\n') + contents = contents.replace('\r\n', '\n') + contents = contents.replace('\t', '\u00A0' * 4) + contents = contents.replace(' ', '\u00A0' * 2) + return contents diff --git a/plugin/hover.py b/plugin/hover.py index 6dbbbd01f..bc079a021 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -8,7 +8,7 @@ from .core.protocol import Request from .core.documents import get_document_position from .core.logging import debug - +from .core.popups import preserve_whitespace, popup_css, popup_class SUBLIME_WORD_MASK = 515 NO_HOVER_SCOPES = 'comment, constant, keyword, storage, string' @@ -62,11 +62,11 @@ def show_diagnostics_hover(self, point, diagnostics): mdpopups.show_popup( self.view, "\n".join(formatted), - css=".mdpopups .lsp_hover { margin: 4px; }", + css=popup_css, md=True, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, - wrapper_class="lsp_hover", + wrapper_class=popup_class, max_width=800, on_navigate=lambda href: self.on_diagnostics_navigate(href, point, diagnostics)) @@ -93,25 +93,17 @@ def show_hover(self, point, contents): value = item.get("value") language = item.get("language") if language: - formatted.append("```{}\n{}\n```".format(language, value)) + formatted.append("```{}\n{}\n```\n".format(language, value)) else: - formatted.append(value) + formatted.append(preserve_whitespace(value)) mdpopups.show_popup( self.view, - preserve_whitespace("\n".join(formatted)), - css=".mdpopups .lsp_hover { margin: 4px; } .mdpopups p { margin: 0.1rem; }", + "\n".join(formatted), + css=popup_css, md=True, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, - wrapper_class="lsp_hover", + wrapper_class=popup_class, max_width=800) - -def preserve_whitespace(contents: str) -> str: - """Preserve empty lines and whitespace for markdown conversion.""" - contents = contents.strip(' \t\r\n') - contents = contents.replace('\t', ' ' * 4) - contents = contents.replace(' ', ' ' * 2) - contents = contents.replace('\n\n', '\n \n') - return contents diff --git a/plugin/signature_help.py b/plugin/signature_help.py index 0151b186e..98d61628f 100644 --- a/plugin/signature_help.py +++ b/plugin/signature_help.py @@ -14,13 +14,11 @@ from .core.configurations import is_supported_syntax, config_for_scope from .core.protocol import Request from .core.logging import debug +from .core.popups import preserve_whitespace, popup_css, popup_class class SignatureHelpListener(sublime_plugin.ViewEventListener): - css = ".mdpopups .lsp_signature { margin: 4px; } .mdpopups p { margin: 0.1rem; }" - wrapper_class = "lsp_signature" - def __init__(self, view): self.view = view self._initialized = False @@ -90,11 +88,11 @@ def handle_response(self, response, point): if len(self._signatures) > 0: mdpopups.show_popup(self.view, self._build_popup_content(), - css=self.__class__.css, + css=popup_css, md=True, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, - wrapper_class=self.__class__.wrapper_class, + wrapper_class=popup_class, max_width=800, on_hide=self._on_hide) self._visible = True @@ -118,9 +116,9 @@ def on_query_context(self, key, _, operand, __): self._active_signature = new_index mdpopups.update_popup(self.view, self._build_popup_content(), - css=self.__class__.css, + css=popup_css, md=True, - wrapper_class=self.__class__.wrapper_class) + wrapper_class=popup_class) return True # We handled this keybinding. @@ -132,11 +130,11 @@ def _build_popup_content(self) -> str: formatted = [] if len(self._signatures) > 1: - signature_navigation = "**{}** of **{}** overloads (use the arrow keys to navigate):\n".format( + signature_navigation = "**{}** of **{}** overloads (use the ↑ ↓ keys to navigate):\n".format( str(self._active_signature + 1), str(len(self._signatures))) formatted.append(signature_navigation) - label = "```{}\n{}\n```".format(self._language_id, signature.get('label')) + label = "```{}\n{}\n```\n".format(self._language_id, signature.get('label')) formatted.append(label) params = signature.get('parameters') @@ -150,12 +148,3 @@ def _build_popup_content(self) -> str: if sigDocs: formatted.append(sigDocs) return preserve_whitespace("\n".join(formatted)) - - -def preserve_whitespace(contents: str) -> str: - """Preserve empty lines and whitespace for markdown conversion.""" - contents = contents.strip(' \t\r\n') - contents = contents.replace('\t', ' ' * 4) - contents = contents.replace(' ', ' ' * 2) - contents = contents.replace('\n\n', '\n \n') - return contents From 64b9ed304715c2c8730ea5deb9f1ab15d31010a6 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Mon, 16 Oct 2017 15:03:04 +0200 Subject: [PATCH 3/7] lint --- plugin/hover.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/hover.py b/plugin/hover.py index bc079a021..77d5d7bb2 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -106,4 +106,3 @@ def show_hover(self, point, contents): location=point, wrapper_class=popup_class, max_width=800) - From 0669ccba996f78116ab7c66c340fdeb0189ce562 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Mon, 16 Oct 2017 18:07:29 +0200 Subject: [PATCH 4/7] remove newline processing --- plugin/core/popups.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin/core/popups.py b/plugin/core/popups.py index 6201f9ef0..0abe8cd5b 100644 --- a/plugin/core/popups.py +++ b/plugin/core/popups.py @@ -18,8 +18,6 @@ def preserve_whitespace(contents: str) -> str: """Preserve empty lines and whitespace for markdown conversion.""" - contents = contents.strip(' \t\r\n') - contents = contents.replace('\r\n', '\n') contents = contents.replace('\t', '\u00A0' * 4) contents = contents.replace(' ', '\u00A0' * 2) return contents From 13cf547b0725897d92075159564bbe3f2897a64b Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Mon, 16 Oct 2017 18:25:34 +0200 Subject: [PATCH 5/7] update comment re: need for preserve_whitespace --- plugin/core/popups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/popups.py b/plugin/core/popups.py index 0abe8cd5b..2ea2c55cb 100644 --- a/plugin/core/popups.py +++ b/plugin/core/popups.py @@ -17,7 +17,7 @@ def preserve_whitespace(contents: str) -> str: - """Preserve empty lines and whitespace for markdown conversion.""" + """Preserve indentation in (non-markdown) ascii docstrings (e.g. pyls)""" contents = contents.replace('\t', '\u00A0' * 4) contents = contents.replace(' ', '\u00A0' * 2) return contents From baf565002240dab611001f56d9a565c4159df39e Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Mon, 16 Oct 2017 23:45:09 +0200 Subject: [PATCH 6/7] Remove preserve_whitespace Tabs as used in python docstrings are not Markdown, work with python language server to improve hovers --- plugin/core/popups.py | 7 ------- plugin/hover.py | 4 ++-- plugin/signature_help.py | 4 ++-- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/plugin/core/popups.py b/plugin/core/popups.py index 2ea2c55cb..2c623124e 100644 --- a/plugin/core/popups.py +++ b/plugin/core/popups.py @@ -14,10 +14,3 @@ font-family: system; } ''' - - -def preserve_whitespace(contents: str) -> str: - """Preserve indentation in (non-markdown) ascii docstrings (e.g. pyls)""" - contents = contents.replace('\t', '\u00A0' * 4) - contents = contents.replace(' ', '\u00A0' * 2) - return contents diff --git a/plugin/hover.py b/plugin/hover.py index 77d5d7bb2..5991e509a 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -8,7 +8,7 @@ from .core.protocol import Request from .core.documents import get_document_position from .core.logging import debug -from .core.popups import preserve_whitespace, popup_css, popup_class +from .core.popups import popup_css, popup_class SUBLIME_WORD_MASK = 515 NO_HOVER_SCOPES = 'comment, constant, keyword, storage, string' @@ -95,7 +95,7 @@ def show_hover(self, point, contents): if language: formatted.append("```{}\n{}\n```\n".format(language, value)) else: - formatted.append(preserve_whitespace(value)) + formatted.append(value) mdpopups.show_popup( self.view, diff --git a/plugin/signature_help.py b/plugin/signature_help.py index 98d61628f..d00b3cae5 100644 --- a/plugin/signature_help.py +++ b/plugin/signature_help.py @@ -14,7 +14,7 @@ from .core.configurations import is_supported_syntax, config_for_scope from .core.protocol import Request from .core.logging import debug -from .core.popups import preserve_whitespace, popup_css, popup_class +from .core.popups import popup_css, popup_class class SignatureHelpListener(sublime_plugin.ViewEventListener): @@ -147,4 +147,4 @@ def _build_popup_content(self) -> str: sigDocs = signature.get('documentation', None) if sigDocs: formatted.append(sigDocs) - return preserve_whitespace("\n".join(formatted)) + return "\n".join(formatted) From 64e494ceb8609f5c9968a65ce4e3afa6b5c6ee8c Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Mon, 16 Oct 2017 23:54:32 +0200 Subject: [PATCH 7/7] Add system font for list items --- plugin/core/popups.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/core/popups.py b/plugin/core/popups.py index 2c623124e..7eea2bb20 100644 --- a/plugin/core/popups.py +++ b/plugin/core/popups.py @@ -13,4 +13,7 @@ padding: 0 0.5rem; font-family: system; } + .lsp_popup li { + font-family: system; + } '''