From 6f432d9a68cf1fc9396b97d35c4d25e07582765b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 30 Jun 2025 11:24:36 +0200 Subject: [PATCH] Fixed crash on `ConstructSignature` when computing interactive inlay hints --- src/services/inlayHints.ts | 10 +++ .../inlayHintsVariableTypes3.baseline | 69 +++++++++++++++++++ .../fourslash/inlayHintsVariableTypes3.ts | 20 ++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/baselines/reference/inlayHintsVariableTypes3.baseline create mode 100644 tests/cases/fourslash/inlayHintsVariableTypes3.ts diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index d79def836396d..7c84d533443f5 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -44,6 +44,7 @@ import { isCallSignatureDeclaration, isConditionalTypeNode, isConstructorTypeNode, + isConstructSignatureDeclaration, isEnumMember, isExpressionWithTypeArguments, isFunctionDeclaration, @@ -825,6 +826,15 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] { visitForDisplayParts(node.type); } break; + case SyntaxKind.ConstructSignature: + Debug.assertNode(node, isConstructSignatureDeclaration); + parts.push({ text: "new " }); + visitParametersAndTypeParameters(node); + if (node.type) { + parts.push({ text: ": " }); + visitForDisplayParts(node.type); + } + break; case SyntaxKind.ArrayBindingPattern: Debug.assertNode(node, isArrayBindingPattern); parts.push({ text: "[" }); diff --git a/tests/baselines/reference/inlayHintsVariableTypes3.baseline b/tests/baselines/reference/inlayHintsVariableTypes3.baseline new file mode 100644 index 0000000000000..9b43534d8c51c --- /dev/null +++ b/tests/baselines/reference/inlayHintsVariableTypes3.baseline @@ -0,0 +1,69 @@ +// === Inlay Hints === +const div = getCtor("div"); + ^ +{ + "text": "", + "displayParts": [ + { + "text": ": " + }, + { + "text": "{" + }, + { + "text": " " + }, + { + "text": "new " + }, + { + "text": "(" + }, + { + "text": ")" + }, + { + "text": ": " + }, + { + "text": "DivElement", + "span": { + "start": 10, + "length": 10 + }, + "file": "/tests/cases/fourslash/inlayHintsVariableTypes3.ts" + }, + { + "text": "; " + }, + { + "text": "prototype" + }, + { + "text": ": " + }, + { + "text": "DivElement", + "span": { + "start": 10, + "length": 10 + }, + "file": "/tests/cases/fourslash/inlayHintsVariableTypes3.ts" + }, + { + "text": " " + }, + { + "text": "}" + }, + { + "text": " | " + }, + { + "text": "undefined" + } + ], + "position": 260, + "kind": "Type", + "whitespaceBefore": true +} \ No newline at end of file diff --git a/tests/cases/fourslash/inlayHintsVariableTypes3.ts b/tests/cases/fourslash/inlayHintsVariableTypes3.ts new file mode 100644 index 0000000000000..87c15a601089b --- /dev/null +++ b/tests/cases/fourslash/inlayHintsVariableTypes3.ts @@ -0,0 +1,20 @@ +/// + +// @strict: true +// @target: esnext + +//// interface DivElement {} +//// declare var DivElementCtor: { +//// prototype: DivElement; +//// new(): DivElement; +//// }; +//// interface ElementMap { +//// div: typeof DivElementCtor; +//// } +//// declare function getCtor(tagName: K): ElementMap[K] | undefined; +//// const div = getCtor("div"); + +verify.baselineInlayHints(undefined, { + includeInlayVariableTypeHints: true, + interactiveInlayHints: true +});