Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ TestSignatureHelpCallExpressionJs
TestSpaceAfterReturn
TestStringCompletionsImportOrExportSpecifier
TestStringCompletionsVsEscaping
TestStringLiteralCompletionsWithinInferredObjectWhenItsKeysAreUsedOutsideOfIt
TestSuggestionOfUnusedVariableWithExternalModule
TestSymbolCompletionLowerPriority
TestSyntheticImportFromBabelGeneratedFile1
Expand All @@ -570,7 +569,6 @@ TestTsxQuickInfo5
TestTsxQuickInfo6
TestTsxQuickInfo7
TestTypeCheckAfterResolve
TestTypeErrorAfterStringCompletionsInNestedCall
TestTypeOperatorNodeBuilding
TestUnclosedStringLiteralAutoformating
TestWhiteSpaceTrimming
Expand Down
1 change: 1 addition & 0 deletions internal/fourslash/_scripts/manualTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ stringLiteralCompletionsInPositionTypedUsingRest
tripleSlashRefPathCompletionAbsolutePaths
tripleSlashRefPathCompletionHiddenFile
tsxCompletion12
typeErrorAfterStringCompletionsInNestedCall
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func TestTypeErrorAfterStringCompletionsInNestedCall(t *testing.T) {
fourslash.SkipIfFailing(t)
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @stableTypeOrdering: true
Expand Down Expand Up @@ -49,8 +48,8 @@ createMachine<GreetingEvent>({
},
Items: &fourslash.CompletionsExpectedItems{
Exact: []fourslash.CompletionsExpectedItem{
"ALOHAx",
"ALOHA",
"ALOHAx",
"LUNCH_TIME",
"MORNING",
},
Expand Down
27 changes: 21 additions & 6 deletions internal/ls/string_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ func (l *LanguageService) getStringLiteralCompletionEntries(
fromProperties: stringLiteralCompletionsForObjectLiteral(typeChecker, parent.Parent),
}
}
result := fromContextualType(checker.ContextFlagsCompletions, node, typeChecker)
if result != nil {
return &stringLiteralCompletions{
fromTypes: result,
}
if ast.FindAncestor(parent.Parent, ast.IsCallLikeExpression) != nil {
uniques := &collections.Set[string]{}
stringLiteralTypes := append(
getStringLiteralTypes(typeChecker.GetContextualType(node, checker.ContextFlagsNone), uniques, typeChecker),
getStringLiteralTypes(typeChecker.GetContextualType(node, checker.ContextFlagsCompletions), uniques, typeChecker)...,
)
return toStringLiteralCompletionsFromTypes(stringLiteralTypes)
}
return &stringLiteralCompletions{
fromTypes: fromContextualType(checker.ContextFlagsNone, node, typeChecker),
Expand Down Expand Up @@ -421,7 +423,10 @@ func (l *LanguageService) getStringLiteralCompletionEntries(
func fromContextualType(contextFlags checker.ContextFlags, node *ast.Node, typeChecker *checker.Checker) *completionsFromTypes {
// Get completion for string literal from string literal type
// i.e. var x: "hi" | "hello" = "/*completion position*/"
types := getStringLiteralTypes(getContextualTypeFromParent(node, typeChecker, contextFlags), nil, typeChecker)
return toCompletionsFromTypes(getStringLiteralTypes(getContextualTypeFromParent(node, typeChecker, contextFlags), nil, typeChecker))
}

func toCompletionsFromTypes(types []*checker.StringLiteralType) *completionsFromTypes {
if len(types) == 0 {
return nil
}
Expand All @@ -431,6 +436,16 @@ func fromContextualType(contextFlags checker.ContextFlags, node *ast.Node, typeC
}
}

func toStringLiteralCompletionsFromTypes(types []*checker.StringLiteralType) *stringLiteralCompletions {
result := toCompletionsFromTypes(types)
if result == nil {
return nil
}
return &stringLiteralCompletions{
fromTypes: result,
}
}

func fromUnionableLiteralType(
grandparent *ast.Node,
parent *ast.Node,
Expand Down
Loading