fix(55946): Errant case causes crash in switch/case snippet completions (#55949)

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
Oleksandr T 2023-10-03 07:46:48 +03:00 committed by GitHub
parent c640c5de0a
commit f2805dc88b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3568 additions and 4 deletions

View File

@ -2824,7 +2824,7 @@ export function getCompletionEntryDetails(
return createSimpleDetails(completionNameForLiteral(sourceFile, preferences, literal), ScriptElementKind.string, typeof literal === "string" ? SymbolDisplayPartKind.stringLiteral : SymbolDisplayPartKind.numericLiteral);
}
case "cases": {
const { entry, importAdder } = getExhaustiveCaseSnippets(
const snippets = getExhaustiveCaseSnippets(
contextToken!.parent as CaseBlock,
sourceFile,
preferences,
@ -2832,8 +2832,10 @@ export function getCompletionEntryDetails(
host,
program,
/*formatContext*/ undefined,
)!;
if (importAdder.hasFixes()) {
);
if (snippets?.importAdder.hasFixes()) {
const { entry, importAdder } = snippets;
const changes = textChanges.ChangeTracker.with(
{ host, formatContext, preferences },
importAdder.writeFixes,
@ -2850,8 +2852,9 @@ export function getCompletionEntryDetails(
}],
};
}
return {
name: entry.name,
name,
kind: ScriptElementKind.unknown,
kindModifiers: "",
displayParts: [],

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
// @newline: LF
////switch (Math.random() ? 123 : 456) {
//// case "foo!":
//// case/**/
////}
verify.baselineCompletions({
includeCompletionsWithInsertText: true,
})