-
Notifications
You must be signed in to change notification settings - Fork 239
impl inline refactor code actions #2033
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request implements three inline refactoring code actions for Python: inline variable, inline method (call-site only), and inline parameter. The implementation includes comprehensive safety checks to ensure conservative refactoring operations.
Key Changes
- Added inline variable refactoring that replaces all references with the assigned value and removes the assignment
- Added inline method refactoring that replaces a single call site with the method body (preserving the method definition)
- Added inline parameter refactoring that requires exactly one call site, removes the parameter, and inlines the argument value
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pyrefly/lib/test/lsp/code_actions.rs | Added test helpers and unit tests for the three new inline refactoring actions |
| pyrefly/lib/state/lsp/quick_fixes/mod.rs | Added module declarations for the three new inline refactoring implementations |
| pyrefly/lib/state/lsp/quick_fixes/inline_variable.rs | Implemented inline variable with safety checks for recursion, nested scopes, and disallowed expressions |
| pyrefly/lib/state/lsp/quick_fixes/inline_parameter.rs | Implemented inline parameter with single call site requirement and parameter usage validation |
| pyrefly/lib/state/lsp/quick_fixes/inline_method.rs | Implemented inline method for single call sites with parameter mapping and substitution |
| pyrefly/lib/state/lsp.rs | Added public API methods to expose the three inline code actions to the LSP layer |
| pyrefly/lib/lsp/non_wasm/server.rs | Registered REFACTOR_INLINE capability and wired the three actions into the code action pipeline |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Summary
Fixes part of #364
Added conservative inline refactor code actions (variable, call‑site method, and parameter) with safety checks, wired them into LSP capabilities and the code‑action pipeline.
Inline method replaces the selected call only (doesn’t delete the definition). Inline parameter requires a single local call site and removes the parameter + argument.
https://www.jetbrains.com/help/pycharm/inline.html#inline-variable-python
Test Plan
added focused unit tests in the LSP code‑actions suite.