From 88bffac07ff5288531c139f221576fc4235e4923 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 8 Oct 2015 14:26:43 -0700 Subject: [PATCH 1/5] 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(); +} From b1c83033007657b32d8ee777130357447700feed Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 8 Oct 2015 14:55:11 -0700 Subject: [PATCH 2/5] Fix case for completion on the line after a self-closing element --- src/services/services.ts | 15 ++++++++++----- tests/cases/fourslash/tsxCompletion9.ts | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 3eb5ec319ad..0fd76eff61f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3322,11 +3322,16 @@ namespace ts { return true; } - return contextToken.kind === SyntaxKind.GreaterThanToken && - contextToken.parent && - (contextToken.parent.kind === SyntaxKind.JsxOpeningElement || - contextToken.parent.kind === SyntaxKind.JsxSelfClosingElement || - contextToken.parent.kind === SyntaxKind.JsxClosingElement); + if (contextToken.kind === SyntaxKind.GreaterThanToken && contextToken.parent) { + if (contextToken.parent.kind === SyntaxKind.JsxOpeningElement) { + return true; + } + + if (contextToken.parent.kind === SyntaxKind.JsxClosingElement || contextToken.parent.kind === SyntaxKind.JsxSelfClosingElement) { + return contextToken.parent.parent && contextToken.parent.parent.kind === SyntaxKind.JsxElement; + } + } + return false; } function isNewIdentifierDefinitionLocation(previousToken: Node): boolean { diff --git a/tests/cases/fourslash/tsxCompletion9.ts b/tests/cases/fourslash/tsxCompletion9.ts index dbb6c46293b..12542cc6b5b 100644 --- a/tests/cases/fourslash/tsxCompletion9.ts +++ b/tests/cases/fourslash/tsxCompletion9.ts @@ -11,8 +11,14 @@ //// var x2 =
/*4*/
/*5*/ world /*6*/
; //// var x3 =
/*7*/
/*8*/world/*9*/
; //// var x4 =
/*10*/
; +////
+//// /*end*/ +//// for (var i = 1; i <= 10; i++) { goTo.marker(i + ''); verify.completionListIsEmpty(); } + +goTo.marker('end'); +verify.not.completionListIsEmpty(); From 1e708b46a7251ea9a8b6b4b8c5c1d925e098fed6 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 8 Oct 2015 15:31:59 -0700 Subject: [PATCH 3/5] Implement not.greaterThan for completion list --- src/harness/fourslash.ts | 13 ++++++++++--- tests/cases/fourslash/fourslash.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index a846077a85f..2b6f6ee8d0e 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -588,14 +588,21 @@ namespace FourSlash { } } - public verifyCompletionListItemsCountIsGreaterThan(count: number) { + public verifyCompletionListItemsCountIsGreaterThan(count: number, negative: boolean) { this.taoInvalidReason = "verifyCompletionListItemsCountIsGreaterThan NYI"; let completions = this.getCompletionListAtCaret(); let itemsCount = completions.entries.length; - if (itemsCount <= count) { - this.raiseError(`Expected completion list items count to be greater than ${count}, but is actually ${itemsCount}`); + if (negative) { + if (itemsCount > count) { + this.raiseError(`Expected completion list items count to not be greater than ${count}, but is actually ${itemsCount}`); + } + } + else { + if (itemsCount <= count) { + this.raiseError(`Expected completion list items count to be greater than ${count}, but is actually ${itemsCount}`); + } } } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 42cfc1248b0..8d1ee35dc1a 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -205,7 +205,7 @@ module FourSlashInterface { // Verifies the completion list items count to be greater than the specified amount. The // completion list is brought up if necessary public completionListItemsCountIsGreaterThan(count: number) { - FourSlash.currentTestState.verifyCompletionListItemsCountIsGreaterThan(count); + FourSlash.currentTestState.verifyCompletionListItemsCountIsGreaterThan(count, this.negative); } public completionListIsEmpty() { From 24334b506c28b58ba3c30528b5044cd4db05e778 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 8 Oct 2015 15:32:36 -0700 Subject: [PATCH 4/5] Only show the opening tag name when completing a close tag Fixes #5096 --- src/services/services.ts | 19 ++++++++++++++++--- tests/cases/fourslash/tsxCompletion10.ts | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/tsxCompletion10.ts diff --git a/src/services/services.ts b/src/services/services.ts index 0fd76eff61f..84794e95a6e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3105,6 +3105,7 @@ namespace ts { let node = currentToken; let isRightOfDot = false; let isRightOfOpenTag = false; + let isStartingCloseTag = false; let location = getTouchingPropertyName(sourceFile, position); if (contextToken) { @@ -3130,9 +3131,14 @@ namespace ts { return undefined; } } - else if (kind === SyntaxKind.LessThanToken && sourceFile.languageVariant === LanguageVariant.JSX) { - isRightOfOpenTag = true; - location = contextToken; + else if (sourceFile.languageVariant === LanguageVariant.JSX) { + if (kind === SyntaxKind.LessThanToken) { + isRightOfOpenTag = true; + location = contextToken; + } + else if (kind === SyntaxKind.SlashToken && contextToken.parent.kind === SyntaxKind.JsxClosingElement) { + isStartingCloseTag = true; + } } } @@ -3155,6 +3161,13 @@ namespace ts { isMemberCompletion = true; isNewIdentifierLocation = false; } + else if (isStartingCloseTag) { + let tagName = (contextToken.parent.parent).openingElement.tagName; + symbols = [typeChecker.getSymbolAtLocation(tagName)]; + + isMemberCompletion = true; + isNewIdentifierLocation = false; + } else { // For JavaScript or TypeScript, if we're not after a dot, then just try to get the // global symbols in scope. These results should be valid for either language as diff --git a/tests/cases/fourslash/tsxCompletion10.ts b/tests/cases/fourslash/tsxCompletion10.ts new file mode 100644 index 00000000000..cf8b3068f10 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion10.ts @@ -0,0 +1,15 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// var x1 =
Date: Tue, 13 Oct 2015 13:16:44 -0700 Subject: [PATCH 5/5] Use `memberListCount` --- tests/cases/fourslash/tsxCompletion10.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/cases/fourslash/tsxCompletion10.ts b/tests/cases/fourslash/tsxCompletion10.ts index cf8b3068f10..f10e014c282 100644 --- a/tests/cases/fourslash/tsxCompletion10.ts +++ b/tests/cases/fourslash/tsxCompletion10.ts @@ -10,6 +10,5 @@ //// var x1 =