From 31d721d60eac2a70368071d7a6a048da5fe359a6 Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Fri, 17 Nov 2023 11:36:29 -0800 Subject: [PATCH] add index signature --- src/services/inlayHints.ts | 12 +++ ...nteractiveFunctionParameterTypes1.baseline | 79 ++++++++++++++++++- ...HintsInteractiveFunctionParameterTypes1.ts | 6 ++ 3 files changed, 93 insertions(+), 4 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index a36e4054911a1..3946d9a135e80 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -53,6 +53,7 @@ import { isIdentifierText, isImportTypeNode, isIndexedAccessTypeNode, + isIndexSignatureDeclaration, isInferTypeNode, isInfinityOrNaNString, isIntersectionTypeNode, @@ -743,6 +744,17 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] { visitForDisplayParts(node.type); } break; + case SyntaxKind.IndexSignature: + Debug.assertNode(node, isIndexSignatureDeclaration); + Debug.assertEqual(node.parameters.length, 1); + parts.push({ text: "[" }); + visitForDisplayParts(node.parameters[0]); + parts.push({ text: "]" }); + if (node.type) { + parts.push({ text: ": " }); + visitForDisplayParts(node.type); + } + break; case SyntaxKind.MethodSignature: Debug.assertNode(node, isMethodSignature); if (node.modifiers?.length) { diff --git a/tests/baselines/reference/inlayHintsInteractiveFunctionParameterTypes1.baseline b/tests/baselines/reference/inlayHintsInteractiveFunctionParameterTypes1.baseline index 4a36146628873..e845d97ca77e7 100644 --- a/tests/baselines/reference/inlayHintsInteractiveFunctionParameterTypes1.baseline +++ b/tests/baselines/reference/inlayHintsInteractiveFunctionParameterTypes1.baseline @@ -262,6 +262,30 @@ { "text": "; " }, + { + "text": "[" + }, + { + "text": "i" + }, + { + "text": ": " + }, + { + "text": "string" + }, + { + "text": "]" + }, + { + "text": ": " + }, + { + "text": "number" + }, + { + "text": "; " + }, { "text": "a" }, @@ -464,7 +488,7 @@ "text": "}" } ], - "position": 646, + "position": 671, "kind": "Type", "whitespaceBefore": true } @@ -490,7 +514,7 @@ "text": "42" } ], - "position": 716, + "position": 741, "kind": "Type", "whitespaceBefore": true } @@ -506,13 +530,60 @@ foo4(p => {}) { "text": "Thing", "span": { - "start": 735, + "start": 760, "length": 5 }, "file": "/tests/cases/fourslash/inlayHintsInteractiveFunctionParameterTypes1.ts" } ], - "position": 801, + "position": 826, + "kind": "Type", + "whitespaceBefore": true +} + + const foo5: F4 = (a) => { } + ^ +{ + "text": "", + "displayParts": [ + { + "text": ": " + }, + { + "text": "{" + }, + { + "text": " " + }, + { + "text": "[" + }, + { + "text": "x" + }, + { + "text": ": " + }, + { + "text": "string" + }, + { + "text": "]" + }, + { + "text": ": " + }, + { + "text": "number" + }, + { + "text": " " + }, + { + "text": "}" + } + ], + "position": 910, "kind": "Type", "whitespaceBefore": true } \ No newline at end of file diff --git a/tests/cases/fourslash/inlayHintsInteractiveFunctionParameterTypes1.ts b/tests/cases/fourslash/inlayHintsInteractiveFunctionParameterTypes1.ts index d9c668507aee8..ffca754c9361a 100644 --- a/tests/cases/fourslash/inlayHintsInteractiveFunctionParameterTypes1.ts +++ b/tests/cases/fourslash/inlayHintsInteractiveFunctionParameterTypes1.ts @@ -28,6 +28,7 @@ //// g(): T //// h?(x: X): Y //// (x: X): Y +//// [i: string]: number //// }) => void //// const foo5: F2 = (a) => { } @@ -41,6 +42,11 @@ ////function foo4(callback: (thing: Thing) => void) {} ////foo4(p => {}) +//// type F4 = (a: { +//// [i in string]: number +//// }) => void +//// const foo5: F4 = (a) => { } + verify.baselineInlayHints(undefined, { includeInlayFunctionParameterTypeHints: true, interactiveInlayHints: true,