37
37
@hookimpl
38
38
def pylsp_completions (config , document , position ):
39
39
"""Get formatted completions for current code position"""
40
+ # pylint: disable=too-many-locals
41
+
40
42
settings = config .plugin_settings ('jedi_completion' , document_path = document .path )
43
+ resolve_eagerly = settings .get ('eager' , False )
41
44
code_position = _utils .position_to_jedi_linecolumn (document , position )
42
45
43
- code_position [" fuzzy" ] = settings .get (" fuzzy" , False )
46
+ code_position [' fuzzy' ] = settings .get (' fuzzy' , False )
44
47
completions = document .jedi_script (use_document_path = True ).complete (** code_position )
45
48
46
49
if not completions :
@@ -60,17 +63,37 @@ def pylsp_completions(config, document, position):
60
63
for c in completions
61
64
]
62
65
66
+ # TODO split up once other improvements are merged
63
67
if include_class_objects :
64
68
for c in completions :
65
69
if c .type == 'class' :
66
- completion_dict = _format_completion (c , False )
70
+ completion_dict = _format_completion (c , False , resolve = resolve_eagerly )
67
71
completion_dict ['kind' ] = lsp .CompletionItemKind .TypeParameter
68
72
completion_dict ['label' ] += ' object'
69
73
ready_completions .append (completion_dict )
70
74
75
+ for completion_dict in ready_completions :
76
+ completion_dict ['data' ] = {
77
+ 'doc_uri' : document .uri
78
+ }
79
+
80
+ # most recently retrieved completion items, used for resolution
81
+ document .shared_data ['LAST_JEDI_COMPLETIONS' ] = {
82
+ # label is the only required property; here it is assumed to be unique
83
+ completion ['label' ]: (completion , data )
84
+ for completion , data in zip (ready_completions , completions )
85
+ }
86
+
71
87
return ready_completions or None
72
88
73
89
90
+ @hookimpl
91
+ def pylsp_completion_item_resolve (completion_item , document ):
92
+ """Resolve formatted completion for given non-resolved completion"""
93
+ completion , data = document .shared_data ['LAST_JEDI_COMPLETIONS' ].get (completion_item ['label' ])
94
+ return _resolve_completion (completion , data )
95
+
96
+
74
97
def is_exception_class (name ):
75
98
"""
76
99
Determine if a class name is an instance of an Exception.
@@ -121,16 +144,23 @@ def use_snippets(document, position):
121
144
not (expr_type in _ERRORS and 'import' in code ))
122
145
123
146
124
- def _format_completion (d , include_params = True ):
147
+ def _resolve_completion (completion , d ):
148
+ completion ['detail' ] = _detail (d )
149
+ completion ['documentation' ] = _utils .format_docstring (d .docstring ())
150
+ return completion
151
+
152
+
153
+ def _format_completion (d , include_params = True , resolve = False ):
125
154
completion = {
126
155
'label' : _label (d ),
127
156
'kind' : _TYPE_MAP .get (d .type ),
128
- 'detail' : _detail (d ),
129
- 'documentation' : _utils .format_docstring (d .docstring ()),
130
157
'sortText' : _sort_text (d ),
131
158
'insertText' : d .name
132
159
}
133
160
161
+ if resolve :
162
+ completion = _resolve_completion (completion , d )
163
+
134
164
if d .type == 'path' :
135
165
path = osp .normpath (d .name )
136
166
path = path .replace ('\\ ' , '\\ \\ ' )
0 commit comments