From c794fd0bfb53868c002840ddbe1db40ff26748ef Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 23 Aug 2021 23:18:25 +0000 Subject: [PATCH 1/2] Only provide hints for simple literals when 'literals' is specified. --- src/services/inlayHints.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index b37a9be01c2a0..404e1232c77ca 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -156,7 +156,7 @@ namespace ts.InlayHints { for (let i = 0; i < args.length; ++i) { const originalArg = args[i]; const arg = skipParentheses(originalArg); - if (shouldShowLiteralParameterNameHintsOnly(preferences) && !isHintableExpression(arg)) { + if (shouldShowLiteralParameterNameHintsOnly(preferences) && !isHintableLiteral(arg)) { continue; } @@ -202,7 +202,7 @@ namespace ts.InlayHints { return some(ranges, range => regex.test(sourceFileText.substring(range.pos, range.end))); } - function isHintableExpression(node: Node) { + function isHintableLiteral(node: Node) { switch (node.kind) { case SyntaxKind.PrefixUnaryExpression: { const operand = (node as PrefixUnaryExpression).operand; @@ -210,10 +210,6 @@ namespace ts.InlayHints { } case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.NullKeyword: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.TemplateExpression: From 3875dbb2240f34f8334f606c78bb35cf9c07ccce Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 23 Aug 2021 23:18:38 +0000 Subject: [PATCH 2/2] Update fourslash tests. --- tests/cases/fourslash/inlayHintsShouldWork12.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork29.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork34.ts | 6 ------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/cases/fourslash/inlayHintsShouldWork12.ts b/tests/cases/fourslash/inlayHintsShouldWork12.ts index 8414ca08c97e0..0d2471eb6c828 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork12.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork12.ts @@ -21,5 +21,5 @@ verify.getInlayHints([ whitespaceAfter: true }, ], undefined, { - includeInlayParameterNameHints: "literals" + includeInlayParameterNameHints: "all" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork29.ts b/tests/cases/fourslash/inlayHintsShouldWork29.ts index f371e2c552633..5eb157d582351 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork29.ts @@ -32,6 +32,6 @@ verify.getInlayHints([ whitespaceBefore: true } ], undefined, { - includeInlayParameterNameHints: "literals", + includeInlayParameterNameHints: "all", includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork34.ts b/tests/cases/fourslash/inlayHintsShouldWork34.ts index 6c5f87a78340f..8aa03a8d4af6e 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork34.ts @@ -5,12 +5,6 @@ //// foo(/*a*/1); //// foo(/*b*/''); //// foo(/*c*/true); -//// foo(/*d*/() => 1); -//// foo(/*e*/function () { return 1 }); -//// foo(/*f*/{}); -//// foo(/*g*/{ a: 1 }); -//// foo(/*h*/[]); -//// foo(/*i*/[1]); //// foo(foo); //// foo(/*j*/(1));