diff --git a/pylsp/plugins/jedi_completion.py b/pylsp/plugins/jedi_completion.py index 51c3589c..4aa1826b 100644 --- a/pylsp/plugins/jedi_completion.py +++ b/pylsp/plugins/jedi_completion.py @@ -147,6 +147,13 @@ def pylsp_completion_item_resolve( document, ): """Resolve formatted completion for given non-resolved completion""" + + if ( + "LAST_JEDI_COMPLETIONS" not in document.shared_data + or completion_item["label"] not in document.shared_data["LAST_JEDI_COMPLETIONS"] + ): + return None + shared_data = document.shared_data["LAST_JEDI_COMPLETIONS"].get( completion_item["label"] ) @@ -158,15 +165,13 @@ def pylsp_completion_item_resolve( supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"]) preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds) - if shared_data: - completion, data = shared_data - return _resolve_completion( - completion, - data, - markup_kind=preferred_markup_kind, - signature_config=config.settings().get("signature", {}), - ) - return completion_item + completion, data = shared_data + return _resolve_completion( + completion, + data, + markup_kind=preferred_markup_kind, + signature_config=config.settings().get("signature", {}), + ) def is_exception_class(name): diff --git a/pylsp/plugins/rope_autoimport.py b/pylsp/plugins/rope_autoimport.py index be51d20e..6de3dad9 100644 --- a/pylsp/plugins/rope_autoimport.py +++ b/pylsp/plugins/rope_autoimport.py @@ -265,9 +265,31 @@ def pylsp_completions( ) if len(results) > MAX_RESULTS_COMPLETIONS: results = results[:MAX_RESULTS_COMPLETIONS] + + # most recently retrieved completion items, used for resolution + document.shared_data["LAST_ROPE_AUTOIMPORT_COMPLETIONS"] = { + # label is the only required property; here it is assumed to be unique + result["label"]: ... + for result in results + } + return results +@hookimpl +def pylsp_completion_item_resolve(config, completion_item, document): + """Resolve formatted completion for given non-resolved completion""" + + if ( + "LAST_ROPE_AUTOIMPORT_COMPLETIONS" not in document.shared_data + or completion_item["label"] + not in document.shared_data["LAST_ROPE_AUTOIMPORT_COMPLETIONS"] + ): + return None + + return completion_item + + def _document(import_statement: str) -> str: return """# Auto-Import\n""" + import_statement diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index dc94ddea..47681e38 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -92,6 +92,13 @@ def pylsp_completions(config, workspace, document, position): @hookimpl def pylsp_completion_item_resolve(config, completion_item, document): """Resolve formatted completion for given non-resolved completion""" + + if ( + "LAST_ROPE_COMPLETIONS" not in document.shared_data + or completion_item["label"] not in document.shared_data["LAST_ROPE_COMPLETIONS"] + ): + return None + shared_data = document.shared_data["LAST_ROPE_COMPLETIONS"].get( completion_item["label"] ) @@ -102,11 +109,8 @@ def pylsp_completion_item_resolve(config, completion_item, document): item_capabilities = completion_capabilities.get("completionItem", {}) supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"]) preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds) - - if shared_data: - completion, data = shared_data - return _resolve_completion(completion, data, preferred_markup_kind) - return completion_item + completion, data = shared_data + return _resolve_completion(completion, data, preferred_markup_kind) def _sort_text(definition):