From c0271feaa6bd7dabd7b2b4040507a8dcb0124315 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 7 Oct 2017 14:20:16 +0200 Subject: [PATCH 01/11] Fix   being displayed in toolip code blocks fixes #159 Directly replacing whitespace with &nbps; works only, if the result is passed to mdpopups as html directly. The solution is to use `\u00A0` as fixed whitespace instead, which mdpopups is designed to use for markdown as well. --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e45dff6e9..22392d6fb 100644 --- a/main.py +++ b/main.py @@ -2040,9 +2040,9 @@ def show_hover(self, point, contents): 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') + contents = contents.replace('\t', '\u00A0' * 4) + contents = contents.replace(' ', '\u00A0' * 2) + contents = contents.replace('\n\n', '\n\u00A0\n') return contents From 675467c1a7c845d19b46e2b6f31f0554e9e8b067 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Sun, 8 Oct 2017 17:50:29 +0200 Subject: [PATCH 02/11] improve whitespace in diagnostics popup --- main.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 550dfaf57..2e6193e07 100644 --- a/main.py +++ b/main.py @@ -1983,6 +1983,7 @@ def handle_response(self, response, point): # Flow returns None sometimes # See: https://github.com/flowtype/flow-language-server/issues/51 contents = response.get('contents') or contents + print(contents) self.show_hover(point, contents) def show_diagnostics_hover(self, point, diagnostics): @@ -2022,14 +2023,35 @@ 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("
{}
".format(value)) + # print(formatted) mdpopups.show_popup( self.view, preserve_whitespace("\n".join(formatted)), - css=".mdpopups .lsp_hover { margin: 4px; } .mdpopups p { margin: 0.1rem; }", + css=''' + .mdpopups .lsp_hover { + margin: 0.25rem; + } + .mdpopups .lsp_hover div.highlight, + .mdpopups .lsp_hover pre.highlight { + margin: 0; + } + .mdpopups .lsp_hover .text, + .mdpopups .lsp_hover p { + margin: 0; + padding: 0; + } + .mdpopups .lsp_hover p .text { + position: relative; + top: -0.5rem; + margin: 0 .5rem; + padding: 1px; + font-family: sans-serif; + } + ''', md=True, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, @@ -2040,6 +2062,8 @@ def show_hover(self, point, contents): 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('\n Date: Sun, 8 Oct 2017 20:30:25 +0200 Subject: [PATCH 03/11] Remove prints --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 2e6193e07..e45245bc9 100644 --- a/main.py +++ b/main.py @@ -1983,7 +1983,6 @@ def handle_response(self, response, point): # Flow returns None sometimes # See: https://github.com/flowtype/flow-language-server/issues/51 contents = response.get('contents') or contents - print(contents) self.show_hover(point, contents) def show_diagnostics_hover(self, point, diagnostics): @@ -2026,7 +2025,6 @@ def show_hover(self, point, contents): formatted.append("```{}\n{}\n```\n".format(language, value)) else: formatted.append("
{}
".format(value)) - # print(formatted) mdpopups.show_popup( self.view, From 54c585302d1443aaa805021151bfd98f1619ff7d Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Mon, 9 Oct 2017 11:21:13 +0200 Subject: [PATCH 04/11] reduce cruft --- main.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index e45245bc9..227ef1329 100644 --- a/main.py +++ b/main.py @@ -2024,29 +2024,17 @@ def show_hover(self, point, contents): if language: formatted.append("```{}\n{}\n```\n".format(language, value)) else: - formatted.append("
{}
".format(value)) + formatted.append("
{}
".format(value)) mdpopups.show_popup( self.view, - preserve_whitespace("\n".join(formatted)), + preserve_whitespace("".join(formatted)), css=''' - .mdpopups .lsp_hover { - margin: 0.25rem; + .mdpopups .lsp_hover .highlight { + border-width: 0; } - .mdpopups .lsp_hover div.highlight, - .mdpopups .lsp_hover pre.highlight { - margin: 0; - } - .mdpopups .lsp_hover .text, - .mdpopups .lsp_hover p { - margin: 0; - padding: 0; - } - .mdpopups .lsp_hover p .text { - position: relative; - top: -0.5rem; - margin: 0 .5rem; - padding: 1px; + .mdpopups .lsp_hover .description { + margin: 0 0.5rem; font-family: sans-serif; } ''', @@ -2061,7 +2049,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('\n Date: Mon, 9 Oct 2017 11:34:59 +0200 Subject: [PATCH 05/11] =?UTF-8?q?perhaps=20a=20p=20is=20more=20semantic=3F?= =?UTF-8?q?=20=F0=9F=A4=B7=F0=9F=8F=BC=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 846cd2834..fe9a5cb40 100644 --- a/main.py +++ b/main.py @@ -2024,7 +2024,7 @@ def show_hover(self, point, contents): if language: formatted.append("```{}\n{}\n```\n".format(language, value)) else: - formatted.append("
{}
".format(value)) + formatted.append("

{}

".format(value)) mdpopups.show_popup( self.view, From 748db3ee0ff3f79d0758dc74a07d7e6f612860fd Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Tue, 10 Oct 2017 13:08:38 +0200 Subject: [PATCH 06/11] do md2html before passing to show_popup --- main.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index fe9a5cb40..a8a72e1c9 100644 --- a/main.py +++ b/main.py @@ -2021,24 +2021,38 @@ def show_hover(self, point, contents): else: value = item.get("value") language = item.get("language") + if language: - formatted.append("```{}\n{}\n```\n".format(language, value)) + formatted.append( + mdpopups.md2html( + sublime.active_window().active_view(), + "```{}\n{}\n```\n".format(language, value) + ) + ) else: - formatted.append("

{}

".format(value)) + formatted.append( + mdpopups.md2html( + sublime.active_window().active_view(), + "
{}
".format(preserve_whitespace(value)) + ) + ) mdpopups.show_popup( self.view, - preserve_whitespace("".join(formatted)), + "".join(formatted), css=''' - .mdpopups .lsp_hover .highlight { - border-width: 0; + .lsp_hover .highlight { + border-width: 0; } - .mdpopups .lsp_hover .description { - margin: 0 0.5rem; - font-family: sans-serif; + .lsp_hover div.highlight, + .lsp_hover pre.highlight { + margin-bottom: 0; + } + .lsp_hover .description { + padding: 0.5rem 0.5rem 0 0.5rem; } ''', - md=True, + md=False, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, wrapper_class="lsp_hover", From 8368d9a13b3eb4e6857019b461c46d7dcdb6aefb Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Tue, 10 Oct 2017 21:02:23 +0200 Subject: [PATCH 07/11] less code is much betterer --- main.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index a8a72e1c9..0d4a16369 100644 --- a/main.py +++ b/main.py @@ -2023,36 +2023,23 @@ def show_hover(self, point, contents): language = item.get("language") if language: - formatted.append( - mdpopups.md2html( - sublime.active_window().active_view(), - "```{}\n{}\n```\n".format(language, value) - ) - ) + formatted.append("```{}\n{}\n```\n".format(language, value)) else: - formatted.append( - mdpopups.md2html( - sublime.active_window().active_view(), - "
{}
".format(preserve_whitespace(value)) - ) - ) + formatted.append(preserve_whitespace(value)) mdpopups.show_popup( self.view, - "".join(formatted), + "\n".join(formatted), css=''' - .lsp_hover .highlight { - border-width: 0; + .lsp_hover { + margin: 0.5rem 0.5rem 0 0.5rem; } - .lsp_hover div.highlight, - .lsp_hover pre.highlight { - margin-bottom: 0; - } - .lsp_hover .description { - padding: 0.5rem 0.5rem 0 0.5rem; + .lsp_hover p { + margin-bottom: 0.5rem; + padding: 0 0.5rem; } ''', - md=False, + md=True, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, wrapper_class="lsp_hover", @@ -2065,7 +2052,6 @@ def preserve_whitespace(contents: str) -> str: contents = contents.replace('\r\n', '\n') contents = contents.replace('\t', '\u00A0' * 4) contents = contents.replace(' ', '\u00A0' * 2) - contents = contents.replace('\n\n', '\n\u00A0\n') return contents From 54a07f928c7bbd517f008e2a742ba66fd4bcb540 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Wed, 11 Oct 2017 09:06:18 +0200 Subject: [PATCH 08/11] hm, that border caused a 1px offset --- main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.py b/main.py index 0d4a16369..a5baede90 100644 --- a/main.py +++ b/main.py @@ -2034,6 +2034,10 @@ def show_hover(self, point, contents): .lsp_hover { margin: 0.5rem 0.5rem 0 0.5rem; } + .lsp_hover .highlight { + border-width: 0; + border-radius: 0; + } .lsp_hover p { margin-bottom: 0.5rem; padding: 0 0.5rem; From 3e75de85e83f05cb654ccf3fc20ca0eb7874aa22 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Wed, 11 Oct 2017 09:58:21 +0200 Subject: [PATCH 09/11] uniform popups everywhere --- main.py | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index a5baede90..c4f02a7cd 100644 --- a/main.py +++ b/main.py @@ -50,6 +50,20 @@ window_client_configs = dict() # type: Dict[int, List[ClientConfig]] +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; + } +''' + class DiagnosticSeverity(object): Error = 1 @@ -1046,9 +1060,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() @@ -1067,7 +1078,15 @@ def run(self): mdpopups.show_popup( view, "\n".join([title, content]), - css=setup_css, + css=''' + .lsp_documentation { + margin: 1rem 1rem 0.5rem 1rem; + } + .lsp_documentation h1, + .lsp_documentation p { + margin: 0 0 0.5rem 0; + } + ''', md=True, wrapper_class="lsp_documentation", max_width=800, @@ -1991,11 +2010,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="lsp_popup", max_width=800, on_navigate=lambda href: self.on_diagnostics_navigate(href, point, diagnostics)) @@ -2030,23 +2049,11 @@ def show_hover(self, point, contents): mdpopups.show_popup( self.view, "\n".join(formatted), - css=''' - .lsp_hover { - margin: 0.5rem 0.5rem 0 0.5rem; - } - .lsp_hover .highlight { - border-width: 0; - border-radius: 0; - } - .lsp_hover p { - margin-bottom: 0.5rem; - padding: 0 0.5rem; - } - ''', + css=popup_css, md=True, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, - wrapper_class="lsp_hover", + wrapper_class="lsp_popup", max_width=800) @@ -2330,7 +2337,7 @@ def handle_response(self, response, point): debug("active signature", signature) formatted = [] formatted.append( - "```{}\n{}\n```".format(config.languageId, signature.get('label'))) + "```{}\n{}\n```\n".format(config.languageId, signature.get('label'))) params = signature.get('parameters') if params: for parameter in params: @@ -2344,11 +2351,11 @@ def handle_response(self, response, point): mdpopups.show_popup( self.view, preserve_whitespace("\n".join(formatted)), - css=".mdpopups .lsp_signature { margin: 4px; } .mdpopups p { margin: 0.1rem; }", + css=popup_css, md=True, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=point, - wrapper_class="lsp_signature", + wrapper_class="lsp_popup", max_width=800) From e1ab1521ff4184d694075b4bd860c47a2e37d354 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Wed, 11 Oct 2017 10:21:41 +0200 Subject: [PATCH 10/11] specify which arrow keys --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2231666f2..b2edc367c 100644 --- a/main.py +++ b/main.py @@ -2429,7 +2429,7 @@ 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) From 67daa344a284453c9a179a44a336c3a085446814 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Wed, 11 Oct 2017 14:00:26 +0200 Subject: [PATCH 11/11] use the "system" generic font for descriptions as per jps's recommendation --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index b2edc367c..8e8575ae4 100644 --- a/main.py +++ b/main.py @@ -61,6 +61,7 @@ .lsp_popup p { margin-bottom: 0.5rem; padding: 0 0.5rem; + font-family: system; } ''' @@ -1085,6 +1086,7 @@ def run(self): css=''' .lsp_documentation { margin: 1rem 1rem 0.5rem 1rem; + font-family: system; } .lsp_documentation h1, .lsp_documentation p {