Skip to content

Commit

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

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

* Update fourslash tests.
  • Loading branch information
DanielRosenwasser authored and BobobUnicorn committed Oct 23, 2021
1 parent 241f875 commit 25d024f
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
Original file line number Diff line number Diff line change
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.FunctionExpression:
case SyntaxKind.ArrowFunction:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.NullKeyword:
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.TemplateExpression:
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/fourslash/inlayHintsShouldWork12.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 25d024f

Please sign in to comment.