fix quick fix for Enum #3266#3271
Conversation
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
There was a problem hiding this comment.
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_memberquick 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)"), |
There was a problem hiding this comment.
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.
| report.contains("takes_status(AccountStatus.ACTIVE)"), | |
| report.contains( | |
| r#"Before: | |
| takes_status("active") | |
| After: | |
| takes_status(AccountStatus.ACTIVE)"# | |
| ), |
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