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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃 Pick PR #45399 (fix(45393): show parameter name hin...) into release-4.4 #45404

Merged
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
13 changes: 12 additions & 1 deletion src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,18 @@ namespace ts.InlayHints {
}

function isHintableExpression(node: Node) {
return isLiteralExpression(node) || isBooleanLiteral(node) || isArrowFunction(node) || isFunctionExpression(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node);
switch (node.kind) {
case SyntaxKind.PrefixUnaryExpression:
return isLiteralExpression((node as PrefixUnaryExpression).operand);
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.ArrowFunction:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.ArrayLiteralExpression:
return true;
}
return isLiteralExpression(node);
}

function visitFunctionDeclarationLikeForReturnType(decl: FunctionDeclaration | ArrowFunction | FunctionExpression | MethodDeclaration | GetAccessorDeclaration) {
Expand Down
34 changes: 34 additions & 0 deletions tests/cases/fourslash/inlayHintsShouldWork63.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />

////function foo(a: number, b: number, c: number, d: number) {}
////foo(/*a*/1, /*b*/+1, /*c*/-1, /*d*/+"1");

const [a, b, c, d] = test.markers();
verify.getInlayHints([
{
text: "a:",
position: a.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "b:",
position: b.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "c:",
position: c.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "d:",
position: d.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
}
], undefined, {
includeInlayParameterNameHints: "literals"
});