Skip to content

Commit 156f151

Browse files
committed
Update pyls hover to specify language of signature.
LSP supports `MarkedString[]` to specify render engine. We can definitely say that function signature should be rendered as python. For the docstring, as we have no good way of parsing it to guess the engine, we can pass it as markdown.
1 parent 363e39a commit 156f151

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pyls/plugins/hover.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ def pyls_hover(document, position):
1313
# Find an exact match for a completion
1414
for d in definitions:
1515
if d.name == word:
16-
return {'contents': _utils.format_docstring(d.docstring()) or ''}
16+
doc = _utils.format_docstring(d.docstring()).split('\n\n', 1)
17+
if not doc:
18+
return {'contents': ''}
19+
contents = [{
20+
'language': 'python',
21+
'value': doc[0],
22+
}]
23+
if len(doc) > 1:
24+
contents.append(doc[1])
25+
return {'contents': contents}
1726

1827
return {'contents': ''}

test/plugins/test_hover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_hover():
2121
doc = Document(DOC_URI, DOC)
2222

2323
assert {
24-
'contents': 'main()\n\nhello world'
24+
'contents': [{'language': 'python', 'value': 'main()'}, 'hello world']
2525
} == pyls_hover(doc, hov_position)
2626

2727
assert {'contents': ''} == pyls_hover(doc, no_hov_position)

0 commit comments

Comments
 (0)