Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes #2178

Added match-pattern literal completions by detecting PatternMatchValue/PatternMatchSingleton at the cursor and using the match subject’s inferred type to surface Literal values.

Test Plan

A regression test for string literal matching.

@meta-cla meta-cla bot added the cla signed label Jan 22, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 22, 2026 09:52
Copilot AI review requested due to automatic review settings January 22, 2026 09:52
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 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_completions function 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.

@github-actions

This comment has been minimized.

@jvansch1 jvansch1 self-requested a review January 22, 2026 14:32
@jvansch1 jvansch1 self-assigned this Jan 22, 2026
@github-actions

This comment has been minimized.

@github-actions
Copy link

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

provide auto completion when match Literal

2 participants