-
Notifications
You must be signed in to change notification settings - Fork 184
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
Improve whitespace in diagnostics popup #168
Changes from 7 commits
c0271fe
675467c
0aa2ce3
54c5853
fa75b0e
f6a79e4
748db3e
8368d9a
54a07f9
3e75de8
197f771
e1ab152
67daa34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2021,16 +2021,38 @@ def show_hover(self, point, contents): | |
else: | ||
value = item.get("value") | ||
language = item.get("language") | ||
|
||
if language: | ||
formatted.append("```{}\n{}\n```".format(language, value)) | ||
formatted.append( | ||
mdpopups.md2html( | ||
sublime.active_window().active_view(), | ||
"```{}\n{}\n```\n".format(language, value) | ||
) | ||
) | ||
else: | ||
formatted.append(value) | ||
formatted.append( | ||
mdpopups.md2html( | ||
sublime.active_window().active_view(), | ||
"<div class='description' markdown='1'>{}</div>".format(preserve_whitespace(value)) | ||
) | ||
) | ||
|
||
mdpopups.show_popup( | ||
self.view, | ||
preserve_whitespace("\n".join(formatted)), | ||
css=".mdpopups .lsp_hover { margin: 4px; } .mdpopups p { margin: 0.1rem; }", | ||
md=True, | ||
"".join(formatted), | ||
css=''' | ||
.lsp_hover .highlight { | ||
border-width: 0; | ||
} | ||
.lsp_hover div.highlight, | ||
.lsp_hover pre.highlight { | ||
margin-bottom: 0; | ||
} | ||
.lsp_hover .description { | ||
padding: 0.5rem 0.5rem 0 0.5rem; | ||
} | ||
''', | ||
md=False, | ||
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, | ||
location=point, | ||
wrapper_class="lsp_hover", | ||
|
@@ -2040,9 +2062,10 @@ 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('\r\n', '\n') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which language-server returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be all of them, according to protocol? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jsts in my case at least |
||
contents = contents.replace('\t', '\u00A0' * 4) | ||
contents = contents.replace(' ', '\u00A0' * 2) | ||
contents = contents.replace('\n\n', '\n\u00A0\n') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am no longer sure about that line. I originally added it as I experienced absolutely no spaces between paragraphs. Indeed it breaks the creation of If we remove this line and tweak the CSS a little bit to add proper padding, we may not even need the You may try ... ...
for item in contents:
if isinstance(item, str):
value = item
language = None
else:
value = item.get("value")
language = item.get("language")
if language:
formatted.append("```{}\n{}\n```\n".format(language, value))
else:
formatted.append(preserve_whitespace(value))
mdpopups.show_popup(
self.view,
"".join(formatted),
css='''
.mdpopups .lsp_hover {
margin: 0 0 0 0.5rem;
}
.mdpopups .lsp_hover .highlight {
border: none;
margin-bottom: 0;
}
.mdpopups .lsp_hover p {
padding: 0.5rem 0.5rem 0 0;
}
''',
md=True,
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
location=point,
wrapper_class="lsp_hover",
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('\r\n', '\n')
contents = contents.replace('\t', '\u00A0' * 4)
contents = contents.replace(' ', '\u00A0' * 2)
return contents ... may need to have a look onto other stylesheets, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's also pretty clean. However, it looks a lot better if the description text aligns with the code text. Now it aligns with the code box: Some screenshots to compare: Also note in the first screenshot how there is whitespace missing after As an aside, I don't think we have to prefix css selectors with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for sticking closely to mdpopups, this is in line with @deathaxe's suggestion, but with some fixes and even less lines of code: for item in contents:
value = ""
language = None
if isinstance(item, str):
value = item
else:
value = item.get("value")
language = item.get("language")
if language:
formatted.append("```{}\n{}\n```\n".format(language, value))
else:
formatted.append(preserve_whitespace(value))
mdpopups.show_popup(
self.view,
"\n".join(formatted),
css='''
.lsp_hover {
margin: 0.5rem 0.5rem 0 0.5rem;
}
.lsp_hover p {
margin-bottom: 0.5rem;
}
''',
md=True,
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
location=point,
wrapper_class="lsp_hover",
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('\r\n', '\n')
contents = contents.replace('\t', '\u00A0' * 4)
contents = contents.replace(' ', '\u00A0' * 2)
return contents I still think it's prettier to align the text, but I also very much like how little code this is. To align text, it's now enough to add I also kinda like removing the border around the code, by adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, you probably want to experiment around with the new signature help browser now, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
agree.
Can be tweaked by setting the margin of
I saw such issues with signatures, too. Would be interesting how the raw text looks like, and if there is a way to fix it before passing it to mdpopups. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed my mind about the border around the code box. I'll push an update and will look into some of the other popups later on. Gotta watch a football match right now, will get back to the code as soon as we're a couple of goals behind ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, it might be caused by applying TOOLTIP_CSS = """
.lsp_hover {
margin: 0;
padding: 0;
}
.lsp_hover .highlight {
border-radius: 0;
border-style: none;
font-size: 1.2rem;
}
.lsp_hover p {
padding: 0.5rem 0.5rem 0 0.5rem;
}
"""
...
for item in contents:
if isinstance(item, str):
value = item
language = None
else:
value = item.get("value")
language = item.get("language")
if language:
formatted.append("```{}\n{}\n```\n".format(language, value))
else:
formatted.append(value)
mdpopups.show_popup(
self.view,
preserve_whitespace("\n".join(formatted)),
css=TOOLTIP_CSS,
md=True,
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
location=point,
wrapper_class="lsp_hover",
max_width=800) |
||
return contents | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about @tomv564 's coding style wishes, but I'd suggest
... to save some lines of code.
Btw.: you can use
self.view
inside ViewEventListeners instead ofsublime.active_window().active_view()