forked from palantir/python-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhover.py
More file actions
35 lines (27 loc) · 995 Bytes
/
Copy pathhover.py
File metadata and controls
35 lines (27 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Copyright 2017 Palantir Technologies, Inc.
import logging
from pyls import hookimpl, _utils
log = logging.getLogger(__name__)
@hookimpl
def pyls_hover(document, position):
definitions = document.jedi_script(position).goto_definitions()
word = document.word_at_position(position)
# Find first exact matching definition
definition = next((x for x in definitions if x.name == word), None)
if not definition:
return {'contents': ''}
# raw docstring returns only doc, without signature
doc = _utils.format_docstring(definition.docstring(raw=True))
# Find first exact matching signature
signature = next((x.to_string() for x in definition.get_signatures() if x.name == word), '')
contents = []
if signature:
contents.append({
'language': 'python',
'value': signature,
})
if doc:
contents.append(doc)
if not contents:
return {'contents': ''}
return {'contents': contents}