Skip to content

Commit 3f7a8d5

Browse files
authored
fix(52828): No signature help in parameter declaration before , and ) (#52840)
1 parent 21db2ae commit 3f7a8d5

File tree

3 files changed

+1709
-7
lines changed

3 files changed

+1709
-7
lines changed

src/services/signatureHelp.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
emptyArray,
1717
Expression,
1818
factory,
19+
findAncestor,
1920
findContainingList,
2021
findIndex,
2122
findPrecedingToken,
@@ -30,7 +31,9 @@ import {
3031
Identifier,
3132
identity,
3233
InternalSymbolName,
34+
isArrayBindingPattern,
3335
isBinaryExpression,
36+
isBindingElement,
3437
isBlock,
3538
isCallOrNewExpression,
3639
isFunctionTypeNode,
@@ -41,6 +44,8 @@ import {
4144
isJsxOpeningLikeElement,
4245
isMethodDeclaration,
4346
isNoSubstitutionTemplateLiteral,
47+
isObjectBindingPattern,
48+
isParameter,
4449
isPropertyAccessExpression,
4550
isSourceFile,
4651
isSourceFileJS,
@@ -387,8 +392,11 @@ function countBinaryExpressionParameters(b: BinaryExpression): number {
387392
}
388393

389394
function tryGetParameterInfo(startingToken: Node, position: number, sourceFile: SourceFile, checker: TypeChecker): ArgumentListInfo | undefined {
390-
const info = getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker);
391-
if (!info) return undefined;
395+
const node = getAdjustedNode(startingToken);
396+
if (node === undefined) return undefined;
397+
398+
const info = getContextualSignatureLocationInfo(node, sourceFile, position, checker);
399+
if (info === undefined) return undefined;
392400
const { contextualType, argumentIndex, argumentCount, argumentsSpan } = info;
393401

394402
// for optional function condition.
@@ -404,24 +412,34 @@ function tryGetParameterInfo(startingToken: Node, position: number, sourceFile:
404412
return { isTypeParameterList: false, invocation, argumentsSpan, argumentIndex, argumentCount };
405413
}
406414

415+
function getAdjustedNode(node: Node) {
416+
switch (node.kind) {
417+
case SyntaxKind.OpenParenToken:
418+
case SyntaxKind.CommaToken:
419+
return node;
420+
default:
421+
return findAncestor(node.parent, n =>
422+
isParameter(n) ? true : isBindingElement(n) || isObjectBindingPattern(n) || isArrayBindingPattern(n) ? false : "quit");
423+
}
424+
}
425+
407426
interface ContextualSignatureLocationInfo { readonly contextualType: Type; readonly argumentIndex: number; readonly argumentCount: number; readonly argumentsSpan: TextSpan; }
408-
function getContextualSignatureLocationInfo(startingToken: Node, sourceFile: SourceFile, position: number, checker: TypeChecker): ContextualSignatureLocationInfo | undefined {
409-
if (startingToken.kind !== SyntaxKind.OpenParenToken && startingToken.kind !== SyntaxKind.CommaToken) return undefined;
410-
const { parent } = startingToken;
427+
function getContextualSignatureLocationInfo(node: Node, sourceFile: SourceFile, position: number, checker: TypeChecker): ContextualSignatureLocationInfo | undefined {
428+
const { parent } = node;
411429
switch (parent.kind) {
412430
case SyntaxKind.ParenthesizedExpression:
413431
case SyntaxKind.MethodDeclaration:
414432
case SyntaxKind.FunctionExpression:
415433
case SyntaxKind.ArrowFunction:
416-
const info = getArgumentOrParameterListInfo(startingToken, position, sourceFile);
434+
const info = getArgumentOrParameterListInfo(node, position, sourceFile);
417435
if (!info) return undefined;
418436
const { argumentIndex, argumentCount, argumentsSpan } = info;
419437
const contextualType = isMethodDeclaration(parent) ? checker.getContextualTypeForObjectLiteralElement(parent) : checker.getContextualType(parent as ParenthesizedExpression | FunctionExpression | ArrowFunction);
420438
return contextualType && { contextualType, argumentIndex, argumentCount, argumentsSpan };
421439
case SyntaxKind.BinaryExpression: {
422440
const highestBinary = getHighestBinary(parent as BinaryExpression);
423441
const contextualType = checker.getContextualType(highestBinary);
424-
const argumentIndex = startingToken.kind === SyntaxKind.OpenParenToken ? 0 : countBinaryExpressionParameters(parent as BinaryExpression) - 1;
442+
const argumentIndex = node.kind === SyntaxKind.OpenParenToken ? 0 : countBinaryExpressionParameters(parent as BinaryExpression) - 1;
425443
const argumentCount = countBinaryExpressionParameters(highestBinary);
426444
return contextualType && { contextualType, argumentIndex, argumentCount, argumentsSpan: createTextSpanFromNode(parent) };
427445
}

0 commit comments

Comments
 (0)