Skip to content

Commit c82ccf1

Browse files
TypeScript Bota-tarasyuk
TypeScript Bot
andauthored
Cherry-pick PR #45399 into release-4.4 (#45404)
Component commits: f7af8f4 fix(45393): show parameter name hints for unary literal expressions Co-authored-by: Oleksandr T <[email protected]>
1 parent 0648de8 commit c82ccf1

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/services/inlayHints.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,18 @@ namespace ts.InlayHints {
203203
}
204204

205205
function isHintableExpression(node: Node) {
206-
return isLiteralExpression(node) || isBooleanLiteral(node) || isArrowFunction(node) || isFunctionExpression(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node);
206+
switch (node.kind) {
207+
case SyntaxKind.PrefixUnaryExpression:
208+
return isLiteralExpression((node as PrefixUnaryExpression).operand);
209+
case SyntaxKind.TrueKeyword:
210+
case SyntaxKind.FalseKeyword:
211+
case SyntaxKind.ArrowFunction:
212+
case SyntaxKind.FunctionExpression:
213+
case SyntaxKind.ObjectLiteralExpression:
214+
case SyntaxKind.ArrayLiteralExpression:
215+
return true;
216+
}
217+
return isLiteralExpression(node);
207218
}
208219

209220
function visitFunctionDeclarationLikeForReturnType(decl: FunctionDeclaration | ArrowFunction | FunctionExpression | MethodDeclaration | GetAccessorDeclaration) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function foo(a: number, b: number, c: number, d: number) {}
4+
////foo(/*a*/1, /*b*/+1, /*c*/-1, /*d*/+"1");
5+
6+
const [a, b, c, d] = test.markers();
7+
verify.getInlayHints([
8+
{
9+
text: "a:",
10+
position: a.position,
11+
kind: ts.InlayHintKind.Parameter,
12+
whitespaceAfter: true
13+
},
14+
{
15+
text: "b:",
16+
position: b.position,
17+
kind: ts.InlayHintKind.Parameter,
18+
whitespaceAfter: true
19+
},
20+
{
21+
text: "c:",
22+
position: c.position,
23+
kind: ts.InlayHintKind.Parameter,
24+
whitespaceAfter: true
25+
},
26+
{
27+
text: "d:",
28+
position: d.position,
29+
kind: ts.InlayHintKind.Parameter,
30+
whitespaceAfter: true
31+
}
32+
], undefined, {
33+
includeInlayParameterNameHints: "literals"
34+
});

0 commit comments

Comments
 (0)