diff --git a/src/services/completions.ts b/src/services/completions.ts index d9e856c195829..a7a47193da622 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2543,16 +2543,20 @@ namespace ts.Completions { } if (contextToken.kind === SyntaxKind.GreaterThanToken && contextToken.parent) { + // /**/ /> + // /**/ > + // - contextToken: GreaterThanToken (before cursor) + // - location: JsxSelfClosingElement or JsxOpeningElement + // - contextToken.parent === location + if (location === contextToken.parent && (location.kind === SyntaxKind.JsxOpeningElement || location.kind === SyntaxKind.JsxSelfClosingElement)) { + return false; + } + if (contextToken.parent.kind === SyntaxKind.JsxOpeningElement) { - // Two possibilities: - // 1.
/**/ - // - contextToken: GreaterThanToken (before cursor) - // - location: JSXElement - // - different parents (JSXOpeningElement, JSXElement) - // 2. /**/> - // - contextToken: GreaterThanToken (before cursor) - // - location: GreaterThanToken (after cursor) - // - same parent (JSXOpeningElement) + //
/**/ + // - contextToken: GreaterThanToken (before cursor) + // - location: JSXElement + // - different parents (JSXOpeningElement, JSXElement) return location.parent.kind !== SyntaxKind.JsxOpeningElement; } diff --git a/tests/cases/fourslash/jsxAttributeSnippetCompletionAfterTypeArgs.ts b/tests/cases/fourslash/jsxAttributeSnippetCompletionAfterTypeArgs.ts new file mode 100644 index 0000000000000..f22d6a7c86e4f --- /dev/null +++ b/tests/cases/fourslash/jsxAttributeSnippetCompletionAfterTypeArgs.ts @@ -0,0 +1,55 @@ +/// +//@Filename: file.tsx + +////declare const React: any; +//// +////namespace JSX { +//// export interface IntrinsicElements { +//// div: any; +//// } +////} +//// +////function GenericElement(props: {xyz?: T}) { +//// return <> +////} +//// +////function fn1() { +//// return
+//// /*1*/ /> +////
+////} +//// +////function fn2() { +//// return <> +//// /*2*/ /> +//// +////} +////function fn3() { +//// return
+//// /*3*/ > +////
+////} +//// +////function fn4() { +//// return <> +//// /*4*/ > +//// +////} + +verify.completions( + { + marker: test.markers(), + includes: { + name: "xyz", + insertText: "xyz={$1}", + text: "(property) xyz?: number", + isSnippet: true, + sortText: completion.SortText.OptionalMember + }, + preferences: { + jsxAttributeCompletionStyle: "braces", + includeCompletionsWithSnippetText: true, + includeCompletionsWithInsertText: true, + }, + }, +)