Skip to content

Commit 5719423

Browse files
Only provide hints for simple literals when 'literals' is specified. (microsoft#45557)
* Only provide hints for simple literals when 'literals' is specified. * Update fourslash tests.
1 parent d2a46a0 commit 5719423

File tree

4 files changed

+4
-14
lines changed

4 files changed

+4
-14
lines changed

src/services/inlayHints.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace ts.InlayHints {
156156
for (let i = 0; i < args.length; ++i) {
157157
const originalArg = args[i];
158158
const arg = skipParentheses(originalArg);
159-
if (shouldShowLiteralParameterNameHintsOnly(preferences) && !isHintableExpression(arg)) {
159+
if (shouldShowLiteralParameterNameHintsOnly(preferences) && !isHintableLiteral(arg)) {
160160
continue;
161161
}
162162

@@ -202,18 +202,14 @@ namespace ts.InlayHints {
202202
return some(ranges, range => regex.test(sourceFileText.substring(range.pos, range.end)));
203203
}
204204

205-
function isHintableExpression(node: Node) {
205+
function isHintableLiteral(node: Node) {
206206
switch (node.kind) {
207207
case SyntaxKind.PrefixUnaryExpression: {
208208
const operand = (node as PrefixUnaryExpression).operand;
209209
return isLiteralExpression(operand) || isIdentifier(operand) && isInfinityOrNaNString(operand.escapedText);
210210
}
211211
case SyntaxKind.TrueKeyword:
212212
case SyntaxKind.FalseKeyword:
213-
case SyntaxKind.ArrowFunction:
214-
case SyntaxKind.FunctionExpression:
215-
case SyntaxKind.ObjectLiteralExpression:
216-
case SyntaxKind.ArrayLiteralExpression:
217213
case SyntaxKind.NullKeyword:
218214
return true;
219215
case SyntaxKind.Identifier: {

tests/cases/fourslash/inlayHintsShouldWork12.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ verify.getInlayHints([
2121
whitespaceAfter: true
2222
},
2323
], undefined, {
24-
includeInlayParameterNameHints: "literals"
24+
includeInlayParameterNameHints: "all"
2525
});

tests/cases/fourslash/inlayHintsShouldWork29.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ verify.getInlayHints([
3232
whitespaceBefore: true
3333
}
3434
], undefined, {
35-
includeInlayParameterNameHints: "literals",
35+
includeInlayParameterNameHints: "all",
3636
includeInlayFunctionParameterTypeHints: true
3737
});

tests/cases/fourslash/inlayHintsShouldWork34.ts

-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
//// foo(/*a*/1);
66
//// foo(/*b*/'');
77
//// foo(/*c*/true);
8-
//// foo(/*d*/() => 1);
9-
//// foo(/*e*/function () { return 1 });
10-
//// foo(/*f*/{});
11-
//// foo(/*g*/{ a: 1 });
12-
//// foo(/*h*/[]);
13-
//// foo(/*i*/[1]);
148

159
//// foo(foo);
1610
//// foo(/*j*/(1));

0 commit comments

Comments
 (0)