@@ -428,6 +428,7 @@ namespace ts.Completions {
428
428
isJsxInitializer,
429
429
isTypeOnlyLocation,
430
430
isJsxIdentifierExpected,
431
+ isRightOfOpenTag,
431
432
importCompletionNode,
432
433
insideJsDocTagTypeExpression,
433
434
symbolToSortTextIdMap,
@@ -466,7 +467,9 @@ namespace ts.Completions {
466
467
importCompletionNode ,
467
468
recommendedCompletion ,
468
469
symbolToOriginInfoMap ,
469
- symbolToSortTextIdMap
470
+ symbolToSortTextIdMap ,
471
+ isJsxIdentifierExpected ,
472
+ isRightOfOpenTag ,
470
473
) ;
471
474
getJSCompletionEntries ( sourceFile , location . pos , uniqueNames , getEmitScriptTarget ( compilerOptions ) , entries ) ; // TODO: GH#18217
472
475
}
@@ -496,7 +499,9 @@ namespace ts.Completions {
496
499
importCompletionNode ,
497
500
recommendedCompletion ,
498
501
symbolToOriginInfoMap ,
499
- symbolToSortTextIdMap
502
+ symbolToSortTextIdMap ,
503
+ isJsxIdentifierExpected ,
504
+ isRightOfOpenTag ,
500
505
) ;
501
506
}
502
507
@@ -638,6 +643,8 @@ namespace ts.Completions {
638
643
options : CompilerOptions ,
639
644
preferences : UserPreferences ,
640
645
completionKind : CompletionKind ,
646
+ isJsxIdentifierExpected : boolean | undefined ,
647
+ isRightOfOpenTag : boolean | undefined ,
641
648
) : CompletionEntry | undefined {
642
649
let insertText : string | undefined ;
643
650
let replacementSpan = getReplacementSpanForContextToken ( replacementToken ) ;
@@ -713,25 +720,7 @@ namespace ts.Completions {
713
720
}
714
721
}
715
722
716
- // Before offering up a JSX attribute snippet, ensure that we aren't potentially completing
717
- // a tag name; this may appear as an attribute after the "<" when the tag has not yet been
718
- // closed, as in:
719
- //
720
- // return <>
721
- // foo <butto|
722
- // </>
723
- //
724
- // We can detect this case by checking if both:
725
- //
726
- // 1. The location is "<", so we are completing immediately after it.
727
- // 2. The "<" has the same position as its parent, so is not a binary expression.
728
- const kind = SymbolDisplay . getSymbolKind ( typeChecker , symbol , location ) ;
729
- if (
730
- kind === ScriptElementKind . jsxAttribute
731
- && ( location . kind !== SyntaxKind . LessThanToken || location . pos !== location . parent . pos )
732
- && preferences . includeCompletionsWithSnippetText
733
- && preferences . jsxAttributeCompletionStyle
734
- && preferences . jsxAttributeCompletionStyle !== "none" ) {
723
+ if ( isJsxIdentifierExpected && ! isRightOfOpenTag && preferences . includeCompletionsWithSnippetText && preferences . jsxAttributeCompletionStyle && preferences . jsxAttributeCompletionStyle !== "none" ) {
735
724
let useBraces = preferences . jsxAttributeCompletionStyle === "braces" ;
736
725
const type = typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
737
726
@@ -776,7 +765,7 @@ namespace ts.Completions {
776
765
// entries (like JavaScript identifier entries).
777
766
return {
778
767
name,
779
- kind,
768
+ kind : SymbolDisplay . getSymbolKind ( typeChecker , symbol , location ) ,
780
769
kindModifiers : SymbolDisplay . getSymbolModifiers ( typeChecker , symbol ) ,
781
770
sortText,
782
771
source,
@@ -1142,6 +1131,8 @@ namespace ts.Completions {
1142
1131
recommendedCompletion ?: Symbol ,
1143
1132
symbolToOriginInfoMap ?: SymbolOriginInfoMap ,
1144
1133
symbolToSortTextIdMap ?: SymbolSortTextIdMap ,
1134
+ isJsxIdentifierExpected ?: boolean ,
1135
+ isRightOfOpenTag ?: boolean ,
1145
1136
) : UniqueNameSet {
1146
1137
const start = timestamp ( ) ;
1147
1138
const variableDeclaration = getVariableDeclaration ( location ) ;
@@ -1183,6 +1174,8 @@ namespace ts.Completions {
1183
1174
compilerOptions ,
1184
1175
preferences ,
1185
1176
kind ,
1177
+ isJsxIdentifierExpected ,
1178
+ isRightOfOpenTag ,
1186
1179
) ;
1187
1180
if ( ! entry ) {
1188
1181
continue ;
@@ -1534,6 +1527,7 @@ namespace ts.Completions {
1534
1527
readonly isTypeOnlyLocation : boolean ;
1535
1528
/** In JSX tag name and attribute names, identifiers like "my-tag" or "aria-name" is valid identifier. */
1536
1529
readonly isJsxIdentifierExpected : boolean ;
1530
+ readonly isRightOfOpenTag : boolean ;
1537
1531
readonly importCompletionNode ?: Node ;
1538
1532
readonly hasUnresolvedAutoImports ?: boolean ;
1539
1533
}
@@ -1941,6 +1935,7 @@ namespace ts.Completions {
1941
1935
symbolToSortTextIdMap,
1942
1936
isTypeOnlyLocation,
1943
1937
isJsxIdentifierExpected,
1938
+ isRightOfOpenTag,
1944
1939
importCompletionNode,
1945
1940
hasUnresolvedAutoImports,
1946
1941
} ;
0 commit comments