Skip to content

Commit b3a6428

Browse files
author
Andy
authored
Fix completions trigger character on JSX opening tag (microsoft#25167)
1 parent 878bf80 commit b3a6428

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ namespace FourSlash {
856856
private verifyCompletionsWorker(options: FourSlashInterface.VerifyCompletionsOptions): void {
857857
const actualCompletions = this.getCompletionListAtCaret({ ...options.preferences, triggerCharacter: options.triggerCharacter })!;
858858
if (!actualCompletions) {
859-
if (options.exact === undefined) return;
859+
if ("exact" in options && options.exact === undefined) return;
860860
this.raiseError(`No completions at position '${this.currentCaretPosition}'.`);
861861
}
862862

src/services/completions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,7 @@ namespace ts.Completions {
961961
break;
962962

963963
case SyntaxKind.BinaryExpression:
964-
if (!((parent as BinaryExpression).left.flags & NodeFlags.ThisNodeHasError)) {
965-
// It has a left-hand side, so we're not in an opening JSX tag.
964+
if (!binaryExpressionMayBeOpenTag(parent as BinaryExpression)) {
966965
break;
967966
}
968967
// falls through
@@ -2256,7 +2255,7 @@ namespace ts.Completions {
22562255
return isStringLiteralOrTemplate(contextToken) && position === contextToken.getStart(sourceFile) + 1;
22572256
case "<":
22582257
// Opening JSX tag
2259-
return contextToken.kind === SyntaxKind.LessThanToken && contextToken.parent.kind !== SyntaxKind.BinaryExpression;
2258+
return contextToken.kind === SyntaxKind.LessThanToken && (!isBinaryExpression(contextToken.parent) || binaryExpressionMayBeOpenTag(contextToken.parent));
22602259
case "/":
22612260
return isStringLiteralLike(contextToken)
22622261
? !!tryGetImportFromModuleSpecifier(contextToken)
@@ -2266,6 +2265,10 @@ namespace ts.Completions {
22662265
}
22672266
}
22682267

2268+
function binaryExpressionMayBeOpenTag({ left }: BinaryExpression): boolean {
2269+
return nodeIsMissing(left);
2270+
}
2271+
22692272
function isStringLiteralOrTemplate(node: Node): node is StringLiteralLike | TemplateExpression | TaggedTemplateExpression {
22702273
switch (node.kind) {
22712274
case SyntaxKind.StringLiteral:

tests/cases/fourslash/completionsTriggerCharacter.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
////whatever
1414

1515
// @Filename: /a.tsx
16-
////declare namespace JSX {
17-
//// interface Element {}
18-
//// interface IntrinsicElements {
19-
//// div: {};
16+
////declare global {
17+
//// namespace JSX {
18+
//// interface Element {}
19+
//// interface IntrinsicElements {
20+
//// div: {};
21+
//// }
2022
//// }
2123
////}
2224
////const ctr = </*openTag*/;

0 commit comments

Comments
 (0)