Skip to content

fix remove or downgrade the already appear branch in match case #3015#3179

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

fix remove or downgrade the already appear branch in match case #3015#3179
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:3015

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

@asukaminato0721 asukaminato0721 commented Apr 19, 2026

Summary

Fixes #3015

now detect when attribute completion is happening inside a match value pattern, collect enum members already covered by earlier case arms, and demote those members in the completion ranking.

The ranking hook is wired and applied in the attribute-completion path.

Test Plan

add test

@meta-cla meta-cla Bot added the cla signed label Apr 19, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 19, 2026 13:56
Copilot AI review requested due to automatic review settings April 19, 2026 13:56
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

Improves LSP attribute completion ranking inside Python match value patterns by demoting enum members that were already used in earlier case arms (fixes #3015).

Changes:

  • Add a new is_deprioritized ranking flag and incorporate it into sort_text generation.
  • Detect match value-pattern attribute completion, collect previously-matched enum members, and mark corresponding completions as deprioritized.
  • Add a regression test for the new ranking behavior in match cases.

Reviewed changes

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

File Description
pyrefly/lib/lsp/wasm/completion.rs Adds deprioritization support to completion ranking and wires match-case enum-member demotion into the attribute-completion path.
pyrefly/lib/test/lsp/completion.rs Adds a regression test intended to verify that already-matched enum members are ranked lower during completion.

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

Comment on lines +1421 to +1447
let report = get_batched_lsp_operations_report_allow_error(
&[("main", code)],
|state, handle, position| {
let mut report = String::new();
for item in state
.transaction()
.completion(handle, position, ImportFormat::Absolute, true, None)
.into_iter()
.filter(|item| matches!(item.label.as_str(), "AA" | "BB"))
{
report.push_str(&item.label);
report.push('\n');
}
report
},
);

let bb_index = report.find("BB\n");
let aa_index = report.find("AA\n");
assert!(
bb_index.is_some() && aa_index.is_some(),
"Expected completions for AA and BB."
);
assert!(
bb_index.unwrap() < aa_index.unwrap(),
"Expected the unmatched enum member to sort first."
);
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

This test’s ordering assertion is unreliable because get_batched_lsp_operations_report_allow_error prepends a code frame and the source itself contains AA/BB (e.g. BB = auto() and case A.AA:). As a result, report.find("BB\n") / report.find("AA\n") can match the code frame rather than the completion output, making the test pass even if completion ranking is wrong. Consider asserting against the full expected report (like other tests in this file), or add an unambiguous sentinel header in the closure output and restrict the search to that section before comparing ordering.

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

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.

remove or downgrade the already appear branch in match case

3 participants