3333# Types of parso node for errors
3434_ERRORS = ('error_node' , )
3535
36- # most recently retrieved completion items, used for resolution
37- _LAST_COMPLETIONS = {}
38-
3936
4037@hookimpl
4138def pylsp_completions (config , document , position ):
4239 """Get formatted completions for current code position"""
4340 # pylint: disable=too-many-locals
44- # pylint: disable=global-statement
45- global _LAST_COMPLETIONS
4641
4742 settings = config .plugin_settings ('jedi_completion' , document_path = document .path )
4843 resolve_eagerly = settings .get ('eager' , False )
4944 code_position = _utils .position_to_jedi_linecolumn (document , position )
5045
51- code_position [" fuzzy" ] = settings .get (" fuzzy" , False )
46+ code_position [' fuzzy' ] = settings .get (' fuzzy' , False )
5247 completions = document .jedi_script (use_document_path = True ).complete (** code_position )
5348
5449 if not completions :
@@ -77,7 +72,13 @@ def pylsp_completions(config, document, position):
7772 completion_dict ['label' ] += ' object'
7873 ready_completions .append (completion_dict )
7974
80- _LAST_COMPLETIONS = {
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' ] = {
8182 # label is the only required property; here it is assumed to be unique
8283 completion ['label' ]: (completion , data )
8384 for completion , data in zip (ready_completions , completions )
@@ -87,9 +88,9 @@ def pylsp_completions(config, document, position):
8788
8889
8990@hookimpl
90- def pylsp_completion_item_resolve (completion_item ):
91+ def pylsp_completion_item_resolve (completion_item , document ):
9192 """Resolve formatted completion for given non-resolved completion"""
92- completion , data = _LAST_COMPLETIONS .get (completion_item ['label' ])
93+ completion , data = document . shared_data [ 'LAST_JEDI_COMPLETIONS' ] .get (completion_item ['label' ])
9394 return _resolve_completion (completion , data )
9495
9596
0 commit comments