From f224b5022e543703fbf9a0d3bf308f3ce5786b7d Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Fri, 31 Jul 2015 00:36:47 -0700 Subject: [PATCH 1/2] Offer JSX attribute intellisense between string-literal props and the closing tag. Fixes #4098 --- src/services/services.ts | 18 +++++++++++++----- tests/cases/fourslash/tsxCompletion6.ts | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/tsxCompletion6.ts diff --git a/src/services/services.ts b/src/services/services.ts index 8e670268498..49490756470 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3392,16 +3392,24 @@ namespace ts { case SyntaxKind.LessThanSlashToken: case SyntaxKind.SlashToken: case SyntaxKind.Identifier: - if(parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { + case SyntaxKind.JsxAttribute: + if (parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { return parent; } break; + // The context token is the closing } or " of an attribute, which means + // its parent is a JsxExpression, whose parent is a JsxAttribute, + // whose parent is a JsxOpeningLikeElement + case SyntaxKind.StringLiteral: + if (parent && parent.kind === SyntaxKind.JsxAttribute) { + return parent.parent; + } + + break; + case SyntaxKind.CloseBraceToken: - // The context token is the closing } of an attribute, which means - // its parent is a JsxExpression, whose parent is a JsxAttribute, - // whose parent is a JsxOpeningLikeElement - if(parent && + if (parent && parent.kind === SyntaxKind.JsxExpression && parent.parent && parent.parent.kind === SyntaxKind.JsxAttribute) { diff --git a/tests/cases/fourslash/tsxCompletion6.ts b/tests/cases/fourslash/tsxCompletion6.ts new file mode 100644 index 00000000000..5bb01717be7 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion6.ts @@ -0,0 +1,15 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// var x =
; + +goTo.marker(); + +verify.completionListContains("TWO"); +verify.not.completionListAllowsNewIdentifier(); From a45e9a91bf92d04230bb6d50a8a8e5d9c5fa7e9f Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Fri, 31 Jul 2015 14:05:43 -0700 Subject: [PATCH 2/2] Also fix the case where we are to the right of a spread expr --- src/services/services.ts | 9 +++++++-- tests/cases/fourslash/tsxCompletion7.ts | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/tsxCompletion7.ts diff --git a/src/services/services.ts b/src/services/services.ts index 49490756470..72b4b617b3a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3393,6 +3393,7 @@ namespace ts { case SyntaxKind.SlashToken: case SyntaxKind.Identifier: case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxSpreadAttribute: if (parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { return parent; } @@ -3402,7 +3403,7 @@ namespace ts { // its parent is a JsxExpression, whose parent is a JsxAttribute, // whose parent is a JsxOpeningLikeElement case SyntaxKind.StringLiteral: - if (parent && parent.kind === SyntaxKind.JsxAttribute) { + if (parent && ((parent.kind === SyntaxKind.JsxAttribute) || (parent.kind === SyntaxKind.JsxSpreadAttribute))) { return parent.parent; } @@ -3412,11 +3413,15 @@ namespace ts { if (parent && parent.kind === SyntaxKind.JsxExpression && parent.parent && - parent.parent.kind === SyntaxKind.JsxAttribute) { + (parent.parent.kind === SyntaxKind.JsxAttribute)) { return parent.parent.parent; } + if (parent && parent.kind === SyntaxKind.JsxSpreadAttribute) { + return parent.parent; + } + break; } } diff --git a/tests/cases/fourslash/tsxCompletion7.ts b/tests/cases/fourslash/tsxCompletion7.ts new file mode 100644 index 00000000000..ca489b8e0c4 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion7.ts @@ -0,0 +1,17 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// let y = { ONE: '' }; +//// var x =
; + +goTo.marker(); + +verify.completionListContains("ONE"); +verify.completionListContains("TWO"); +verify.not.completionListAllowsNewIdentifier();