From 5719423aad482509270041b5dae0ae6697fae6b1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 23 Aug 2021 16:38:26 -0700 Subject: [PATCH] Only provide hints for simple literals when 'literals' is specified. (#45557) * Only provide hints for simple literals when 'literals' is specified. * Update fourslash tests. --- src/services/inlayHints.ts | 8 ++------ tests/cases/fourslash/inlayHintsShouldWork12.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork29.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork34.ts | 6 ------ 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 56930c169ae9b..b36cba380c505 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.ArrowFunction: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.NullKeyword: return true; case SyntaxKind.Identifier: { 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));