Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New whitespace / layout / styling PR #176

Merged
merged 7 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions plugin/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions plugin/core/popups.py
Original file line number Diff line number Diff line change
@@ -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;
}
'''
23 changes: 7 additions & 16 deletions plugin/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))

Expand All @@ -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
27 changes: 8 additions & 19 deletions plugin/signature_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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')
Expand All @@ -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)