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_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): diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index bdc072d4..c5eed12c 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -420,8 +420,13 @@ def completions(self, doc_uri, position): def completion_item_resolve(self, completion_item): doc_uri = completion_item.get("data", {}).get("doc_uri", None) - return self._hook( - "pylsp_completion_item_resolve", doc_uri, completion_item=completion_item + return ( + self._hook( + "pylsp_completion_item_resolve", + doc_uri, + completion_item=completion_item, + ) + or completion_item ) def definitions(self, doc_uri, position):