Skip to content

Commit

Permalink
Do not escape quote characters for hover content
Browse files Browse the repository at this point in the history
Otherwise mdpopups will complain.
Also add two hover tests to cement this behavior.
  • Loading branch information
rwols committed Jul 19, 2019
1 parent 1e09409 commit c1cbffc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plugin/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,17 @@ def hover_content(self, point, response: 'Optional[Any]') -> str:
formatted = []
for item in contents:
value = ""
language = None
language = None # type: Optional[str]
if isinstance(item, str):
value = escape(item)
value = item
else:
value = escape(item.get("value"))
value = item.get("value")
language = item.get("language")
# NOTE: Escape the hover content for languages like C# where the
# hover content may contain "<" and ">" characters, but do not
# escape the quote characters "'" and '"' for languages like Python.
# mdpopups will complain otherwise.
value = escape(value, quote=False)
if language:
formatted.append("```{}\n{}\n```\n".format(language, value))
else:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ def test_hover_info(self):

last_content = _test_contents[-1]
self.assertTrue("greeting" in last_content)

def test_escape_fish_brackets(self):
self.client.responses['textDocument/hover'] = {"contents": "<summary>foobar</summary>"}
yield 100
self.view.run_command('insert', {"characters": ORIGINAL_CONTENT})
self.view.run_command('lsp_hover', {'point': 3})
yield 100
self.assertTrue(self.view.is_popup_visible())
last_content = _test_contents[-1]
self.assertTrue("&lt;summary&gt;foobar&lt;/summary&gt;" in last_content)

def test_dont_escape_quotes(self):
self.client.responses['textDocument/hover'] = {"contents": "print(foo=bar, prefix='LSP')"}
yield 100
self.view.run_command('insert', {"characters": ORIGINAL_CONTENT})
self.view.run_command('lsp_hover', {'point': 3})
yield 100
self.assertTrue(self.view.is_popup_visible())
last_content = _test_contents[-1]
self.assertTrue("print(foo=bar, prefix='LSP')" in last_content)

0 comments on commit c1cbffc

Please sign in to comment.