Skip to content

Commit 9665bc6

Browse files
authored
Supress hints for access expr too (microsoft#45121)
1 parent 11c7dae commit 9665bc6

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/services/inlayHints.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace ts.InlayHints {
163163
const identifierNameInfo = checker.getParameterIdentifierNameAtPosition(signature, i);
164164
if (identifierNameInfo) {
165165
const [parameterName, isFirstVariadicArgument] = identifierNameInfo;
166-
const isParameterNameNotSameAsArgument = preferences.includeInlayParameterNameHintsWhenArgumentMatchesName || !isIdentifier(arg) || arg.text !== parameterName;
166+
const isParameterNameNotSameAsArgument = preferences.includeInlayParameterNameHintsWhenArgumentMatchesName || !identifierOrAccessExpressionPostfixMatchesParameterName(arg, parameterName);
167167
if (!isParameterNameNotSameAsArgument && !isFirstVariadicArgument) {
168168
continue;
169169
}
@@ -178,6 +178,16 @@ namespace ts.InlayHints {
178178
}
179179
}
180180

181+
function identifierOrAccessExpressionPostfixMatchesParameterName(expr: Expression, parameterName: __String) {
182+
if (isIdentifier(expr)) {
183+
return expr.text === parameterName;
184+
}
185+
if (isPropertyAccessExpression(expr)) {
186+
return expr.name.text === parameterName;
187+
}
188+
return false;
189+
}
190+
181191
function leadingCommentsContainsParameterName(node: Node, name: string) {
182192
if (!isIdentifierText(name, compilerOptions.target, getLanguageVariant(file.scriptKind))) {
183193
return false;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// function foo (a: number, b: number) {}
4+
//// declare const a: 1;
5+
//// foo(a, /*b*/2);
6+
//// declare const v: any;
7+
//// foo(v.a, /*c*/v.a);
8+
//// foo(/*d*/v.b, v.b);
9+
//// foo(/*e*/v.c, /*f*/v.c);
10+
11+
const markers = test.markers();
12+
verify.getInlayHints([
13+
{
14+
text: 'b:',
15+
position: markers[0].position,
16+
kind: ts.InlayHintKind.Parameter,
17+
whitespaceAfter: true
18+
},
19+
{
20+
text: 'b:',
21+
position: markers[1].position,
22+
kind: ts.InlayHintKind.Parameter,
23+
whitespaceAfter: true
24+
},
25+
{
26+
text: 'a:',
27+
position: markers[2].position,
28+
kind: ts.InlayHintKind.Parameter,
29+
whitespaceAfter: true
30+
},
31+
{
32+
text: 'a:',
33+
position: markers[3].position,
34+
kind: ts.InlayHintKind.Parameter,
35+
whitespaceAfter: true
36+
},
37+
{
38+
text: 'b:',
39+
position: markers[4].position,
40+
kind: ts.InlayHintKind.Parameter,
41+
whitespaceAfter: true
42+
},
43+
], undefined, {
44+
includeInlayParameterNameHints: "all",
45+
includeInlayParameterNameHintsWhenArgumentMatchesName: false,
46+
});

0 commit comments

Comments
 (0)