Skip to content

Commit c3cab77

Browse files
mpanarinccordoba12
authored andcommitted
Separate signature from docstring on hover (#623)
1 parent f6b10a8 commit c3cab77

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

pyls/_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def format_docstring(contents):
136136
"""
137137
contents = contents.replace('\t', u'\u00A0' * 4)
138138
contents = contents.replace(' ', u'\u00A0' * 2)
139-
contents = contents.replace('*', '\\*')
140139
return contents
141140

142141

pyls/plugins/hover.py

+22-5
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

+1-1
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.14.1,<0.15',
39+
'jedi>=0.15.0,<0.16',
4040
'python-jsonrpc-server>=0.1.0',
4141
'pluggy'
4242
],

test/plugins/test_hover.py

+1-1
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)