Skip to content

Commit e8a0920

Browse files
authored
Fix porting bug in tsx completions (#1676)
1 parent 4a5c3e2 commit e8a0920

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ TestCompletionsJSDocImportTagAttributesErrorModuleSpecifier1
129129
TestCompletionsJSDocImportTagEmptyModuleSpecifier1
130130
TestCompletionsJSDocNoCrash1
131131
TestCompletionsJsdocTypeTagCast
132-
TestCompletionsJsxAttribute2
133132
TestCompletionsJsxAttributeInitializer2
134133
TestCompletionsLiteralFromInferenceWithinInferredType3
135134
TestCompletionsLiterals
@@ -458,11 +457,8 @@ TestTripleSlashRefPathCompletionExtensionsAllowJSTrue
458457
TestTripleSlashRefPathCompletionHiddenFile
459458
TestTripleSlashRefPathCompletionRootdirs
460459
TestTslibFindAllReferencesOnRuntimeImportWithPaths1
461-
TestTsxCompletion12
462-
TestTsxCompletion13
463460
TestTsxCompletion14
464461
TestTsxCompletion15
465-
TestTsxCompletion8
466462
TestTsxCompletionNonTagLessThan
467463
TestTsxQuickInfo1
468464
TestTsxQuickInfo4

internal/fourslash/_scripts/manualTests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ completionListInClosedFunction05
22
completionsAtIncompleteObjectLiteralProperty
33
completionsSelfDeclaring1
44
completionsWithDeprecatedTag4
5+
tsxCompletion12

internal/fourslash/tests/gen/completionsJsxAttribute2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestCompletionsJsxAttribute2(t *testing.T) {
1212
t.Parallel()
13-
t.Skip()
13+
1414
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1515
const content = `// @jsx: preserve
1616
// @Filename: /a.tsx

internal/fourslash/tests/gen/tsxCompletion13_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestTsxCompletion13(t *testing.T) {
1414
t.Parallel()
15-
t.Skip()
15+
1616
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1717
const content = `//@Filename: file.tsx
1818
// @jsx: preserve

internal/fourslash/tests/gen/tsxCompletion8_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestTsxCompletion8(t *testing.T) {
1212
t.Parallel()
13-
t.Skip()
13+
1414
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1515
const content = `//@Filename: file.tsx
1616
declare module JSX {

internal/fourslash/tests/gen/tsxCompletion12_test.go renamed to internal/fourslash/tests/manual/tsxCompletion12_test.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestTsxCompletion12(t *testing.T) {
1414
t.Parallel()
15-
t.Skip()
15+
1616
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1717
const content = `//@Filename: file.tsx
1818
// @jsx: preserve
@@ -30,12 +30,12 @@ func TestTsxCompletion12(t *testing.T) {
3030
}
3131
declare function Opt(attributes: OptionPropBag): JSX.Element;
3232
let opt = <Opt /*1*/ />;
33-
let opt1 = <Opt prop/*2*/ />;
33+
let opt1 = <Opt [|prop|]/*2*/ />;
3434
let opt2 = <Opt propx={100} /*3*/ />;
3535
let opt3 = <Opt propx={100} optional /*4*/ />;
3636
let opt4 = <Opt wrong /*5*/ />;`
3737
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
38-
f.VerifyCompletions(t, []string{"1", "2", "5"}, &fourslash.CompletionsExpectedList{
38+
f.VerifyCompletions(t, []string{"1", "5"}, &fourslash.CompletionsExpectedList{
3939
IsIncomplete: false,
4040
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
4141
CommitCharacters: &DefaultCommitCharacters,
@@ -55,6 +55,32 @@ func TestTsxCompletion12(t *testing.T) {
5555
},
5656
},
5757
})
58+
f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{
59+
IsIncomplete: false,
60+
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
61+
CommitCharacters: &DefaultCommitCharacters,
62+
EditRange: Ignored,
63+
},
64+
Items: &fourslash.CompletionsExpectedItems{
65+
Exact: []fourslash.CompletionsExpectedItem{
66+
"propString",
67+
"propx",
68+
&lsproto.CompletionItem{
69+
Label: "optional?",
70+
FilterText: PtrTo("optional"),
71+
Kind: PtrTo(lsproto.CompletionItemKindField),
72+
SortText: PtrTo(string(ls.SortTextOptionalMember)),
73+
TextEdit: &lsproto.TextEditOrInsertReplaceEdit{
74+
InsertReplaceEdit: &lsproto.InsertReplaceEdit{
75+
NewText: "optional",
76+
Insert: f.Ranges()[0].LSRange,
77+
Replace: f.Ranges()[0].LSRange,
78+
},
79+
},
80+
},
81+
},
82+
},
83+
})
5884
f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{
5985
IsIncomplete: false,
6086
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{

internal/ls/completions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,6 +4255,12 @@ func tryGetContainingJsxElement(contextToken *ast.Node, file *ast.SourceFile) *a
42554255
}
42564256
}
42574257
return parent
4258+
} else if parent != nil && parent.Kind == ast.KindJsxAttribute {
4259+
// Currently we parse JsxOpeningLikeElement as:
4260+
// JsxOpeningLikeElement
4261+
// attributes: JsxAttributes
4262+
// properties: NodeArray<JsxAttributeLike>
4263+
return parent.Parent.Parent
42584264
}
42594265
// The context token is the closing } or " of an attribute, which means
42604266
// its parent is a JsxExpression, whose parent is a JsxAttribute,

0 commit comments

Comments
 (0)