Skip to content

Commit f38d3ef

Browse files
committed
Handle Rope find_implementations errors explicitly
1 parent c1437e8 commit f38d3ef

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pylsp/plugins/rope_implementation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def pylsp_implementations(config, workspace, document, position):
2626
rope_project = workspace._rope_project_builder(rope_config)
2727
rope_resource = document._rope_resource(rope_config)
2828

29-
impls = find_implementations(rope_project, rope_resource, offset)
29+
try:
30+
impls = find_implementations(rope_project, rope_resource, offset)
31+
except Exception as e:
32+
log.debug("Failed to run Rope implementations finder: %s", e)
33+
return []
3034

3135
return [
3236
{

test/plugins/test_implementations.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pathlib import Path
66

77
import pytest
8-
from rope.base.exceptions import BadIdentifierError
98

109
from pylsp import uris
1110
from pylsp.config.config import Config
@@ -74,7 +73,7 @@ def test_implementations_skipping_one_class(config, workspace, doc_uri) -> None:
7473

7574

7675
@pytest.mark.xfail(
77-
reason="not implemented upstream (Rope)", strict=True, raises=BadIdentifierError
76+
reason="not implemented upstream (Rope)", strict=True, raises=AssertionError
7877
)
7978
def test_property_implementations(config, workspace, doc_uri) -> None:
8079
# Over 'Animal.size'
@@ -93,12 +92,11 @@ def test_property_implementations(config, workspace, doc_uri) -> None:
9392

9493

9594
def test_implementations_not_a_method(config, workspace, doc_uri) -> None:
96-
# Over 'print(...)' call => Rope error because not a method.
95+
# Over 'print(...)' call
9796
cursor_pos = {"line": 28, "character": 0}
9897

9998
doc = workspace.get_document(doc_uri)
10099

101-
# This exception is turned into an empty result set automatically in upper
102-
# layers, so we just check that it is raised to document this behavior:
103-
with pytest.raises(BadIdentifierError):
104-
pylsp_implementations(config, workspace, doc, cursor_pos)
100+
# Rope produces an error because we're not over a method, which we then
101+
# turn into an empty result list:
102+
assert [] == pylsp_implementations(config, workspace, doc, cursor_pos)

0 commit comments

Comments
 (0)