diff --git a/pylsp/plugins/jedi_rename.py b/pylsp/plugins/jedi_rename.py index 5606a881..b35e321a 100644 --- a/pylsp/plugins/jedi_rename.py +++ b/pylsp/plugins/jedi_rename.py @@ -20,7 +20,7 @@ def pylsp_rename(config, workspace, document, position, new_name): except NotImplementedError as exc: raise Exception( "No support for renaming in Python 2/3.5 with Jedi. " - "Consider using the rope_rename plugin instead" + "Consider using the pylsp-rope plugin instead" ) from exc log.debug("Finished rename: %s", refactoring.get_diff()) changes = [] diff --git a/pylsp/plugins/rope_rename.py b/pylsp/plugins/rope_rename.py deleted file mode 100644 index 9e386944..00000000 --- a/pylsp/plugins/rope_rename.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2017-2020 Palantir Technologies, Inc. -# Copyright 2021- Python Language Server Contributors. - -import logging - -from rope.base import libutils -from rope.refactor.rename import Rename - -from pylsp import _utils, hookimpl, uris - -log = logging.getLogger(__name__) - - -@hookimpl -def pylsp_settings(): - # Default rope_rename to disabled - return {"plugins": {"rope_rename": {"enabled": False}}} - - -@hookimpl -def pylsp_rename(config, workspace, document, position, new_name): - rope_config = config.settings(document_path=document.path).get("rope", {}) - rope_project = workspace._rope_project_builder(rope_config) - - rename = Rename( - rope_project, - libutils.path_to_resource(rope_project, document.path), - document.offset_at_position(position), - ) - - log.debug( - "Executing rename of %s to %s", document.word_at_position(position), new_name - ) - changeset = rename.get_changes(new_name, in_hierarchy=True, docs=True) - log.debug("Finished rename: %s", changeset.changes) - changes = [] - for change in changeset.changes: - uri = uris.from_fs_path(change.resource.path) - doc = workspace.get_maybe_document(uri) - changes.append( - { - "textDocument": {"uri": uri, "version": doc.version if doc else None}, - "edits": [ - { - "range": { - "start": {"line": 0, "character": 0}, - "end": { - "line": _num_lines(change.resource), - "character": 0, - }, - }, - "newText": change.new_contents, - } - ], - } - ) - return {"documentChanges": changes} - - -def _num_lines(resource): - "Count the number of lines in a `File` resource." - text = resource.read() - - if _utils.get_eol_chars(text): - return len(text.splitlines()) - return 0 diff --git a/pyproject.toml b/pyproject.toml index 4665dcbe..9dbb4bbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,6 @@ pydocstyle = "pylsp.plugins.pydocstyle_lint" pyflakes = "pylsp.plugins.pyflakes_lint" pylint = "pylsp.plugins.pylint_lint" rope_completion = "pylsp.plugins.rope_completion" -rope_rename = "pylsp.plugins.rope_rename" rope_autoimport = "pylsp.plugins.rope_autoimport" yapf = "pylsp.plugins.yapf_format" diff --git a/test/plugins/test_rope_rename.py b/test/plugins/test_rope_rename.py deleted file mode 100644 index c55ead0a..00000000 --- a/test/plugins/test_rope_rename.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2017-2020 Palantir Technologies, Inc. -# Copyright 2021- Python Language Server Contributors. - -import os - -import pytest - -from pylsp import uris -from pylsp.plugins.rope_rename import pylsp_rename -from pylsp.workspace import Document - -DOC_NAME = "test1.py" -DOC = """class Test1(): - pass - -class Test2(Test1): - pass -""" - -DOC_NAME_SIMPLE = "test2.py" -DOC_SIMPLE = "foo = 12" - - -@pytest.fixture -def tmp_workspace(temp_workspace_factory): - return temp_workspace_factory({DOC_NAME: DOC, DOC_NAME_SIMPLE: DOC_SIMPLE}) - - -def test_rope_rename(tmp_workspace, config): - position = {"line": 0, "character": 6} - DOC_URI = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC_NAME)) - doc = Document(DOC_URI, tmp_workspace) - - result = pylsp_rename(config, tmp_workspace, doc, position, "ShouldBeRenamed") - assert len(result.keys()) == 1 - - changes = result.get("documentChanges") - assert len(changes) == 1 - changes = changes[0] - - # Note that this test differs from test_jedi_rename, because rope does not - # seem to modify files that haven't been opened with textDocument/didOpen. - assert changes.get("edits") == [ - { - "range": { - "start": {"line": 0, "character": 0}, - "end": {"line": 5, "character": 0}, - }, - "newText": "class ShouldBeRenamed():\n pass\n\nclass Test2(ShouldBeRenamed):\n pass\n", - } - ] - - # Regression test for issue python-lsp/python-lsp-server#413 - # rename foo - position = {"line": 0, "character": 0} - DOC_URI = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC_NAME_SIMPLE)) - doc = Document(DOC_URI, tmp_workspace) - - result = pylsp_rename(config, tmp_workspace, doc, position, "bar") - assert len(result.keys()) == 1 - - changes = result.get("documentChanges") - assert len(changes) == 1 - - assert changes[0].get("edits") == [ - { - "range": { - "start": {"line": 0, "character": 0}, - "end": {"line": 0, "character": 0}, - }, - "newText": "bar = 12", - } - ]