-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite logic for JSX attribute completion detection
- Loading branch information
1 parent
14f33d5
commit d14d8ff
Showing
7 changed files
with
367 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
tests/cases/fourslash/jsxAttributeSnippetCompletionClosed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/// <reference path="fourslash.ts" /> | ||
//@Filename: file.tsx | ||
////interface NestedInterface { | ||
//// Foo: NestedInterface; | ||
//// (props: {className?: string}): any; | ||
////} | ||
//// | ||
////declare const Foo: NestedInterface; | ||
//// | ||
////function fn1() { | ||
//// return <Foo> | ||
//// <Foo /*1*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn2() { | ||
//// return <Foo> | ||
//// <Foo.Foo /*2*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn3() { | ||
//// return <Foo> | ||
//// <Foo.Foo cla/*3*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn4() { | ||
//// return <Foo> | ||
//// <Foo.Foo cla/*4*/ something /> | ||
//// </Foo> | ||
////} | ||
////function fn5() { | ||
//// return <Foo> | ||
//// <Foo.Foo something /*5*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn6() { | ||
//// return <Foo> | ||
//// <Foo.Foo something cla/*6*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn7() { | ||
//// return <Foo /*7*/ /> | ||
////} | ||
////function fn8() { | ||
//// return <Foo cla/*8*/ /> | ||
////} | ||
////function fn9() { | ||
//// return <Foo cla/*9*/ something /> | ||
////} | ||
////function fn10() { | ||
//// return <Foo something /*10*/ /> | ||
////} | ||
////function fn11() { | ||
//// return <Foo something cla/*11*/ /> | ||
////} | ||
|
||
var preferences: FourSlashInterface.UserPreferences = { | ||
jsxAttributeCompletionStyle: "braces", | ||
includeCompletionsWithSnippetText: true, | ||
includeCompletionsWithInsertText: true, | ||
}; | ||
|
||
verify.completions( | ||
{ marker: "1", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "2", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "3", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "4", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "5", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "6", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "7", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "8", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "9", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "10", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "11", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
) |
74 changes: 74 additions & 0 deletions
74
tests/cases/fourslash/jsxAttributeSnippetCompletionUnclosed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/// <reference path="fourslash.ts" /> | ||
//@Filename: file.tsx | ||
////interface NestedInterface { | ||
//// Foo: NestedInterface; | ||
//// (props: {className?: string}): any; | ||
////} | ||
//// | ||
////declare const Foo: NestedInterface; | ||
//// | ||
////function fn1() { | ||
//// return <Foo> | ||
//// <Foo /*1*/ | ||
//// </Foo> | ||
////} | ||
////function fn2() { | ||
//// return <Foo> | ||
//// <Foo.Foo /*2*/ | ||
//// </Foo> | ||
////} | ||
////function fn3() { | ||
//// return <Foo> | ||
//// <Foo.Foo cla/*3*/ | ||
//// </Foo> | ||
////} | ||
////function fn4() { | ||
//// return <Foo> | ||
//// <Foo.Foo cla/*4*/ something | ||
//// </Foo> | ||
////} | ||
////function fn5() { | ||
//// return <Foo> | ||
//// <Foo.Foo something /*5*/ | ||
//// </Foo> | ||
////} | ||
////function fn6() { | ||
//// return <Foo> | ||
//// <Foo.Foo something cla/*6*/ | ||
//// </Foo> | ||
////} | ||
////function fn7() { | ||
//// return <Foo /*7*/ | ||
////} | ||
////function fn8() { | ||
//// return <Foo cla/*8*/ | ||
////} | ||
////function fn9() { | ||
//// return <Foo cla/*9*/ something | ||
////} | ||
////function fn10() { | ||
//// return <Foo something /*10*/ | ||
////} | ||
////function fn11() { | ||
//// return <Foo something cla/*11*/ | ||
////} | ||
|
||
var preferences: FourSlashInterface.UserPreferences = { | ||
jsxAttributeCompletionStyle: "braces", | ||
includeCompletionsWithSnippetText: true, | ||
includeCompletionsWithInsertText: true, | ||
}; | ||
|
||
verify.completions( | ||
{ marker: "1", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "2", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "3", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "4", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "5", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "6", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "7", preferences, includes: { name: "className", insertText: "className={$1}", text: "(property) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "8", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "9", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "10", preferences, includes: { name: "className", insertText: "className={$1}", text: "(property) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
{ marker: "11", preferences, includes: { name: "className", insertText: "className={$1}", text: "(JSX attribute) className?: string", isSnippet: true, sortText: completion.SortText.OptionalMember } }, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// <reference path="fourslash.ts" /> | ||
//@Filename: file.tsx | ||
////interface NestedInterface { | ||
//// Foo: NestedInterface; | ||
//// (props: {}): any; | ||
////} | ||
//// | ||
////declare const Foo: NestedInterface; | ||
//// | ||
////function fn1() { | ||
//// return <Foo> | ||
//// </*1*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn2() { | ||
//// return <Foo> | ||
//// <Fo/*2*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn3() { | ||
//// return <Foo> | ||
//// <Foo./*3*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn4() { | ||
//// return <Foo> | ||
//// <Foo.F/*4*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn5() { | ||
//// return <Foo> | ||
//// <Foo.Foo./*5*/ /> | ||
//// </Foo> | ||
////} | ||
////function fn6() { | ||
//// return <Foo> | ||
//// <Foo.Foo.F/*6*/ /> | ||
//// </Foo> | ||
////} | ||
|
||
var preferences: FourSlashInterface.UserPreferences = { | ||
jsxAttributeCompletionStyle: "braces", | ||
includeCompletionsWithSnippetText: true, | ||
includeCompletionsWithInsertText: true, | ||
}; | ||
|
||
verify.completions( | ||
{ marker: "1", preferences, includes: { name: "Foo", text: "const Foo: NestedInterface" } }, | ||
{ marker: "2", preferences, includes: { name: "Foo", text: "const Foo: NestedInterface" } }, | ||
{ marker: "3", preferences, includes: { name: "Foo", text: "(JSX attribute) NestedInterface.Foo: NestedInterface" } }, | ||
{ marker: "4", preferences, includes: { name: "Foo", text: "(property) NestedInterface.Foo: NestedInterface" } }, | ||
{ marker: "5", preferences, includes: { name: "Foo", text: "(JSX attribute) NestedInterface.Foo: NestedInterface" } }, | ||
{ marker: "6", preferences, includes: { name: "Foo", text: "(property) NestedInterface.Foo: NestedInterface" } }, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// <reference path="fourslash.ts" /> | ||
//@Filename: file.tsx | ||
////interface NestedInterface { | ||
//// Foo: NestedInterface; | ||
//// (props: {}): any; | ||
////} | ||
//// | ||
////declare const Foo: NestedInterface; | ||
//// | ||
////function fn1() { | ||
//// return <Foo> | ||
//// </*1*/ | ||
//// </Foo> | ||
////} | ||
////function fn2() { | ||
//// return <Foo> | ||
//// <Fo/*2*/ | ||
//// </Foo> | ||
////} | ||
////function fn3() { | ||
//// return <Foo> | ||
//// <Foo./*3*/ | ||
//// </Foo> | ||
////} | ||
////function fn4() { | ||
//// return <Foo> | ||
//// <Foo.F/*4*/ | ||
//// </Foo> | ||
////} | ||
////function fn5() { | ||
//// return <Foo> | ||
//// <Foo.Foo./*5*/ | ||
//// </Foo> | ||
////} | ||
////function fn6() { | ||
//// return <Foo> | ||
//// <Foo.Foo.F/*6*/ | ||
//// </Foo> | ||
////} | ||
|
||
var preferences: FourSlashInterface.UserPreferences = { | ||
jsxAttributeCompletionStyle: "braces", | ||
includeCompletionsWithSnippetText: true, | ||
includeCompletionsWithInsertText: true, | ||
}; | ||
|
||
verify.completions( | ||
{ marker: "1", preferences, includes: { name: "Foo", text: "const Foo: NestedInterface" } }, | ||
{ marker: "2", preferences, includes: { name: "Foo", text: "const Foo: NestedInterface" } }, | ||
{ marker: "3", preferences, includes: { name: "Foo", text: "(JSX attribute) NestedInterface.Foo: NestedInterface" } }, | ||
{ marker: "4", preferences, includes: { name: "Foo", text: "(property) NestedInterface.Foo: NestedInterface" } }, | ||
{ marker: "5", preferences, includes: { name: "Foo", text: "(JSX attribute) NestedInterface.Foo: NestedInterface" } }, | ||
{ marker: "6", preferences, includes: { name: "Foo", text: "(property) NestedInterface.Foo: NestedInterface" } }, | ||
) |
35 changes: 35 additions & 0 deletions
35
tests/cases/fourslash/jsxTagNameCompletionUnderElementClosed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// <reference path="fourslash.ts" /> | ||
//@Filename: file.tsx | ||
////declare namespace JSX { | ||
//// interface IntrinsicElements { | ||
//// button: any; | ||
//// div: any; | ||
//// } | ||
////} | ||
////function fn() { | ||
//// return <> | ||
//// <butto/*1*/ /> | ||
//// </>; | ||
////} | ||
////function fn2() { | ||
//// return <> | ||
//// preceding junk <butto/*2*/ /> | ||
//// </>; | ||
////} | ||
////function fn3() { | ||
//// return <> | ||
//// <butto/*3*/ style="" /> | ||
//// </>; | ||
////} | ||
|
||
var preferences: FourSlashInterface.UserPreferences = { | ||
jsxAttributeCompletionStyle: "braces", | ||
includeCompletionsWithSnippetText: true, | ||
includeCompletionsWithInsertText: true, | ||
}; | ||
|
||
verify.completions( | ||
{ marker: "1", preferences, includes: { name: "button", text: "(JSX attribute) JSX.IntrinsicElements.button: any" } }, | ||
{ marker: "2", preferences, includes: { name: "button", text: "(JSX attribute) JSX.IntrinsicElements.button: any" } }, | ||
{ marker: "3", preferences, includes: { name: "button", text: "(JSX attribute) JSX.IntrinsicElements.button: any" } }, | ||
) |
35 changes: 35 additions & 0 deletions
35
tests/cases/fourslash/jsxTagNameCompletionUnderElementUnclosed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// <reference path="fourslash.ts" /> | ||
//@Filename: file.tsx | ||
////declare namespace JSX { | ||
//// interface IntrinsicElements { | ||
//// button: any; | ||
//// div: any; | ||
//// } | ||
////} | ||
////function fn() { | ||
//// return <> | ||
//// <butto/*1*/ | ||
//// </>; | ||
////} | ||
////function fn2() { | ||
//// return <> | ||
//// preceding junk <butto/*2*/ | ||
//// </>; | ||
////} | ||
////function fn3() { | ||
//// return <> | ||
//// <butto/*3*/ style="" | ||
//// </>; | ||
////} | ||
|
||
var preferences: FourSlashInterface.UserPreferences = { | ||
jsxAttributeCompletionStyle: "braces", | ||
includeCompletionsWithSnippetText: true, | ||
includeCompletionsWithInsertText: true, | ||
}; | ||
|
||
verify.completions( | ||
{ marker: "1", preferences, includes: { name: "button", text: "(JSX attribute) JSX.IntrinsicElements.button: any" } }, | ||
{ marker: "2", preferences, includes: { name: "button", text: "(JSX attribute) JSX.IntrinsicElements.button: any" } }, | ||
{ marker: "3", preferences, includes: { name: "button", text: "(JSX attribute) JSX.IntrinsicElements.button: any" } }, | ||
) |