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
54 changes: 54 additions & 0 deletions tsc/internal/fourslash/tests/completionsInEmptyTupleType_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/TypeScript/tsc/internal/fourslash"
. "github.com/microsoft/TypeScript/tsc/internal/fourslash/tests/util"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)

func TestCompletionsInEmptyTupleType(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `type UserTuple = [["name", string], ["age", number], ["address", string]];
type AdminTuple = [/*1*/];
type OtherTuple = [string, /*2*/];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might also want to test type QueryTuple = [typeof /*3*/];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

type QueryTuple = [typeof /*3*/];

const User: UserTuple = [["name", "2333"], ["age", 2333], ["address", "2333"]];`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyCompletions(t, []string{"1", "2"}, &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
"UserTuple",
},
Excludes: []string{
"User",
},
},
})

// After `typeof` in a tuple type we are back in a value location, so type-only symbols shouldn't be offered.
f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
"User",
},
Excludes: []string{
"UserTuple",
},
},
})
}
2 changes: 2 additions & 0 deletions tsc/internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,8 @@ func isContextTokenTypeLocation(contextToken *ast.Node) bool {
return parentKind == ast.KindTypeParameter
case ast.KindSatisfiesKeyword:
return parentKind == ast.KindSatisfiesExpression
case ast.KindOpenBracketToken, ast.KindCommaToken:
return parentKind == ast.KindTupleType
}
}
return false
Expand Down