3737@hookimpl
3838def pylsp_completions (config , document , position ):
3939 """Get formatted completions for current code position"""
40+ # pylint: disable=too-many-locals
41+
4042 settings = config .plugin_settings ('jedi_completion' , document_path = document .path )
43+ resolve_eagerly = settings .get ('eager' , False )
4144 code_position = _utils .position_to_jedi_linecolumn (document , position )
4245
43- code_position [" fuzzy" ] = settings .get (" fuzzy" , False )
46+ code_position [' fuzzy' ] = settings .get (' fuzzy' , False )
4447 completions = document .jedi_script (use_document_path = True ).complete (** code_position )
4548
4649 if not completions :
@@ -60,17 +63,37 @@ def pylsp_completions(config, document, position):
6063 for c in completions
6164 ]
6265
66+ # TODO split up once other improvements are merged
6367 if include_class_objects :
6468 for c in completions :
6569 if c .type == 'class' :
66- completion_dict = _format_completion (c , False )
70+ completion_dict = _format_completion (c , False , resolve = resolve_eagerly )
6771 completion_dict ['kind' ] = lsp .CompletionItemKind .TypeParameter
6872 completion_dict ['label' ] += ' object'
6973 ready_completions .append (completion_dict )
7074
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+
7187 return ready_completions or None
7288
7389
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+
7497def is_exception_class (name ):
7598 """
7699 Determine if a class name is an instance of an Exception.
@@ -121,16 +144,23 @@ def use_snippets(document, position):
121144 not (expr_type in _ERRORS and 'import' in code ))
122145
123146
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 ):
125154 completion = {
126155 'label' : _label (d ),
127156 'kind' : _TYPE_MAP .get (d .type ),
128- 'detail' : _detail (d ),
129- 'documentation' : _utils .format_docstring (d .docstring ()),
130157 'sortText' : _sort_text (d ),
131158 'insertText' : d .name
132159 }
133160
161+ if resolve :
162+ completion = _resolve_completion (completion , d )
163+
134164 if d .type == 'path' :
135165 path = osp .normpath (d .name )
136166 path = path .replace ('\\ ' , '\\ \\ ' )
0 commit comments