Skip to content

Commit 2983d52

Browse files
committed
Use the flags that are already set up for this, grr
1 parent d14d8ff commit 2983d52

File tree

1 file changed

+16
-42
lines changed

1 file changed

+16
-42
lines changed

src/services/completions.ts

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ namespace ts.Completions {
456456
isJsxInitializer,
457457
isTypeOnlyLocation,
458458
isJsxIdentifierExpected,
459+
isRightOfOpenTag,
459460
importCompletionNode,
460461
insideJsDocTagTypeExpression,
461462
symbolToSortTextIdMap,
@@ -495,7 +496,9 @@ namespace ts.Completions {
495496
importCompletionNode,
496497
recommendedCompletion,
497498
symbolToOriginInfoMap,
498-
symbolToSortTextIdMap
499+
symbolToSortTextIdMap,
500+
isJsxIdentifierExpected,
501+
isRightOfOpenTag,
499502
);
500503
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
501504
}
@@ -526,7 +529,9 @@ namespace ts.Completions {
526529
importCompletionNode,
527530
recommendedCompletion,
528531
symbolToOriginInfoMap,
529-
symbolToSortTextIdMap
532+
symbolToSortTextIdMap,
533+
isJsxIdentifierExpected,
534+
isRightOfOpenTag,
530535
);
531536
}
532537

@@ -669,6 +674,8 @@ namespace ts.Completions {
669674
preferences: UserPreferences,
670675
completionKind: CompletionKind,
671676
formatContext: formatting.FormatContext | undefined,
677+
isJsxIdentifierExpected: boolean | undefined,
678+
isRightOfOpenTag: boolean | undefined,
672679
): CompletionEntry | undefined {
673680
let insertText: string | undefined;
674681
let replacementSpan = getReplacementSpanForContextToken(replacementToken);
@@ -744,46 +751,7 @@ namespace ts.Completions {
744751
}
745752
}
746753

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") {
787755
let useBraces = preferences.jsxAttributeCompletionStyle === "braces";
788756
const type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
789757

@@ -1224,6 +1192,8 @@ namespace ts.Completions {
12241192
recommendedCompletion?: Symbol,
12251193
symbolToOriginInfoMap?: SymbolOriginInfoMap,
12261194
symbolToSortTextIdMap?: SymbolSortTextIdMap,
1195+
isJsxIdentifierExpected?: boolean,
1196+
isRightOfOpenTag?: boolean,
12271197
): UniqueNameSet {
12281198
const start = timestamp();
12291199
const variableDeclaration = getVariableDeclaration(location);
@@ -1266,6 +1236,8 @@ namespace ts.Completions {
12661236
preferences,
12671237
kind,
12681238
formatContext,
1239+
isJsxIdentifierExpected,
1240+
isRightOfOpenTag,
12691241
);
12701242
if (!entry) {
12711243
continue;
@@ -1618,6 +1590,7 @@ namespace ts.Completions {
16181590
readonly isTypeOnlyLocation: boolean;
16191591
/** In JSX tag name and attribute names, identifiers like "my-tag" or "aria-name" is valid identifier. */
16201592
readonly isJsxIdentifierExpected: boolean;
1593+
readonly isRightOfOpenTag: boolean;
16211594
readonly importCompletionNode?: Node;
16221595
readonly hasUnresolvedAutoImports?: boolean;
16231596
}
@@ -2025,6 +1998,7 @@ namespace ts.Completions {
20251998
symbolToSortTextIdMap,
20261999
isTypeOnlyLocation,
20272000
isJsxIdentifierExpected,
2001+
isRightOfOpenTag,
20282002
importCompletionNode,
20292003
hasUnresolvedAutoImports,
20302004
};

0 commit comments

Comments
 (0)