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.
This commit is contained in:
Andy 2017-11-06 19:14:24 -08:00 committed by GitHub
parent 3f248ecfe1
commit 6d273cfb33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -75,10 +75,16 @@ namespace ts.SymbolDisplay {
}
return unionPropertyKind;
}
if (location.parent && isJsxAttribute(location.parent)) {
return ScriptElementKind.jsxAttribute;
// If we requested completions after `x.` at the top-level, we may be at a source file location.
switch (location.parent && location.parent.kind) {
// If we've typed a character of the attribute name, will be 'JsxAttribute', else will be 'JsxOpeningElement'.
case SyntaxKind.JsxOpeningElement:
return location.kind === SyntaxKind.Identifier ? ScriptElementKind.memberVariableElement : ScriptElementKind.jsxAttribute;
case SyntaxKind.JsxAttribute:
return ScriptElementKind.jsxAttribute;
default:
return ScriptElementKind.memberVariableElement;
}
return ScriptElementKind.memberVariableElement;
}
return ScriptElementKind.unknown;

View File

@ -0,0 +1,22 @@
/// <reference path="fourslash.ts" />
// @jsx: preserve
// @Filename: /a.tsx
////declare namespace JSX {
//// interface Element {}
//// interface IntrinsicElements {
//// div: {
//// /** Doc */
//// foo: string
//// }
//// }
////}
////
////<div /**/></div>;
goTo.marker();
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute", []);
edit.insert("f");
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute", []);