Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only provide hints for simple literals when 'literals' is specified. #45557

Merged
merged 2 commits into from Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.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
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]);
Comment on lines -8 to -13
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inlayHintsShouldWork35 covers the all case.


//// foo(foo);
//// foo(/*j*/(1));
Expand Down