66
77
88class JediCompletion (object ):
9- types = {
9+ basic_types = {
1010 'module' : 'import' ,
1111 'class' : 'class' ,
1212 'instance' : 'variable' ,
@@ -20,6 +20,33 @@ def __init__(self):
2020 if path not in sys .path :
2121 sys .path .insert (0 , path )
2222
23+ def _get_completion_type (self , completion ):
24+ is_built_in = completion .in_builtin_module
25+ if completion .type not in ['import' , 'keyword' ] and is_built_in ():
26+ return 'builtin'
27+ if completion .type in ['statement' ] and completion .name .isupper ():
28+ return 'constant'
29+ if completion .type in self .basic_types :
30+ return self .basic_types .get (completion .type )
31+
32+ def _description (self , completion ):
33+ """Provide a description of the completion object."""
34+ if completion ._definition is None :
35+ return ''
36+ t = completion .type
37+ if t == 'statement' :
38+ desc = '' .join (
39+ c .get_code () for c in completion ._definition .children
40+ if type (c ).__name__ in ['InstanceElement' , 'String' ]).replace ('\n ' , '' )
41+ elif t == 'keyword' :
42+ desc = ''
43+ elif t == 'import' :
44+ desc = completion ._definition .get_code ()
45+ else :
46+ desc = '.' .join (unicode (p ) for p in completion ._path ())
47+ line = '' if completion .in_builtin_module else '@%s' % completion .line
48+ return ('%s: %s%s' % (t , desc , line ))[:50 ]
49+
2350 @classmethod
2451 def _get_top_level_module (cls , path ):
2552 """Recursively walk through directories looking for top level module.
@@ -57,10 +84,10 @@ def _serialize(self, completions, identifier):
5784 'snippet' : self ._generate_snippet (completion ),
5885 'displayText' : completion .name ,
5986 # 'replacementPrefix': completion.name[:completion._like_name_length],
60- 'type' : self .types . get (completion . type ),
87+ 'type' : self ._get_completion_type (completion ),
6188 # TODO: try to understand return value
6289 # 'leftLabel': '',
63- 'rightLabel' : completion . description ,
90+ 'rightLabel' : self . _description ( completion ) ,
6491 'description' : completion .docstring (),
6592 # 'descriptionMoreURL': completion.module_name
6693 })
0 commit comments