11# Copyright 2017 Palantir Technologies, Inc.
2+ from distutils .version import LooseVersion
23import logging
4+
35from pyls import hookimpl , _utils
46
57log = logging .getLogger (__name__ )
@@ -10,26 +12,34 @@ def pyls_hover(document, position):
1012 definitions = document .jedi_script (position ).goto_definitions ()
1113 word = document .word_at_position (position )
1214
13- # Find first exact matching definition
14- definition = next ((x for x in definitions if x .name == word ), None )
15-
16- if not definition :
17- return {'contents' : '' }
15+ if LooseVersion (_utils .JEDI_VERSION ) >= LooseVersion ('0.15.0' ):
16+ # Find first exact matching definition
17+ definition = next ((x for x in definitions if x .name == word ), None )
18+
19+ if not definition :
20+ return {'contents' : '' }
21+
22+ # raw docstring returns only doc, without signature
23+ doc = _utils .format_docstring (definition .docstring (raw = True ))
24+
25+ # Find first exact matching signature
26+ signature = next ((x .to_string () for x in definition .get_signatures () if x .name == word ), '' )
27+
28+ contents = []
29+ if signature :
30+ contents .append ({
31+ 'language' : 'python' ,
32+ 'value' : signature ,
33+ })
34+ if doc :
35+ contents .append (doc )
36+ if not contents :
37+ return {'contents' : '' }
38+ return {'contents' : contents }
39+ else :
40+ # Find an exact match for a completion
41+ for d in definitions :
42+ if d .name == word :
43+ return {'contents' : _utils .format_docstring (d .docstring ()) or '' }
1844
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 :
3445 return {'contents' : '' }
35- return {'contents' : contents }
0 commit comments