Skip to content

Commit 2aeb3aa

Browse files
committed
fix rope autoimport completion
1 parent a362006 commit 2aeb3aa

3 files changed

Lines changed: 45 additions & 14 deletions

File tree

pylsp/plugins/jedi_completion.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ def pylsp_completion_item_resolve(
147147
document,
148148
):
149149
"""Resolve formatted completion for given non-resolved completion"""
150+
151+
if (
152+
"LAST_JEDI_COMPLETIONS" not in document.shared_data
153+
or completion_item["label"] not in document.shared_data["LAST_JEDI_COMPLETIONS"]
154+
):
155+
return None
156+
150157
shared_data = document.shared_data["LAST_JEDI_COMPLETIONS"].get(
151158
completion_item["label"]
152159
)
@@ -158,15 +165,13 @@ def pylsp_completion_item_resolve(
158165
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
159166
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
160167

161-
if shared_data:
162-
completion, data = shared_data
163-
return _resolve_completion(
164-
completion,
165-
data,
166-
markup_kind=preferred_markup_kind,
167-
signature_config=config.settings().get("signature", {}),
168-
)
169-
return completion_item
168+
completion, data = shared_data
169+
return _resolve_completion(
170+
completion,
171+
data,
172+
markup_kind=preferred_markup_kind,
173+
signature_config=config.settings().get("signature", {}),
174+
)
170175

171176

172177
def is_exception_class(name):

pylsp/plugins/rope_autoimport.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,31 @@ def pylsp_completions(
265265
)
266266
if len(results) > MAX_RESULTS_COMPLETIONS:
267267
results = results[:MAX_RESULTS_COMPLETIONS]
268+
269+
# most recently retrieved completion items, used for resolution
270+
document.shared_data["LAST_ROPE_AUTOIMPORT_COMPLETIONS"] = {
271+
# label is the only required property; here it is assumed to be unique
272+
result["label"]: ...
273+
for result in results
274+
}
275+
268276
return results
269277

270278

279+
@hookimpl
280+
def pylsp_completion_item_resolve(config, completion_item, document):
281+
"""Resolve formatted completion for given non-resolved completion"""
282+
283+
if (
284+
"LAST_ROPE_AUTOIMPORT_COMPLETIONS" not in document.shared_data
285+
or completion_item["label"]
286+
not in document.shared_data["LAST_ROPE_AUTOIMPORT_COMPLETIONS"]
287+
):
288+
return None
289+
290+
return completion_item
291+
292+
271293
def _document(import_statement: str) -> str:
272294
return """# Auto-Import\n""" + import_statement
273295

pylsp/plugins/rope_completion.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ def pylsp_completions(config, workspace, document, position):
9292
@hookimpl
9393
def pylsp_completion_item_resolve(config, completion_item, document):
9494
"""Resolve formatted completion for given non-resolved completion"""
95+
96+
if (
97+
"LAST_ROPE_COMPLETIONS" not in document.shared_data
98+
or completion_item["label"] not in document.shared_data["LAST_ROPE_COMPLETIONS"]
99+
):
100+
return None
101+
95102
shared_data = document.shared_data["LAST_ROPE_COMPLETIONS"].get(
96103
completion_item["label"]
97104
)
@@ -102,11 +109,8 @@ def pylsp_completion_item_resolve(config, completion_item, document):
102109
item_capabilities = completion_capabilities.get("completionItem", {})
103110
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
104111
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
105-
106-
if shared_data:
107-
completion, data = shared_data
108-
return _resolve_completion(completion, data, preferred_markup_kind)
109-
return completion_item
112+
completion, data = shared_data
113+
return _resolve_completion(completion, data, preferred_markup_kind)
110114

111115

112116
def _sort_text(definition):

0 commit comments

Comments
 (0)