Skip to content

fix quick fix for Enum #3266#3271

Open
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:3266
Open

fix quick fix for Enum #3266#3271
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:3266

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

@asukaminato0721 asukaminato0721 commented Apr 30, 2026

Summary

Fixes #3266

Added an enum-member quick fix that turns the existing diagnostic note Did you mean AccountStatus.ACTIVE? into a code action replacing the enclosing string literal, e.g. "active" -> AccountStatus.ACTIVE.

Test Plan

add test

@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. ✅

@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 30, 2026 12:09
Copilot AI review requested due to automatic review settings April 30, 2026 12:09
Copy link
Copy Markdown

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

Adds an LSP quick fix to replace a string literal argument with the suggested enum member when the type checker emits an enum-member “Did you mean …?” hint (fixing #3266).

Changes:

  • Introduce enum_member quick fix that parses enum-member suggestions from diagnostic details and replaces the enclosing string literal with the enum member reference.
  • Wire the new quick fix into local_quickfix_code_actions_sorted.
  • Add an LSP code-actions test covering the new quick fix.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pyrefly/lib/test/lsp/code_actions.rs Adds a regression test for the new enum-member replacement quick fix.
pyrefly/lib/state/lsp/quick_fixes/mod.rs Exposes the new enum_member quick-fix module.
pyrefly/lib/state/lsp/quick_fixes/enum_member.rs Implements the “Replace with Enum.Member” code action by extracting a suggestion from diagnostic details and locating the string literal range.
pyrefly/lib/state/lsp.rs Hooks the new enum-member quick fix into the LSP quick-fix action generation pipeline.

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

"{report}"
);
assert!(
report.contains("takes_status(AccountStatus.ACTIVE)"),
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This test only asserts that the report contains substrings, which can allow false positives (e.g., if multiple code actions are produced or the Before/After block format changes). Consider asserting the full expected report (as other tests in this file do) or at least asserting the relevant Before/After block boundaries and the exact transformed line, to make the test more robust and regression-resistant.

Suggested change
report.contains("takes_status(AccountStatus.ACTIVE)"),
report.contains(
r#"Before:
takes_status("active")
After:
takes_status(AccountStatus.ACTIVE)"#
),

Copilot uses AI. Check for mistakes.
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.

quick fix for Enum

2 participants