@@ -456,6 +456,7 @@ namespace ts.Completions {
456
456
isJsxInitializer,
457
457
isTypeOnlyLocation,
458
458
isJsxIdentifierExpected,
459
+ isRightOfOpenTag,
459
460
importCompletionNode,
460
461
insideJsDocTagTypeExpression,
461
462
symbolToSortTextIdMap,
@@ -495,7 +496,9 @@ namespace ts.Completions {
495
496
importCompletionNode ,
496
497
recommendedCompletion ,
497
498
symbolToOriginInfoMap ,
498
- symbolToSortTextIdMap
499
+ symbolToSortTextIdMap ,
500
+ isJsxIdentifierExpected ,
501
+ isRightOfOpenTag ,
499
502
) ;
500
503
getJSCompletionEntries ( sourceFile , location . pos , uniqueNames , getEmitScriptTarget ( compilerOptions ) , entries ) ; // TODO: GH#18217
501
504
}
@@ -526,7 +529,9 @@ namespace ts.Completions {
526
529
importCompletionNode ,
527
530
recommendedCompletion ,
528
531
symbolToOriginInfoMap ,
529
- symbolToSortTextIdMap
532
+ symbolToSortTextIdMap ,
533
+ isJsxIdentifierExpected ,
534
+ isRightOfOpenTag ,
530
535
) ;
531
536
}
532
537
@@ -669,6 +674,8 @@ namespace ts.Completions {
669
674
preferences : UserPreferences ,
670
675
completionKind : CompletionKind ,
671
676
formatContext : formatting . FormatContext | undefined ,
677
+ isJsxIdentifierExpected : boolean | undefined ,
678
+ isRightOfOpenTag : boolean | undefined ,
672
679
) : CompletionEntry | undefined {
673
680
let insertText : string | undefined ;
674
681
let replacementSpan = getReplacementSpanForContextToken ( replacementToken ) ;
@@ -744,46 +751,7 @@ namespace ts.Completions {
744
751
}
745
752
}
746
753
747
- const isJSXAttributeCompletion = contextToken && forEachAncestor ( contextToken , ( n ) => {
748
- if ( isJsxAttributeLike ( n ) ) {
749
- return true ;
750
- }
751
-
752
- if ( isJsxFragment ( n ) || isJsxOpeningFragment ( n ) || isJsxClosingFragment ( n ) ) {
753
- return false ;
754
- }
755
-
756
- if ( isJsxOpeningElement ( n ) || isJsxSelfClosingElement ( n ) || isJsxClosingElement ( n ) ) {
757
- if ( contextToken . getEnd ( ) <= n . tagName . getFullStart ( ) ) {
758
- // Definitely completing part of the tag name.
759
- return false ;
760
- }
761
-
762
- if ( rangeContainsRange ( n . tagName , contextToken ) ) {
763
- // We are to the right of the tag name, as the context is there.
764
- // figure out where we are based on where the location is.
765
-
766
- if ( contextToken . kind === SyntaxKind . DotToken || contextToken . kind === SyntaxKind . QuestionDotToken ) {
767
- // Unfinished dotted tag name.
768
- return false ;
769
- }
770
-
771
- if ( ! rangeContainsRange ( n , location ) ) {
772
- // Unclosed JSX element; location is entirely outside the element.
773
- return true ;
774
- }
775
-
776
- if ( n . tagName . getEnd ( ) <= location . getFullStart ( ) ) {
777
- // After existing attributes, so is another attribute.
778
- return true ;
779
- }
780
- }
781
-
782
- return false ;
783
- }
784
- } ) ;
785
-
786
- if ( isJSXAttributeCompletion && preferences . includeCompletionsWithSnippetText && preferences . jsxAttributeCompletionStyle && preferences . jsxAttributeCompletionStyle !== "none" ) {
754
+ if ( isJsxIdentifierExpected && ! isRightOfOpenTag && preferences . includeCompletionsWithSnippetText && preferences . jsxAttributeCompletionStyle && preferences . jsxAttributeCompletionStyle !== "none" ) {
787
755
let useBraces = preferences . jsxAttributeCompletionStyle === "braces" ;
788
756
const type = typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
789
757
@@ -1224,6 +1192,8 @@ namespace ts.Completions {
1224
1192
recommendedCompletion ?: Symbol ,
1225
1193
symbolToOriginInfoMap ?: SymbolOriginInfoMap ,
1226
1194
symbolToSortTextIdMap ?: SymbolSortTextIdMap ,
1195
+ isJsxIdentifierExpected ?: boolean ,
1196
+ isRightOfOpenTag ?: boolean ,
1227
1197
) : UniqueNameSet {
1228
1198
const start = timestamp ( ) ;
1229
1199
const variableDeclaration = getVariableDeclaration ( location ) ;
@@ -1266,6 +1236,8 @@ namespace ts.Completions {
1266
1236
preferences ,
1267
1237
kind ,
1268
1238
formatContext ,
1239
+ isJsxIdentifierExpected ,
1240
+ isRightOfOpenTag ,
1269
1241
) ;
1270
1242
if ( ! entry ) {
1271
1243
continue ;
@@ -1618,6 +1590,7 @@ namespace ts.Completions {
1618
1590
readonly isTypeOnlyLocation : boolean ;
1619
1591
/** In JSX tag name and attribute names, identifiers like "my-tag" or "aria-name" is valid identifier. */
1620
1592
readonly isJsxIdentifierExpected : boolean ;
1593
+ readonly isRightOfOpenTag : boolean ;
1621
1594
readonly importCompletionNode ?: Node ;
1622
1595
readonly hasUnresolvedAutoImports ?: boolean ;
1623
1596
}
@@ -2025,6 +1998,7 @@ namespace ts.Completions {
2025
1998
symbolToSortTextIdMap,
2026
1999
isTypeOnlyLocation,
2027
2000
isJsxIdentifierExpected,
2001
+ isRightOfOpenTag,
2028
2002
importCompletionNode,
2029
2003
hasUnresolvedAutoImports,
2030
2004
} ;
0 commit comments