From de476143472aaf0dbbc04393d2fb1a7e9adc7ac4 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 25 Nov 2021 16:23:41 -0500 Subject: [PATCH 1/3] Fix error when resolving completion items for Rope --- pylsp/plugins/rope_completion.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index b73d8412..cd4c047c 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -83,8 +83,11 @@ def pylsp_completions(config, workspace, document, position): @hookimpl def pylsp_completion_item_resolve(completion_item, document): """Resolve formatted completion for given non-resolved completion""" - completion, data = document.shared_data['LAST_ROPE_COMPLETIONS'].get(completion_item['label']) - return _resolve_completion(completion, data) + shared_data = document.shared_data['LAST_ROPE_COMPLETIONS'].get(completion_item['label']) + if shared_data: + completion, data = shared_data + return _resolve_completion(completion, data) + return completion_item def _sort_text(definition): From b19331fa7131ddd69067def3f4b3e95ecf0705a2 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 25 Nov 2021 16:24:24 -0500 Subject: [PATCH 2/3] Catch any possible error whe trying to get docs for completion items in Rope --- pylsp/plugins/rope_completion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index cd4c047c..44dbe5b9 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -17,9 +17,10 @@ def pylsp_settings(): def _resolve_completion(completion, data): + # pylint: disable=broad-except try: doc = data.get_doc() - except AttributeError: + except Exception: doc = "" completion['detail'] = '{0} {1}'.format(data.scope or "", data.name) completion['documentation'] = doc From 3290eaca3181d24dfe73dc95d2d1840b6d7e3d32 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 6 Dec 2021 21:11:53 -0500 Subject: [PATCH 3/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MichaƂ Krassowski <5832902+krassowski@users.noreply.github.com> --- pylsp/plugins/rope_completion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index 44dbe5b9..502d2390 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -20,7 +20,8 @@ def _resolve_completion(completion, data): # pylint: disable=broad-except try: doc = data.get_doc() - except Exception: + except Exception as e: + log.debug("Failed to resolve Rope completion: %s", e) doc = "" completion['detail'] = '{0} {1}'.format(data.scope or "", data.name) completion['documentation'] = doc