Skip to content

Commit 6d273cf

Browse files
author
Andy
authored
Consistently use "JSX Attribute" completion kind (#19781)
* Consistently use "JSX Attribute" completion kind * Update tests and fix bug * Fix bug: In a JsxOpeningElement, if at an Identifier we are not at an attribute but at the tag itself. If at a GreaterThanToken, we are about to fill in an attribute.
1 parent 3f248ec commit 6d273cf

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/services/symbolDisplay.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ namespace ts.SymbolDisplay {
7575
}
7676
return unionPropertyKind;
7777
}
78-
if (location.parent && isJsxAttribute(location.parent)) {
79-
return ScriptElementKind.jsxAttribute;
78+
// If we requested completions after `x.` at the top-level, we may be at a source file location.
79+
switch (location.parent && location.parent.kind) {
80+
// If we've typed a character of the attribute name, will be 'JsxAttribute', else will be 'JsxOpeningElement'.
81+
case SyntaxKind.JsxOpeningElement:
82+
return location.kind === SyntaxKind.Identifier ? ScriptElementKind.memberVariableElement : ScriptElementKind.jsxAttribute;
83+
case SyntaxKind.JsxAttribute:
84+
return ScriptElementKind.jsxAttribute;
85+
default:
86+
return ScriptElementKind.memberVariableElement;
8087
}
81-
return ScriptElementKind.memberVariableElement;
8288
}
8389

8490
return ScriptElementKind.unknown;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @jsx: preserve
4+
5+
// @Filename: /a.tsx
6+
////declare namespace JSX {
7+
//// interface Element {}
8+
//// interface IntrinsicElements {
9+
//// div: {
10+
//// /** Doc */
11+
//// foo: string
12+
//// }
13+
//// }
14+
////}
15+
////
16+
////<div /**/></div>;
17+
18+
goTo.marker();
19+
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute", []);
20+
edit.insert("f");
21+
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute", []);
22+

0 commit comments

Comments
 (0)