Skip to content

fix Autocomplete parameters of class pattern in match-case situation #2830 - #2848

Open
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:2830
Open

asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:2830

Conversation

@asukaminato0721

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2830

adds class-pattern keyword completions from the matched class’s instance attributes, so case A(...): now suggests a= / b= for dataclass fields.

Test Plan

add test

@meta-cla meta-cla Bot added the cla signed label Mar 22, 2026
@asukaminato0721
asukaminato0721 marked this pull request as ready for review March 22, 2026 00:28
Copilot AI review requested due to automatic review settings March 22, 2026 00:28

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

Fixes LSP completion behavior for Python match/case class patterns by suggesting keyword names derived from the matched class’s instance attributes (e.g. dataclass fields in case A(...)).

Changes:

  • Add completion logic to suggest attr= items when completing inside case <Class>(...).
  • Wire the new completion logic into the main completion flow (pattern-match keyword context + generic non-identifier context).
  • Add a regression test ensuring dataclass fields (a=, b=) are suggested in case A( ).

Reviewed changes

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

File Description
pyrefly/lib/lsp/wasm/completion.rs Adds match-class keyword completion generation and hooks it into completion dispatch.
pyrefly/lib/test/lsp/completion.rs Adds a regression test covering dataclass-field keyword completions in class patterns.

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

Comment thread pyrefly/lib/lsp/wasm/completion.rs Outdated
.map(|attr| {
RankedCompletion::new(CompletionItem {
label: format!("{}=", attr.name.as_str()),
detail: attr.ty.map(|ty| ty.to_string()),

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

The completion detail here uses Type::to_string(), while other completion paths in this file format types with as_lsp_string(LspDisplayMode::Hover) for consistency and readability. Consider using the same formatting helper so match-class keyword completions display types consistently with attribute completions.

Suggested change
detail: attr.ty.map(|ty| ty.to_string()),
detail: attr
.ty
.map(|ty| ty.as_lsp_string(LspDisplayMode::Hover)),

Copilot uses AI. Check for mistakes.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/m and removed size/m labels Mar 28, 2026
@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.

@meta-codesync

meta-codesync Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115175141. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

This comment has been minimized.

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

This branch has not been deployed

No deployments
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.

Autocomplete parameters of class pattern in match-case situation

3 participants