From 88bffac07ff5288531c139f221576fc4235e4923 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 8 Oct 2015 14:26:43 -0700 Subject: [PATCH] Don't issue completion in JSX text Fixes #5096 --- src/services/services.ts | 15 ++++++++++++++- tests/cases/fourslash/tsxCompletion9.ts | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/tsxCompletion9.ts diff --git a/src/services/services.ts b/src/services/services.ts index 9a6afb5f1e0..3eb5ec319ad 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3311,11 +3311,24 @@ namespace ts { let start = new Date().getTime(); let result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || isSolelyIdentifierDefinitionLocation(contextToken) || - isDotOfNumericLiteral(contextToken); + isDotOfNumericLiteral(contextToken) || + isInJsxText(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } + function isInJsxText(contextToken: Node): boolean { + if (contextToken.kind === SyntaxKind.JsxText) { + return true; + } + + return contextToken.kind === SyntaxKind.GreaterThanToken && + contextToken.parent && + (contextToken.parent.kind === SyntaxKind.JsxOpeningElement || + contextToken.parent.kind === SyntaxKind.JsxSelfClosingElement || + contextToken.parent.kind === SyntaxKind.JsxClosingElement); + } + function isNewIdentifierDefinitionLocation(previousToken: Node): boolean { if (previousToken) { let containingNodeKind = previousToken.parent.kind; diff --git a/tests/cases/fourslash/tsxCompletion9.ts b/tests/cases/fourslash/tsxCompletion9.ts new file mode 100644 index 00000000000..dbb6c46293b --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion9.ts @@ -0,0 +1,18 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// var x1 =
/*1*/ hello /*2*/ world /*3*/
; +//// var x2 =
/*4*/
/*5*/ world /*6*/
; +//// var x3 =
/*7*/
/*8*/world/*9*/
; +//// var x4 =
/*10*/
; + +for (var i = 1; i <= 10; i++) { + goTo.marker(i + ''); + verify.completionListIsEmpty(); +}