-
Notifications
You must be signed in to change notification settings - Fork 13k
Prioritize case
and default
keywords in switch statement completions
#62126
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?
Changes from 2 commits
d1d0418
963e167
1695532
7f7a30e
c8b6d8c
75fcd1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// declare const thing: string; | ||
|
||
//// // Basic switch block - should prioritize case/default | ||
//// switch (thing) { | ||
//// /*basic*/ | ||
//// } | ||
|
||
//// // Same - show all completions (not at switch body level) | ||
//// switch (thing) { | ||
//// case 42: | ||
//// /*sameAll1*/ | ||
//// } | ||
|
||
//// // Same - show all completions (after break at same column as case) | ||
//// switch (thing) { | ||
//// case 42: | ||
//// break; | ||
//// /*sameAll2*/ | ||
//// } | ||
|
||
//// // Same - show all completions (complex nested structure) | ||
//// switch (thing) { | ||
//// case 42: | ||
//// if (Math.random()) { | ||
//// } | ||
//// else { | ||
//// } | ||
//// /*sameAll3*/ | ||
//// } | ||
|
||
//// // NEW - prioritize case/default (after break on different column) | ||
//// switch (thing) { | ||
//// case 42: | ||
//// break; | ||
//// /*newPrio1*/ | ||
//// } | ||
|
||
//// // NEW - prioritize case/default (break on same line) | ||
//// switch (thing) { | ||
//// case 42: break; | ||
//// /*newPrio2*/ | ||
//// } | ||
|
||
//// // NEW - prioritize case/default (after return) | ||
//// switch (thing) { | ||
//// case 42: | ||
//// return 1; | ||
//// /*newPrio3*/ | ||
//// } | ||
|
||
//// // NEW - prioritize case/default (after throw) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove these NEW labels, don't claim what to expect. Instead, describe the positioning of these. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed all "NEW" labels and improved the descriptions to focus on positioning rather than claiming expectations. Comments now describe the context (e.g., "After break statement with proper indentation") instead of predicting behavior. Fixed in 7f7a30e. |
||
//// switch (thing) { | ||
//// case 42: | ||
//// throw new Error(); | ||
//// /*newPrio4*/ | ||
//// } | ||
|
||
verify.completions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch this to baselining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched to baseline testing approach using verify.baselineCompletions() for all markers instead of explicit verify.completions() assertions. The baseline now clearly shows case/default prioritization (sortText "10") in appropriate contexts and normal ordering (sortText "15") elsewhere. Fixed in 7f7a30e. |
||
{ | ||
marker: "basic", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.LocalDeclarationPriority }, | ||
{ name: "default", sortText: completion.SortText.LocalDeclarationPriority } | ||
] | ||
}, | ||
{ | ||
marker: "sameAll1", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.GlobalsOrKeywords }, | ||
{ name: "default", sortText: completion.SortText.GlobalsOrKeywords } | ||
] | ||
}, | ||
{ | ||
marker: "sameAll2", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.GlobalsOrKeywords }, | ||
{ name: "default", sortText: completion.SortText.GlobalsOrKeywords } | ||
] | ||
}, | ||
{ | ||
marker: "sameAll3", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.GlobalsOrKeywords }, | ||
{ name: "default", sortText: completion.SortText.GlobalsOrKeywords } | ||
] | ||
}, | ||
{ | ||
marker: "newPrio1", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.LocalDeclarationPriority }, | ||
{ name: "default", sortText: completion.SortText.LocalDeclarationPriority } | ||
] | ||
}, | ||
{ | ||
marker: "newPrio2", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.LocalDeclarationPriority }, | ||
{ name: "default", sortText: completion.SortText.LocalDeclarationPriority } | ||
] | ||
}, | ||
{ | ||
marker: "newPrio3", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.LocalDeclarationPriority }, | ||
{ name: "default", sortText: completion.SortText.LocalDeclarationPriority } | ||
] | ||
}, | ||
{ | ||
marker: "newPrio4", | ||
isNewIdentifierLocation: false, | ||
includes: [ | ||
{ name: "case", sortText: completion.SortText.LocalDeclarationPriority }, | ||
{ name: "default", sortText: completion.SortText.LocalDeclarationPriority } | ||
] | ||
} | ||
); |
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.
The diff is huge, so maybe this needs to run with
noLib
or some similar thing to trim down the full completion list.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.
Added
@noLib: true
and switched from baseline testing to targetedverify.completions()
assertions. This reduced the test from 256k+ lines to a focused test that validates the specific sortText values ("10" for prioritized, "15" for normal) without the massive global completion list. Fixed in c8b6d8c.