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, diff --git a/plugin/core/popups.py b/plugin/core/popups.py new file mode 100644 index 000000000..7eea2bb20 --- /dev/null +++ b/plugin/core/popups.py @@ -0,0 +1,19 @@ +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; + } + .lsp_popup li { + font-family: system; + } +''' diff --git a/plugin/hover.py b/plugin/hover.py index 6dbbbd01f..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 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,16 @@ 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) 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..d00b3cae5 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 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') @@ -149,13 +147,4 @@ def _build_popup_content(self) -> str: sigDocs = signature.get('documentation', None) 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 + return "\n".join(formatted)