Skip to content

Fix Global and Module MoveRefactoring #1141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion doc/pymode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,31 @@ code to call it instead.
let g:pymode_rope_use_function_bind = '<C-c>ru'


Move method/fields ~
Move refactoring ~
*pymode-rope-move*

Moving method/fields

It happens when you perform move refactoring on a method of a class. In this
refactoring, a method of a class is moved to the class of one of its
attributes. The old method will call the new method. If you want to change all
of the occurrences of the old method to use the new method you can inline it
afterwards.

Moving global variable/class/function into another module

It happens when you perform move refactoring on global variable/class/function.
In this refactoring, the object being refactored will be moved to a destination
module. All references to the object being moved will be updated to point to
the new location.

Moving module variable/class/function into a package

It happens when you perform move refactoring on a name referencing a module.
In this refactoring, the module being refactored will be moved to a destination
package. All references to the object being moved will be updated to point to
the new location.

>
let g:pymode_rope_move_bind = '<C-c>rv'

Expand Down
9 changes: 9 additions & 0 deletions pymode/rope.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,15 @@ def get_refactor(ctx):
offset = None
return move.create_move(ctx.project, ctx.resource, offset)

@staticmethod
def get_changes(refactor, input_str, in_hierarchy=False):
with RopeContext() as ctx:
if isinstance(refactor, (move.MoveGlobal, move.MoveModule)):
dest = ctx.project.pycore.find_module(input_str)
else:
dest = input_str
return super(MoveRefactoring, MoveRefactoring).get_changes(refactor, dest, in_hierarchy=in_hierarchy)


class ChangeSignatureRefactoring(Refactoring):

Expand Down