Supress hints for access expr too (#45121)

This commit is contained in:
Wenlu Wang
2021-07-26 11:59:14 -07:00
committed by GitHub
parent 11c7daef62
commit 9665bc6199
2 changed files with 57 additions and 1 deletions
+11 -1
View File
@@ -163,7 +163,7 @@ namespace ts.InlayHints {
const identifierNameInfo = checker.getParameterIdentifierNameAtPosition(signature, i);
if (identifierNameInfo) {
const [parameterName, isFirstVariadicArgument] = identifierNameInfo;
const isParameterNameNotSameAsArgument = preferences.includeInlayParameterNameHintsWhenArgumentMatchesName || !isIdentifier(arg) || arg.text !== parameterName;
const isParameterNameNotSameAsArgument = preferences.includeInlayParameterNameHintsWhenArgumentMatchesName || !identifierOrAccessExpressionPostfixMatchesParameterName(arg, parameterName);
if (!isParameterNameNotSameAsArgument && !isFirstVariadicArgument) {
continue;
}
@@ -178,6 +178,16 @@ namespace ts.InlayHints {
}
}
function identifierOrAccessExpressionPostfixMatchesParameterName(expr: Expression, parameterName: __String) {
if (isIdentifier(expr)) {
return expr.text === parameterName;
}
if (isPropertyAccessExpression(expr)) {
return expr.name.text === parameterName;
}
return false;
}
function leadingCommentsContainsParameterName(node: Node, name: string) {
if (!isIdentifierText(name, compilerOptions.target, getLanguageVariant(file.scriptKind))) {
return false;
@@ -0,0 +1,46 @@
/// <reference path="fourslash.ts" />
//// function foo (a: number, b: number) {}
//// declare const a: 1;
//// foo(a, /*b*/2);
//// declare const v: any;
//// foo(v.a, /*c*/v.a);
//// foo(/*d*/v.b, v.b);
//// foo(/*e*/v.c, /*f*/v.c);
const markers = test.markers();
verify.getInlayHints([
{
text: 'b:',
position: markers[0].position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: 'b:',
position: markers[1].position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: 'a:',
position: markers[2].position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: 'a:',
position: markers[3].position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: 'b:',
position: markers[4].position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
], undefined, {
includeInlayParameterNameHints: "all",
includeInlayParameterNameHintsWhenArgumentMatchesName: false,
});