-
Notifications
You must be signed in to change notification settings - Fork 259
fix provide auto completion when match Literal #2178 #2191
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 PR adds auto-completion support for literal values in Python match statements. When typing a case pattern for a variable with a Literal type annotation, the LSP now suggests the possible literal values.
Changes:
- Added
add_match_literal_completionsfunction to detect match patterns and provide completions based on the subject's type - Integrated the new completion function into the existing completion flow
- Added a regression test for string literal matching
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/state/lsp.rs |
Added add_match_literal_completions method that detects PatternMatchValue and PatternMatchSingleton nodes, retrieves the match subject's type, and provides literal completions |
pyrefly/lib/test/lsp/completion.rs |
Added test case completion_literal_match_value to verify literal completions work correctly in match statements |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
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 #2178
Added match-pattern literal completions by detecting
PatternMatchValue/PatternMatchSingletonat the cursor and using the match subject’s inferred type to surface Literal values.Test Plan
A regression test for string literal matching.