Skip to content

impl inline refactor code actions#2033

Closed
asukaminato0721 wants to merge 3 commits intofacebook:mainfrom
asukaminato0721:364
Closed

impl inline refactor code actions#2033
asukaminato0721 wants to merge 3 commits intofacebook:mainfrom
asukaminato0721:364

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Jan 8, 2026

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.

@meta-cla meta-cla bot added the cla signed label Jan 8, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 8, 2026 03:33
Copilot AI review requested due to automatic review settings January 8, 2026 03:33
Copy link

Copilot AI left a 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.

@github-actions

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as draft January 8, 2026 04:10
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 8, 2026 05:29
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as draft January 15, 2026 04:54
fmt
@github-actions
Copy link

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 15, 2026 06:47
@meta-codesync
Copy link

meta-codesync bot commented Jan 16, 2026

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D90857430.

Copy link
Contributor

@yangdanny97 yangdanny97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync
Copy link

meta-codesync bot commented Jan 22, 2026

@kinto0 merged this pull request in 2c31c0f.

@asukaminato0721 asukaminato0721 deleted the 364 branch January 22, 2026 18:08
meta-codesync bot pushed a commit that referenced this pull request Feb 5, 2026
Summary:
enhancement for #2033

find that class method is missing support

Implemented class instance method inline support by adding an AST-based fallback when find_definition can’t resolve self.foo();

it now resolves to the method in the same enclosing class only when the receiver matches the enclosing method’s first parameter and the enclosing method isn’t `staticmethod`/`classmethod`.

Pull Request resolved: #2301

Test Plan: add test

Reviewed By: stroxler

Differential Revision: D92313955

Pulled By: kinto0

fbshipit-source-id: 50fecc3e30f39f9699494985cf61b934421ef287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants