Skip to content

fix impl unwrap block #2207#3115

Open
asukaminato0721 wants to merge 5 commits into
facebook:mainfrom
asukaminato0721:24552-ty
Open

fix impl unwrap block #2207#3115
asukaminato0721 wants to merge 5 commits into
facebook:mainfrom
asukaminato0721:24552-ty

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Summary

part of #2207

impl unwrap block

astral-sh/ruff#24552

Test Plan

add test

@meta-cla meta-cla Bot added the cla signed label Apr 12, 2026
@asukaminato0721 asukaminato0721 changed the title fix impl unwrap scope #2207 Apr 12, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 12, 2026 17:51
Copilot AI review requested due to automatic review settings April 12, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an “Unwrap block” refactor code action to the Pyrefly LSP, enabling users to remove an enclosing block statement (e.g., if, else, for/while without else, with) and reindent the block body into the parent scope.

Changes:

  • Implemented unwrap_block quick-fix/refactor logic, including AST traversal and text edit construction.
  • Wired the new refactor into Transaction and the non-wasm LSP server’s code-action collection.
  • Added initial LSP code-action tests for unwrap-block (basic if, else, and loop-else rejection).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyrefly/lib/test/lsp/code_actions.rs Adds unwrap-block helpers and a few targeted tests.
pyrefly/lib/state/lsp/quick_fixes/unwrap_block.rs New unwrap-block refactor implementation (target detection + edit generation).
pyrefly/lib/state/lsp/quick_fixes/mod.rs Exposes the new unwrap_block module.
pyrefly/lib/state/lsp.rs Adds Transaction::unwrap_block_code_actions API entrypoint.
pyrefly/lib/lsp/non_wasm/server.rs Includes unwrap-block in refactor code-action computation/telemetry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyrefly/lib/state/lsp/quick_fixes/unwrap_block.rs Outdated
Comment thread pyrefly/lib/test/lsp/code_actions.rs
@github-actions

This comment has been minimized.

@connernilsen connernilsen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @asukaminato0721, this is looking good, but a few things (mostly requests for more tests). Let me know if you have questions

Comment thread pyrefly/lib/test/lsp/code_actions.rs
Comment thread pyrefly/lib/state/lsp/quick_fixes/unwrap_block.rs
Comment thread pyrefly/lib/test/lsp/code_actions.rs
Comment thread pyrefly/lib/state/lsp/quick_fixes/unwrap_block.rs Outdated
@github-actions

This comment has been minimized.

@connernilsen connernilsen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few more things I found

Comment thread pyrefly/lib/state/lsp/quick_fixes/unwrap_block.rs Outdated
Comment thread pyrefly/lib/state/lsp/quick_fixes/unwrap_block.rs Outdated
Comment thread pyrefly/lib/state/lsp/quick_fixes/unwrap_block.rs
Comment thread pyrefly/lib/test/lsp/code_actions.rs
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

asukaminato0721 and others added 4 commits May 20, 2026 04:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/xl and removed size/xl labels May 22, 2026
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants