Skip to content

Commit

Permalink
Only provide hints for simple literals when 'literals' is specified. (#…
Browse files Browse the repository at this point in the history
…45557)

* Only provide hints for simple literals when 'literals' is specified.

* Update fourslash tests.
  • Loading branch information
DanielRosenwasser committed Aug 23, 2021
1 parent d2a46a0 commit 5719423
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/services/inlayHints.ts
Expand Up @@ -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;
}

Expand Down Expand Up @@ -202,18 +202,14 @@ 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;
return isLiteralExpression(operand) || isIdentifier(operand) && isInfinityOrNaNString(operand.escapedText);
}
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: {
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/fourslash/inlayHintsShouldWork12.ts
Expand Up @@ -21,5 +21,5 @@ verify.getInlayHints([
whitespaceAfter: true
},
], undefined, {
includeInlayParameterNameHints: "literals"
includeInlayParameterNameHints: "all"
});
2 changes: 1 addition & 1 deletion tests/cases/fourslash/inlayHintsShouldWork29.ts
Expand Up @@ -32,6 +32,6 @@ verify.getInlayHints([
whitespaceBefore: true
}
], undefined, {
includeInlayParameterNameHints: "literals",
includeInlayParameterNameHints: "all",
includeInlayFunctionParameterTypeHints: true
});
6 changes: 0 additions & 6 deletions tests/cases/fourslash/inlayHintsShouldWork34.ts
Expand Up @@ -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));
Expand Down

0 comments on commit 5719423

Please sign in to comment.