33
33
# Types of parso node for errors
34
34
_ERRORS = ('error_node' , )
35
35
36
- # most recently retrieved completion items, used for resolution
37
- _LAST_COMPLETIONS = {}
38
-
39
36
40
37
@hookimpl
41
38
def pylsp_completions (config , document , position ):
42
39
"""Get formatted completions for current code position"""
43
40
# pylint: disable=too-many-locals
44
- # pylint: disable=global-statement
45
- global _LAST_COMPLETIONS
46
41
47
42
settings = config .plugin_settings ('jedi_completion' , document_path = document .path )
48
43
resolve_eagerly = settings .get ('eager' , False )
49
44
code_position = _utils .position_to_jedi_linecolumn (document , position )
50
45
51
- code_position [" fuzzy" ] = settings .get (" fuzzy" , False )
46
+ code_position [' fuzzy' ] = settings .get (' fuzzy' , False )
52
47
completions = document .jedi_script (use_document_path = True ).complete (** code_position )
53
48
54
49
if not completions :
@@ -77,7 +72,13 @@ def pylsp_completions(config, document, position):
77
72
completion_dict ['label' ] += ' object'
78
73
ready_completions .append (completion_dict )
79
74
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' ] = {
81
82
# label is the only required property; here it is assumed to be unique
82
83
completion ['label' ]: (completion , data )
83
84
for completion , data in zip (ready_completions , completions )
@@ -87,9 +88,9 @@ def pylsp_completions(config, document, position):
87
88
88
89
89
90
@hookimpl
90
- def pylsp_completion_item_resolve (completion_item ):
91
+ def pylsp_completion_item_resolve (completion_item , document ):
91
92
"""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' ])
93
94
return _resolve_completion (completion , data )
94
95
95
96
0 commit comments