mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Supress hints for access expr too (#45121)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
Reference in New Issue
Block a user