Skip to content

Commit b2d666c

Browse files
committed
Merge pull request #5184 from RyanCavanaugh/fix5096
Don't issue completion in JSX text
2 parents c4a15d9 + 6bbfe56 commit b2d666c

File tree

5 files changed

+84
-8
lines changed

5 files changed

+84
-8
lines changed

src/harness/fourslash.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,21 @@ namespace FourSlash {
591591
}
592592
}
593593

594-
public verifyCompletionListItemsCountIsGreaterThan(count: number) {
594+
public verifyCompletionListItemsCountIsGreaterThan(count: number, negative: boolean) {
595595
this.taoInvalidReason = "verifyCompletionListItemsCountIsGreaterThan NYI";
596596

597597
let completions = this.getCompletionListAtCaret();
598598
let itemsCount = completions.entries.length;
599599

600-
if (itemsCount <= count) {
601-
this.raiseError(`Expected completion list items count to be greater than ${count}, but is actually ${itemsCount}`);
600+
if (negative) {
601+
if (itemsCount > count) {
602+
this.raiseError(`Expected completion list items count to not be greater than ${count}, but is actually ${itemsCount}`);
603+
}
604+
}
605+
else {
606+
if (itemsCount <= count) {
607+
this.raiseError(`Expected completion list items count to be greater than ${count}, but is actually ${itemsCount}`);
608+
}
602609
}
603610
}
604611

src/services/services.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,6 +3112,7 @@ namespace ts {
31123112
let node = currentToken;
31133113
let isRightOfDot = false;
31143114
let isRightOfOpenTag = false;
3115+
let isStartingCloseTag = false;
31153116

31163117
let location = getTouchingPropertyName(sourceFile, position);
31173118
if (contextToken) {
@@ -3137,9 +3138,14 @@ namespace ts {
31373138
return undefined;
31383139
}
31393140
}
3140-
else if (kind === SyntaxKind.LessThanToken && sourceFile.languageVariant === LanguageVariant.JSX) {
3141-
isRightOfOpenTag = true;
3142-
location = contextToken;
3141+
else if (sourceFile.languageVariant === LanguageVariant.JSX) {
3142+
if (kind === SyntaxKind.LessThanToken) {
3143+
isRightOfOpenTag = true;
3144+
location = contextToken;
3145+
}
3146+
else if (kind === SyntaxKind.SlashToken && contextToken.parent.kind === SyntaxKind.JsxClosingElement) {
3147+
isStartingCloseTag = true;
3148+
}
31433149
}
31443150
}
31453151

@@ -3162,6 +3168,13 @@ namespace ts {
31623168
isMemberCompletion = true;
31633169
isNewIdentifierLocation = false;
31643170
}
3171+
else if (isStartingCloseTag) {
3172+
let tagName = (<JsxElement>contextToken.parent.parent).openingElement.tagName;
3173+
symbols = [typeChecker.getSymbolAtLocation(tagName)];
3174+
3175+
isMemberCompletion = true;
3176+
isNewIdentifierLocation = false;
3177+
}
31653178
else {
31663179
// For JavaScript or TypeScript, if we're not after a dot, then just try to get the
31673180
// global symbols in scope. These results should be valid for either language as
@@ -3318,11 +3331,29 @@ namespace ts {
33183331
let start = new Date().getTime();
33193332
let result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) ||
33203333
isSolelyIdentifierDefinitionLocation(contextToken) ||
3321-
isDotOfNumericLiteral(contextToken);
3334+
isDotOfNumericLiteral(contextToken) ||
3335+
isInJsxText(contextToken);
33223336
log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start));
33233337
return result;
33243338
}
33253339

3340+
function isInJsxText(contextToken: Node): boolean {
3341+
if (contextToken.kind === SyntaxKind.JsxText) {
3342+
return true;
3343+
}
3344+
3345+
if (contextToken.kind === SyntaxKind.GreaterThanToken && contextToken.parent) {
3346+
if (contextToken.parent.kind === SyntaxKind.JsxOpeningElement) {
3347+
return true;
3348+
}
3349+
3350+
if (contextToken.parent.kind === SyntaxKind.JsxClosingElement || contextToken.parent.kind === SyntaxKind.JsxSelfClosingElement) {
3351+
return contextToken.parent.parent && contextToken.parent.parent.kind === SyntaxKind.JsxElement;
3352+
}
3353+
}
3354+
return false;
3355+
}
3356+
33263357
function isNewIdentifierDefinitionLocation(previousToken: Node): boolean {
33273358
if (previousToken) {
33283359
let containingNodeKind = previousToken.parent.kind;

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ module FourSlashInterface {
212212
// Verifies the completion list items count to be greater than the specified amount. The
213213
// completion list is brought up if necessary
214214
public completionListItemsCountIsGreaterThan(count: number) {
215-
FourSlash.currentTestState.verifyCompletionListItemsCountIsGreaterThan(count);
215+
FourSlash.currentTestState.verifyCompletionListItemsCountIsGreaterThan(count, this.negative);
216216
}
217217

218218
public completionListIsEmpty() {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
//// declare module JSX {
5+
//// interface Element { }
6+
//// interface IntrinsicElements {
7+
//// div: { ONE: string; TWO: number; }
8+
//// }
9+
//// }
10+
//// var x1 = <div><//**/
11+
12+
goTo.marker();
13+
verify.memberListCount(1);
14+
verify.completionListContains('div');
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
//// declare module JSX {
5+
//// interface Element { }
6+
//// interface IntrinsicElements {
7+
//// div: { ONE: string; TWO: number; }
8+
//// }
9+
//// }
10+
//// var x1 = <div> /*1*/ hello /*2*/ world /*3*/</div>;
11+
//// var x2 = <div> /*4*/ <div></div> /*5*/ world /*6*/</div>;
12+
//// var x3 = <div>/*7*/<div/>/*8*/world/*9*/</div>;
13+
//// var x4 = <div>/*10*/</div>;
14+
//// <div/>
15+
//// /*end*/
16+
////
17+
18+
for (var i = 1; i <= 10; i++) {
19+
goTo.marker(i + '');
20+
verify.completionListIsEmpty();
21+
}
22+
23+
goTo.marker('end');
24+
verify.not.completionListIsEmpty();

0 commit comments

Comments
 (0)