fix(60375): Parameter inlay hint is incorrect when function has a this type (#60378)

This commit is contained in:
Oleksandr T.
2025-01-17 23:30:35 +02:00
committed by GitHub
parent 5170645f4e
commit 589f734e5e
3 changed files with 80 additions and 15 deletions

View File

@@ -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)) {
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)) {