Skip to content

Commit 1498ff3

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 35979d3 commit 1498ff3

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

pyls/plugins/hover.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,26 @@ def pyls_hover(document, position):
1010
definitions = document.jedi_script(position).goto_definitions()
1111
word = document.word_at_position(position)
1212

13-
# Find an exact match for a completion
14-
for d in definitions:
15-
if d.name == word:
16-
return {'contents': _utils.format_docstring(d.docstring()) or ''}
13+
# Find first exact matching definition
14+
definition = next((x for x in definitions if x.name == word), None)
1715

18-
return {'contents': ''}
16+
if not definition:
17+
return {'contents': ''}
18+
19+
# raw docstring returns only doc, without signature
20+
doc = _utils.format_docstring(definition.docstring(raw=True))
21+
22+
# Find first exact matching signature
23+
signature = next((x.to_string() for x in definition.get_signatures() if x.name == word), '')
24+
25+
contents = []
26+
if signature:
27+
contents.append({
28+
'language': 'python',
29+
'value': signature,
30+
})
31+
if doc:
32+
contents.append(doc)
33+
if not contents:
34+
return {'contents': ''}
35+
return {'contents': contents}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'future>=0.14.0',
3737
'futures; python_version<"3.2"',
3838
'backports.functools_lru_cache; python_version<"3.2"',
39-
'jedi>=0.13.2,<0.15,!=0.14.0',
39+
'jedi>=0.15.0,<0.16',
4040
'python-jsonrpc-server>=0.1.0',
4141
'pluggy'
4242
],

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)