Skip to content

Commit 24334b5

Browse files
committed
Only show the opening tag name when completing a close tag
Fixes microsoft#5096
1 parent 1e708b4 commit 24334b5

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎src/services/services.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,6 +3105,7 @@ namespace ts {
31053105
let node = currentToken;
31063106
let isRightOfDot = false;
31073107
let isRightOfOpenTag = false;
3108+
let isStartingCloseTag = false;
31083109

31093110
let location = getTouchingPropertyName(sourceFile, position);
31103111
if (contextToken) {
@@ -3130,9 +3131,14 @@ namespace ts {
31303131
return undefined;
31313132
}
31323133
}
3133-
else if (kind === SyntaxKind.LessThanToken && sourceFile.languageVariant === LanguageVariant.JSX) {
3134-
isRightOfOpenTag = true;
3135-
location = contextToken;
3134+
else if (sourceFile.languageVariant === LanguageVariant.JSX) {
3135+
if (kind === SyntaxKind.LessThanToken) {
3136+
isRightOfOpenTag = true;
3137+
location = contextToken;
3138+
}
3139+
else if (kind === SyntaxKind.SlashToken && contextToken.parent.kind === SyntaxKind.JsxClosingElement) {
3140+
isStartingCloseTag = true;
3141+
}
31363142
}
31373143
}
31383144

@@ -3155,6 +3161,13 @@ namespace ts {
31553161
isMemberCompletion = true;
31563162
isNewIdentifierLocation = false;
31573163
}
3164+
else if (isStartingCloseTag) {
3165+
let tagName = (<JsxElement>contextToken.parent.parent).openingElement.tagName;
3166+
symbols = [typeChecker.getSymbolAtLocation(tagName)];
3167+
3168+
isMemberCompletion = true;
3169+
isNewIdentifierLocation = false;
3170+
}
31583171
else {
31593172
// For JavaScript or TypeScript, if we're not after a dot, then just try to get the
31603173
// global symbols in scope. These results should be valid for either language as
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.completionListItemsCountIsGreaterThan(0);
14+
verify.not.completionListItemsCountIsGreaterThan(1);
15+
verify.completionListContains('div');

0 commit comments

Comments
 (0)