Skip to content

Commit 2b62689

Browse files
authored
Merge pull request #30 from YotamAlon/do-not-offer-changeless-inline-refactor
fix(inline): do not offer changeless inline refactor, backed by test
2 parents fae06c7 + fa48473 commit 2b62689

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

pylsp_rope/refactoring.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,14 @@ class CommandRefactorInline(Command):
221221
position: typing.Range
222222

223223
def validate(self, info):
224-
inline.create_inline(
224+
refactoring = inline.create_inline(
225225
project=self.project,
226226
resource=info.resource,
227227
offset=info.current_document.offset_at_position(info.position),
228228
)
229+
rope_changeset = refactoring.get_changes()
230+
if not rope_changeset.changes:
231+
raise Exception("Not offering changeless inline refactor")
229232

230233
def get_changes(self):
231234
current_document, resource = get_resource(self.workspace, self.document_uri)

test/test_inline.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,25 @@ def test_inline_not_offered_when_selecting_unsuitable_range(
7777
response,
7878
command=commands.COMMAND_REFACTOR_INLINE,
7979
)
80+
81+
82+
def test_inline_not_offered_when_selecting_function_parameter(
83+
config, workspace, code_action_context
84+
):
85+
document = create_document(workspace, "simple_extract_method.py")
86+
line = 10
87+
start_col = end_col = document.lines[line].index("a")
88+
selection = Range((line, start_col), (line, end_col))
89+
90+
response = plugin.pylsp_code_actions(
91+
config=config,
92+
workspace=workspace,
93+
document=document,
94+
range=selection,
95+
context=code_action_context,
96+
)
97+
98+
assert_code_actions_do_not_offer(
99+
response,
100+
command=commands.COMMAND_REFACTOR_INLINE,
101+
)

0 commit comments

Comments
 (0)