Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-pylsp-rope for openSUSE:Factory checked in at 2021-11-23 22:10:48 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pylsp-rope (Old) and /work/SRC/openSUSE:Factory/.python-pylsp-rope.new.1895 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pylsp-rope" Tue Nov 23 22:10:48 2021 rev:4 rq:933307 version:0.1.7 Changes: -------- --- /work/SRC/openSUSE:Factory/python-pylsp-rope/python-pylsp-rope.changes 2021-10-12 21:51:34.940063177 +0200 +++ /work/SRC/openSUSE:Factory/.python-pylsp-rope.new.1895/python-pylsp-rope.changes 2021-11-23 22:13:22.494321411 +0100 @@ -1,0 +2,10 @@ +Tue Nov 23 17:38:31 UTC 2021 - Matej Cepl <mc...@suse.com> + +- Update to 0.1.7: + - pylsp-rope now work on unsaved buffers. This support is + currently experimental. + - New Refactoring: + - Implement local to field refactoring + - Implement organize import code action + +------------------------------------------------------------------- Old: ---- pylsp-rope-0.1.6.tar.gz New: ---- pylsp-rope-0.1.7.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pylsp-rope.spec ++++++ --- /var/tmp/diff_new_pack.F5ij9G/_old 2021-11-23 22:13:22.970319837 +0100 +++ /var/tmp/diff_new_pack.F5ij9G/_new 2021-11-23 22:13:22.970319837 +0100 @@ -19,7 +19,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %define skip_python2 1 Name: python-pylsp-rope -Version: 0.1.6 +Version: 0.1.7 Release: 0 Summary: Extended refactoring capabilities for Python LSP Server using Rope License: MIT ++++++ pylsp-rope-0.1.6.tar.gz -> pylsp-rope-0.1.7.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/PKG-INFO new/pylsp-rope-0.1.7/PKG-INFO --- old/pylsp-rope-0.1.6/PKG-INFO 2021-10-12 04:16:42.299155200 +0200 +++ new/pylsp-rope-0.1.7/PKG-INFO 2021-11-05 08:10:35.458753300 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pylsp-rope -Version: 0.1.6 +Version: 0.1.7 Summary: Extended refactoring capabilities for Python LSP Server using Rope. Home-page: https://github.com/python-rope/pylsp-rope Author: Lie Ryan @@ -46,9 +46,11 @@ ``` Then run `pylsp` as usual, the plugin will be auto-discovered by -python-lsp-server if you've installed it to the right environment. Refer to -your IDE/text editor's documentation on how to setup a language server in your -IDE/text editor. +python-lsp-server if you've installed it to the right environment. On Vim, +refer to [Rope in Vim or +Neovim](https://github.com/python-rope/rope/wiki/Rope-in-Vim-or-Neovim). For +other editors, refer to your IDE/text editor's documentation on how to setup a +language server. ## Configuration @@ -63,6 +65,8 @@ - inline method/variable/parameter (codeAction) - use function (codeAction) - method to method object (codeAction) +- convert local variable to field (codeAction) +- organize imports (codeAction) - more to come... Refer to [Rope documentation](https://github.com/python-rope/rope/blob/master/docs/overview.rst) @@ -72,35 +76,40 @@ ### Extract method -This refactoring works by triggering a CodeAction when selecting a block of -code. +This refactoring works by triggering CodeAction when selecting a block of code. ### Extract variable -This refactoring works by triggering a CodeAction when selecting a Python +This refactoring works by triggering CodeAction when selecting a Python expression. ### Inline -This refactoring works by triggering a CodeAction when the cursor is on a +This refactoring works by triggering CodeAction when the cursor is on a resolvable Python identifier. ### Use function -This works by triggering a CodeAction when the cursor is on the function name -of a `def` statement. +This refactoring works by triggering CodeAction when the cursor is on the +function name of a `def` statement. ### Method to method object -This works by triggering a CodeAction when the cursor is on the function name -of a `def` statement. +This refactoring works by triggering CodeAction when the cursor is on the +function name of a `def` statement. -## Caveat +### Convert local variable to field + +This refactoring works by triggering CodeAction when the cursor is on a local +variable. + +### Organize import -Support for working on unsaved document is currently incomplete. +This refactoring works by triggering CodeAction anywhere. + +## Caveat -Before you start refactoring you must save all unsaved changes in your text -editor. I highly recommended that you enable autosave on your text editor. +Support for working on unsaved document is currently experimental. This plugin is in early development, so expect some bugs. Please report in [Github issue tracker](https://github.com/python-lsp/python-lsp-server/issues) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/README.md new/pylsp-rope-0.1.7/README.md --- old/pylsp-rope-0.1.6/README.md 2021-10-12 04:04:46.000000000 +0200 +++ new/pylsp-rope-0.1.7/README.md 2021-11-04 23:39:22.000000000 +0100 @@ -23,9 +23,11 @@ ``` Then run `pylsp` as usual, the plugin will be auto-discovered by -python-lsp-server if you've installed it to the right environment. Refer to -your IDE/text editor's documentation on how to setup a language server in your -IDE/text editor. +python-lsp-server if you've installed it to the right environment. On Vim, +refer to [Rope in Vim or +Neovim](https://github.com/python-rope/rope/wiki/Rope-in-Vim-or-Neovim). For +other editors, refer to your IDE/text editor's documentation on how to setup a +language server. ## Configuration @@ -40,6 +42,8 @@ - inline method/variable/parameter (codeAction) - use function (codeAction) - method to method object (codeAction) +- convert local variable to field (codeAction) +- organize imports (codeAction) - more to come... Refer to [Rope documentation](https://github.com/python-rope/rope/blob/master/docs/overview.rst) @@ -49,35 +53,40 @@ ### Extract method -This refactoring works by triggering a CodeAction when selecting a block of -code. +This refactoring works by triggering CodeAction when selecting a block of code. ### Extract variable -This refactoring works by triggering a CodeAction when selecting a Python +This refactoring works by triggering CodeAction when selecting a Python expression. ### Inline -This refactoring works by triggering a CodeAction when the cursor is on a +This refactoring works by triggering CodeAction when the cursor is on a resolvable Python identifier. ### Use function -This works by triggering a CodeAction when the cursor is on the function name -of a `def` statement. +This refactoring works by triggering CodeAction when the cursor is on the +function name of a `def` statement. ### Method to method object -This works by triggering a CodeAction when the cursor is on the function name -of a `def` statement. +This refactoring works by triggering CodeAction when the cursor is on the +function name of a `def` statement. -## Caveat +### Convert local variable to field + +This refactoring works by triggering CodeAction when the cursor is on a local +variable. + +### Organize import -Support for working on unsaved document is currently incomplete. +This refactoring works by triggering CodeAction anywhere. + +## Caveat -Before you start refactoring you must save all unsaved changes in your text -editor. I highly recommended that you enable autosave on your text editor. +Support for working on unsaved document is currently experimental. This plugin is in early development, so expect some bugs. Please report in [Github issue tracker](https://github.com/python-lsp/python-lsp-server/issues) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/pylsp_rope/commands.py new/pylsp-rope-0.1.7/pylsp_rope/commands.py --- old/pylsp-rope-0.1.6/pylsp_rope/commands.py 2021-10-07 19:25:19.000000000 +0200 +++ new/pylsp-rope-0.1.7/pylsp_rope/commands.py 2021-11-04 19:38:56.000000000 +0100 @@ -3,3 +3,5 @@ COMMAND_REFACTOR_INLINE = "pylsp_rope.refactor.inline" COMMAND_REFACTOR_USE_FUNCTION = "pylsp_rope.refactor.use_function" COMMAND_REFACTOR_METHOD_TO_METHOD_OBJECT = "pylsp_rope.refactor.method_to_method_object" +COMMAND_REFACTOR_LOCAL_TO_FIELD = "pylsp_rope.refactor.local_to_field" +COMMAND_SOURCE_ORGANIZE_IMPORT = "pylsp_rope.source.organize_import" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/pylsp_rope/plugin.py new/pylsp-rope-0.1.7/pylsp_rope/plugin.py --- old/pylsp-rope-0.1.6/pylsp_rope/plugin.py 2021-10-12 02:06:26.000000000 +0200 +++ new/pylsp-rope-0.1.7/pylsp_rope/plugin.py 2021-11-04 23:24:08.000000000 +0100 @@ -4,7 +4,14 @@ from pylsp import hookimpl from pylsp.lsp import MessageType -from rope.refactor import extract, inline, method_object, usefunction +from rope.refactor import ( + extract, + inline, + method_object, + usefunction, + localtofield, + importutils, +) from pylsp_rope import typing, commands from pylsp_rope.project import ( @@ -68,6 +75,10 @@ end_offset = current_document.offset_at_position(range["end"]) selected_text = document.source[start_offset:end_offset] + project = get_project(workspace) + for resource in get_resources(workspace, workspace.documents.keys()): + project.pycore._invalidate_resource_cache(resource) + commands = { "Extract method": CommandRefactorExtractMethod( workspace, @@ -100,6 +111,15 @@ document_uri=document.uri, position=info.position, ), + "Convert local variable to field": CommandRefactorLocalToField( + workspace, + document_uri=document.uri, + position=info.position, + ), + "Organize import": CommandSourceOrganizeImport( + workspace, + document_uri=document.uri, + ), } return [ @@ -140,6 +160,10 @@ self.__dict__.update(**arguments) def __call__(self): + rope_changeset = self.get_changes() + apply_rope_changeset(self.workspace, rope_changeset) + + def get_changes(self): pass def validate(self, info): @@ -183,7 +207,7 @@ # def _is_valid(self, info): # ... - def __call__(self): + def get_changes(self): current_document, resource = get_resource(self.workspace, self.document_uri) refactoring = extract.ExtractMethod( @@ -195,7 +219,7 @@ rope_changeset = refactoring.get_changes( extracted_name="extracted_method", ) - apply_rope_changeset(self.workspace, rope_changeset) + return rope_changeset class CommandRefactorExtractVariable(Command): @@ -209,7 +233,7 @@ # FIXME: requires rope.refactor.extract._ExceptionalConditionChecker for proper checking ast.parse(info.selected_text, mode="eval") - def __call__(self): + def get_changes(self): current_document, resource = get_resource(self.workspace, self.document_uri) refactoring = extract.ExtractVariable( @@ -221,7 +245,7 @@ rope_changeset = refactoring.get_changes( extracted_name="extracted_variable", ) - apply_rope_changeset(self.workspace, rope_changeset) + return rope_changeset class CommandRefactorInline(Command): @@ -238,7 +262,7 @@ offset=info.current_document.offset_at_position(info.position), ) - def __call__(self): + def get_changes(self): current_document, resource = get_resource(self.workspace, self.document_uri) refactoring = inline.create_inline( @@ -247,7 +271,7 @@ offset=current_document.offset_at_position(self.position), ) rope_changeset = refactoring.get_changes() - apply_rope_changeset(self.workspace, rope_changeset) + return rope_changeset class CommandRefactorUseFunction(Command): @@ -264,7 +288,7 @@ offset=info.current_document.offset_at_position(info.position), ) - def __call__(self): + def get_changes(self): current_document, resource = get_resource(self.workspace, self.document_uri) refactoring = usefunction.UseFunction( @@ -275,7 +299,7 @@ rope_changeset = refactoring.get_changes( resources=get_resources(self.workspace, getattr(self, "documents", None)), ) - apply_rope_changeset(self.workspace, rope_changeset) + return rope_changeset class CommandRefactorMethodToMethodObject(Command): @@ -292,7 +316,7 @@ offset=info.current_document.offset_at_position(self.position), ) - def __call__(self): + def get_changes(self): current_document, resource = get_resource(self.workspace, self.document_uri) refactoring = method_object.MethodObject( @@ -301,4 +325,48 @@ offset=current_document.offset_at_position(self.position), ) rope_changeset = refactoring.get_changes(classname="NewMethodObject") - apply_rope_changeset(self.workspace, rope_changeset) + return rope_changeset + + +class CommandRefactorLocalToField(Command): + name = commands.COMMAND_REFACTOR_LOCAL_TO_FIELD + kind: CodeActionKind = "refactor.rewrite" + + document_uri: DocumentUri + position: typing.Range + + def validate(self, info): + localtofield.LocalToField( + project=self.project, + resource=info.resource, + offset=info.current_document.offset_at_position(self.position), + ) + + def get_changes(self): + current_document, resource = get_resource(self.workspace, self.document_uri) + + refactoring = localtofield.LocalToField( + project=self.project, + resource=resource, + offset=current_document.offset_at_position(self.position), + ) + rope_changeset = refactoring.get_changes() + return rope_changeset + + +class CommandSourceOrganizeImport(Command): + name = commands.COMMAND_SOURCE_ORGANIZE_IMPORT + kind: CodeActionKind = "source.organizeImports" + + document_uri: DocumentUri + + def get_changes(self): + current_document, resource = get_resource(self.workspace, self.document_uri) + + organizer = importutils.ImportOrganizer( + project=self.project, + ) + rope_changeset = organizer.organize_imports( + resource=resource, + ) + return rope_changeset diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/pylsp_rope/project.py new/pylsp-rope-0.1.7/pylsp_rope/project.py --- old/pylsp-rope-0.1.6/pylsp_rope/project.py 2021-10-12 02:06:26.000000000 +0200 +++ new/pylsp-rope-0.1.7/pylsp_rope/project.py 2021-11-04 03:25:30.000000000 +0100 @@ -4,6 +4,7 @@ from pylsp import uris, workspace from rope.base import libutils +from rope.base.fscommands import FileSystemCommands from pylsp_rope import rope from pylsp_rope.lsp_diff import lsp_diff @@ -14,28 +15,20 @@ @lru_cache(maxsize=None) -def _get_project(workspace) -> rope.Project: - project = rope.Project(workspace.root_path) - return project - - def get_project(workspace) -> rope.Project: - project = _get_project(workspace) - project.validate() - return project + fscommands = WorkspaceFileCommands(workspace) + return rope.Project(workspace.root_path, fscommands=fscommands) def get_resource( workspace, document_uri: DocumentUri ) -> Tuple[workspace.Document, rope.Resource]: document = workspace.get_document(document_uri) - resource = libutils.path_to_resource(_get_project(workspace), document.path) + resource = libutils.path_to_resource(get_project(workspace), document.path) return document, resource -def get_resources( - workspace, documents: List[workspace.Document] -) -> List[rope.Resource]: +def get_resources(workspace, documents: List[DocumentUri]) -> List[rope.Resource]: if documents is None: return None return [get_resource(workspace, document_uri)[1] for document_uri in documents] @@ -79,3 +72,36 @@ logger.info("applying workspace edit: %s", workspace_edit) workspace.apply_edit(workspace_edit) + + +class WorkspaceFileCommands(object): + def __init__(self, workspace): + self.workspace = workspace + self.normal_actions = FileSystemCommands() + + def create_file(self, path): + return self.normal_actions.create_file(path) + + def create_folder(self, path): + return self.normal_actions.create_folder(path) + + def move(self, path, new_location): + return self.normal_actions.move(path, new_location) + + def remove(self, path): + return self.normal_actions.remove(path) + + def write(self, path, data): + return self.normal_actions.write(path, data) + + def read(self, path): + document_uri = uris.from_fs_path(path) + document = self.workspace.get_maybe_document(document_uri) + if document is None: + content = self.normal_actions.read(path) + logger.info('reading from filesystem: "%s":', path) + return content + else: + content = document.source.encode("utf-8") + logger.info('reading from workspace: "%s":', path) + return content diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/pylsp_rope.egg-info/PKG-INFO new/pylsp-rope-0.1.7/pylsp_rope.egg-info/PKG-INFO --- old/pylsp-rope-0.1.6/pylsp_rope.egg-info/PKG-INFO 2021-10-12 04:16:42.000000000 +0200 +++ new/pylsp-rope-0.1.7/pylsp_rope.egg-info/PKG-INFO 2021-11-05 08:10:35.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pylsp-rope -Version: 0.1.6 +Version: 0.1.7 Summary: Extended refactoring capabilities for Python LSP Server using Rope. Home-page: https://github.com/python-rope/pylsp-rope Author: Lie Ryan @@ -46,9 +46,11 @@ ``` Then run `pylsp` as usual, the plugin will be auto-discovered by -python-lsp-server if you've installed it to the right environment. Refer to -your IDE/text editor's documentation on how to setup a language server in your -IDE/text editor. +python-lsp-server if you've installed it to the right environment. On Vim, +refer to [Rope in Vim or +Neovim](https://github.com/python-rope/rope/wiki/Rope-in-Vim-or-Neovim). For +other editors, refer to your IDE/text editor's documentation on how to setup a +language server. ## Configuration @@ -63,6 +65,8 @@ - inline method/variable/parameter (codeAction) - use function (codeAction) - method to method object (codeAction) +- convert local variable to field (codeAction) +- organize imports (codeAction) - more to come... Refer to [Rope documentation](https://github.com/python-rope/rope/blob/master/docs/overview.rst) @@ -72,35 +76,40 @@ ### Extract method -This refactoring works by triggering a CodeAction when selecting a block of -code. +This refactoring works by triggering CodeAction when selecting a block of code. ### Extract variable -This refactoring works by triggering a CodeAction when selecting a Python +This refactoring works by triggering CodeAction when selecting a Python expression. ### Inline -This refactoring works by triggering a CodeAction when the cursor is on a +This refactoring works by triggering CodeAction when the cursor is on a resolvable Python identifier. ### Use function -This works by triggering a CodeAction when the cursor is on the function name -of a `def` statement. +This refactoring works by triggering CodeAction when the cursor is on the +function name of a `def` statement. ### Method to method object -This works by triggering a CodeAction when the cursor is on the function name -of a `def` statement. +This refactoring works by triggering CodeAction when the cursor is on the +function name of a `def` statement. -## Caveat +### Convert local variable to field + +This refactoring works by triggering CodeAction when the cursor is on a local +variable. + +### Organize import -Support for working on unsaved document is currently incomplete. +This refactoring works by triggering CodeAction anywhere. + +## Caveat -Before you start refactoring you must save all unsaved changes in your text -editor. I highly recommended that you enable autosave on your text editor. +Support for working on unsaved document is currently experimental. This plugin is in early development, so expect some bugs. Please report in [Github issue tracker](https://github.com/python-lsp/python-lsp-server/issues) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/pylsp_rope.egg-info/SOURCES.txt new/pylsp-rope-0.1.7/pylsp_rope.egg-info/SOURCES.txt --- old/pylsp-rope-0.1.6/pylsp_rope.egg-info/SOURCES.txt 2021-10-12 04:16:42.000000000 +0200 +++ new/pylsp-rope-0.1.7/pylsp_rope.egg-info/SOURCES.txt 2021-11-05 08:10:35.000000000 +0100 @@ -24,7 +24,9 @@ test/helpers.py test/test_commands.py test/test_extract.py +test/test_import_utils.py test/test_inline.py +test/test_local_to_field.py test/test_lsp_diff.py test/test_method_to_method_object.py test/test_project.py @@ -32,8 +34,11 @@ test/fixtures/function.py test/fixtures/many_changes.py test/fixtures/many_changes_inlined.py +test/fixtures/method.py +test/fixtures/method_local_to_field.py test/fixtures/method_object.py test/fixtures/method_object_use_function.py +test/fixtures/redundant_import.py test/fixtures/simple.py test/fixtures/simple_extract_method.py test/fixtures/simple_extract_variable.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/pylsp_rope.egg-info/requires.txt new/pylsp-rope-0.1.7/pylsp_rope.egg-info/requires.txt --- old/pylsp-rope-0.1.6/pylsp_rope.egg-info/requires.txt 2021-10-12 04:16:42.000000000 +0200 +++ new/pylsp-rope-0.1.7/pylsp_rope.egg-info/requires.txt 2021-11-05 08:10:35.000000000 +0100 @@ -1,5 +1,5 @@ python-lsp-server -rope +rope>=0.21.0 [:python_version < "3.8"] typing-extensions diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/setup.cfg new/pylsp-rope-0.1.7/setup.cfg --- old/pylsp-rope-0.1.6/setup.cfg 2021-10-12 04:16:42.299155200 +0200 +++ new/pylsp-rope-0.1.7/setup.cfg 2021-11-05 08:10:35.458753300 +0100 @@ -1,6 +1,6 @@ [metadata] name = pylsp-rope -version = 0.1.6 +version = 0.1.7 author = Lie Ryan author_email = lie.1...@gmail.com url = https://github.com/python-rope/pylsp-rope @@ -21,7 +21,7 @@ packages = find: install_requires = python-lsp-server - rope + rope>=0.21.0 typing-extensions; python_version < '3.8' python_requires = >= 3.6 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/test/fixtures/method.py new/pylsp-rope-0.1.7/test/fixtures/method.py --- old/pylsp-rope-0.1.6/test/fixtures/method.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pylsp-rope-0.1.7/test/fixtures/method.py 2021-11-03 03:33:16.000000000 +0100 @@ -0,0 +1,8 @@ +import sys + + +class MyClass: + def my_method(self): + local_var = 10 + print(sys.stdin.read()) + print(local_var) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/test/fixtures/method_local_to_field.py new/pylsp-rope-0.1.7/test/fixtures/method_local_to_field.py --- old/pylsp-rope-0.1.6/test/fixtures/method_local_to_field.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pylsp-rope-0.1.7/test/fixtures/method_local_to_field.py 2021-11-03 03:33:12.000000000 +0100 @@ -0,0 +1,8 @@ +import sys + + +class MyClass: + def my_method(self): + self.local_var = 10 + print(sys.stdin.read()) + print(self.local_var) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/test/fixtures/redundant_import.py new/pylsp-rope-0.1.7/test/fixtures/redundant_import.py --- old/pylsp-rope-0.1.6/test/fixtures/redundant_import.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pylsp-rope-0.1.7/test/fixtures/redundant_import.py 2021-11-04 23:21:12.000000000 +0100 @@ -0,0 +1,7 @@ +import sys +import os.path +import sys + + +def main(): + print(sys.stdin.read()) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/test/test_import_utils.py new/pylsp-rope-0.1.7/test/test_import_utils.py --- old/pylsp-rope-0.1.6/test/test_import_utils.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pylsp-rope-0.1.7/test/test_import_utils.py 2021-11-04 23:23:52.000000000 +0100 @@ -0,0 +1,58 @@ +from pylsp_rope import commands, plugin, typing +from pylsp_rope.text import Range +from test.conftest import create_document +from test.helpers import ( + assert_text_edits, + assert_code_actions_do_not_offer, + assert_single_document_edit, +) + + +def test_organize_import(config, workspace, document, code_action_context): + document = create_document(workspace, "redundant_import.py") + line = 1 + start_col = 0 + end_col = 0 + selection = Range((line, start_col), (line, end_col)) + + response = plugin.pylsp_code_actions( + config=config, + workspace=workspace, + document=document, + range=selection, + context=code_action_context, + ) + + expected: typing.CodeAction = { + "title": "Organize import", + "kind": "source.organizeImports", + "command": { + "title": "Organize import", + "command": commands.COMMAND_SOURCE_ORGANIZE_IMPORT, + "arguments": [ + { + "document_uri": document.uri, + } + ], + }, + } + + assert expected in response + + assert expected["command"] is not None + command = expected["command"]["command"] + arguments = expected["command"]["arguments"] + + response = plugin.pylsp_execute_command( + config=config, + workspace=workspace, + command=command, + arguments=arguments, + ) + + edit_request = workspace._endpoint.request.call_args + + document_edits = assert_single_document_edit(edit_request, document) + new_text = assert_text_edits(document_edits, target="simple.py") + assert document.source.count('import sys') == 2 + assert new_text.count('import sys') == 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pylsp-rope-0.1.6/test/test_local_to_field.py new/pylsp-rope-0.1.7/test/test_local_to_field.py --- old/pylsp-rope-0.1.6/test/test_local_to_field.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pylsp-rope-0.1.7/test/test_local_to_field.py 2021-11-03 03:34:39.000000000 +0100 @@ -0,0 +1,79 @@ +from pylsp_rope import commands, plugin, typing +from pylsp_rope.text import Range +from test.conftest import create_document +from test.helpers import ( + assert_text_edits, + assert_code_actions_do_not_offer, + assert_single_document_edit, +) + + +def test_local_to_field(config, workspace, code_action_context): + document = create_document(workspace, "method.py") + line = 5 + start_col = end_col = document.lines[line].index("local_var") + selection = Range((line, start_col), (line, end_col)) + + response = plugin.pylsp_code_actions( + config=config, + workspace=workspace, + document=document, + range=selection, + context=code_action_context, + ) + + expected: typing.CodeAction = { + "title": "Convert local variable to field", + "kind": "refactor.rewrite", + "command": { + "title": "Convert local variable to field", + "command": commands.COMMAND_REFACTOR_LOCAL_TO_FIELD, + "arguments": [ + { + "document_uri": document.uri, + "position": selection["start"], + } + ], + }, + } + + assert expected in response + + assert expected["command"] is not None + command = expected["command"]["command"] + arguments = expected["command"]["arguments"] + + response = plugin.pylsp_execute_command( + config=config, + workspace=workspace, + command=command, + arguments=arguments, + ) + + edit_request = workspace._endpoint.request.call_args + + document_edits = assert_single_document_edit(edit_request, document) + new_text = assert_text_edits(document_edits, target="method_local_to_field.py") + assert "extracted_method" not in new_text + + +def test_local_to_field_not_offered_when_selecting_unsuitable_range( + config, workspace, code_action_context +): + document = create_document(workspace, "method.py") + line = 6 + start_col = end_col = document.lines[line].index("stdin") + selection = Range((line, start_col), (line, end_col)) + + response = plugin.pylsp_code_actions( + config=config, + workspace=workspace, + document=document, + range=selection, + context=code_action_context, + ) + + assert_code_actions_do_not_offer( + response, + command=commands.COMMAND_REFACTOR_INLINE, + )