Skip to content

Commit

Permalink
fix(inline): do not offer changeless inline refactor, backed by test
Browse files Browse the repository at this point in the history
  • Loading branch information
YotamAlon committed Oct 20, 2024
1 parent fae06c7 commit fa48473
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pylsp_rope/refactoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,14 @@ class CommandRefactorInline(Command):
position: typing.Range

def validate(self, info):
inline.create_inline(
refactoring = inline.create_inline(
project=self.project,
resource=info.resource,
offset=info.current_document.offset_at_position(info.position),
)
rope_changeset = refactoring.get_changes()
if not rope_changeset.changes:
raise Exception("Not offering changeless inline refactor")

def get_changes(self):
current_document, resource = get_resource(self.workspace, self.document_uri)
Expand Down
22 changes: 22 additions & 0 deletions test/test_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,25 @@ def test_inline_not_offered_when_selecting_unsuitable_range(
response,
command=commands.COMMAND_REFACTOR_INLINE,
)


def test_inline_not_offered_when_selecting_function_parameter(
config, workspace, code_action_context
):
document = create_document(workspace, "simple_extract_method.py")
line = 10
start_col = end_col = document.lines[line].index("a")
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,
)

0 comments on commit fa48473

Please sign in to comment.