fix(60375): adjust parameter positions when an explicit this declaration is present
This commit is contained in:
Родитель
21618934bf
Коммит
1625ce570b
|
@ -103,6 +103,7 @@ import {
|
|||
NodeArray,
|
||||
NodeBuilderFlags,
|
||||
ParameterDeclaration,
|
||||
parameterIsThisKeyword,
|
||||
PrefixUnaryExpression,
|
||||
PropertyDeclaration,
|
||||
QuotePreference,
|
||||
|
@ -437,26 +438,28 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
|
|||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < node.parameters.length && i < signature.parameters.length; ++i) {
|
||||
const param = node.parameters[i];
|
||||
if (!isHintableDeclaration(param)) {
|
||||
continue;
|
||||
let pos = 0;
|
||||
for (const param of node.parameters) {
|
||||
if (isHintableDeclaration(param)) {
|
||||
addParameterTypeHint(param, parameterIsThisKeyword(param) ? signature.thisParameter : signature.parameters[pos]);
|
||||
if (parameterIsThisKeyword(param)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(param);
|
||||
if (effectiveTypeAnnotation) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const typeHints = getParameterDeclarationTypeHints(signature.parameters[i]);
|
||||
if (!typeHints) {
|
||||
continue;
|
||||
}
|
||||
|
||||
addTypeHints(typeHints, param.questionToken ? param.questionToken.end : param.name.end);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
function addParameterTypeHint(node: ParameterDeclaration, symbol: Symbol | undefined) {
|
||||
const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(node);
|
||||
if (effectiveTypeAnnotation || symbol === undefined) return;
|
||||
|
||||
const typeHints = getParameterDeclarationTypeHints(symbol);
|
||||
if (typeHints === undefined) return;
|
||||
|
||||
addTypeHints(typeHints, node.questionToken ? node.questionToken.end : node.name.end);
|
||||
}
|
||||
|
||||
function getParameterDeclarationTypeHints(symbol: Symbol) {
|
||||
const valueDeclaration = symbol.valueDeclaration;
|
||||
if (!valueDeclaration || !isParameter(valueDeclaration)) {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// === Inlay Hints ===
|
||||
fn(function (this, a, b) { });
|
||||
^
|
||||
{
|
||||
"text": ": any",
|
||||
"position": 126,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
|
||||
fn(function (this, a, b) { });
|
||||
^
|
||||
{
|
||||
"text": ": number",
|
||||
"position": 129,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
|
||||
fn(function (this, a, b) { });
|
||||
^
|
||||
{
|
||||
"text": ": string",
|
||||
"position": 132,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
|
||||
fn(function (this: I, a, b) { });
|
||||
^
|
||||
{
|
||||
"text": ": number",
|
||||
"position": 163,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
|
||||
fn(function (this: I, a, b) { });
|
||||
^
|
||||
{
|
||||
"text": ": string",
|
||||
"position": 166,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////interface I {
|
||||
//// a: number;
|
||||
////}
|
||||
////
|
||||
////declare function fn(
|
||||
//// callback: (a: number, b: string) => void
|
||||
////): void;
|
||||
////
|
||||
////
|
||||
////fn(function (this, a, b) { });
|
||||
////fn(function (this: I, a, b) { });
|
||||
|
||||
verify.baselineInlayHints(undefined, {
|
||||
includeInlayFunctionParameterTypeHints: true,
|
||||
});
|
Загрузка…
Ссылка в новой задаче