Add Extract function refactoring to the editor context menu - #26254
Open
alanloko wants to merge 3 commits into
Open
Add Extract function refactoring to the editor context menu#26254alanloko wants to merge 3 commits into
alanloko wants to merge 3 commits into
Conversation
Selecting a block of code and choosing Extract function in the editor's context menu extracts it into a new function using rope, which detects the block's input/output variables to build the new function's signature and return value. The replacement is applied as a single undoable edit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
This PR adds an Extract function refactoring action to the editor's context menu (in the same section as Generate docstring and Format file or selection).
How it works:
The selected block is replaced by a call to the new function, and the function is created after the current scope. The refactoring is powered by rope (already available as a dependency through
python-lsp-server[all]), which analyzes the block's input/output variables to build the correct signature and return value.Implementation notes:
clear_all_output), so Ctrl+Z reverts it in one step.Included in this PR:
test_extract_function.pycovering: successful extraction (signature/return detection), single-step undo, no selection, invalid function name, cancelled dialog, and invalid (mid-statement) selections. Existingtest_codeeditor.pyandtest_editing.pysuites still pass locally.changelogs/Spyder-6.md.Issue(s) Resolved
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: alanloko