Merge pull request #21895 from Microsoft/jsxTagCompletion
Fix completion of jsx attributes in self closing element
This commit is contained in:
commit
2305f7b22a
3 changed files with 50 additions and 4 deletions
|
@ -862,6 +862,23 @@ namespace ts.Completions {
|
|||
parent = parent.parent;
|
||||
}
|
||||
|
||||
// Fix location
|
||||
if (currentToken.parent === location) {
|
||||
switch (currentToken.kind) {
|
||||
case SyntaxKind.GreaterThanToken:
|
||||
if (currentToken.parent.kind === SyntaxKind.JsxElement || currentToken.parent.kind === SyntaxKind.JsxOpeningElement) {
|
||||
location = currentToken;
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.SlashToken:
|
||||
if (currentToken.parent.kind === SyntaxKind.JsxSelfClosingElement) {
|
||||
location = currentToken;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
if (contextToken.kind === SyntaxKind.SlashToken) {
|
||||
|
@ -1042,10 +1059,6 @@ namespace ts.Completions {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (tryGetFunctionLikeBodyCompletionContainer(contextToken)) {
|
||||
keywordFilters = KeywordCompletionFilters.FunctionLikeBodyKeywords;
|
||||
}
|
||||
|
||||
if (classLikeContainer = tryGetClassLikeCompletionContainer(contextToken)) {
|
||||
// cursor inside class declaration
|
||||
getGetClassLikeCompletionSymbols(classLikeContainer);
|
||||
|
@ -1067,6 +1080,10 @@ namespace ts.Completions {
|
|||
}
|
||||
}
|
||||
|
||||
if (tryGetFunctionLikeBodyCompletionContainer(contextToken)) {
|
||||
keywordFilters = KeywordCompletionFilters.FunctionLikeBodyKeywords;
|
||||
}
|
||||
|
||||
// Get all entities in the current scope.
|
||||
completionKind = CompletionKind.None;
|
||||
isNewIdentifierLocation = isNewIdentifierDefinitionLocation(contextToken);
|
||||
|
|
|
@ -79,6 +79,8 @@ namespace ts.SymbolDisplay {
|
|||
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:
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
return location.kind === SyntaxKind.Identifier ? ScriptElementKind.memberVariableElement : ScriptElementKind.jsxAttribute;
|
||||
case SyntaxKind.JsxAttribute:
|
||||
return ScriptElementKind.jsxAttribute;
|
||||
|
|
27
tests/cases/fourslash/completionsInJsxTag.ts
Normal file
27
tests/cases/fourslash/completionsInJsxTag.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @jsx: preserve
|
||||
|
||||
// @Filename: /a.tsx
|
||||
////declare namespace JSX {
|
||||
//// interface Element {}
|
||||
//// interface IntrinsicElements {
|
||||
//// div: {
|
||||
//// /** Doc */
|
||||
//// foo: string
|
||||
//// }
|
||||
//// }
|
||||
////}
|
||||
////class Foo {
|
||||
//// render() {
|
||||
//// <div /*1*/ ></div>;
|
||||
//// <div /*2*/ />
|
||||
//// }
|
||||
////}
|
||||
|
||||
goTo.marker("1");
|
||||
verify.completionListCount(1);
|
||||
verify.completionListContains("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute");
|
||||
goTo.marker("2");
|
||||
verify.completionListCount(1);
|
||||
verify.completionListContains("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute");
|
Loading…
Reference in a new issue