@@ -169,12 +169,12 @@ namespace ts.SignatureHelp {
169
169
: { invocation : info . invocation . node , argumentCount : info . argumentCount , argumentIndex : info . argumentIndex } ;
170
170
}
171
171
172
- function getArgumentOrParameterListInfo ( node : Node , sourceFile : SourceFile ) : { readonly list : Node , readonly argumentIndex : number , readonly argumentCount : number , readonly argumentsSpan : TextSpan } | undefined {
172
+ function getArgumentOrParameterListInfo ( node : Node , position : number , sourceFile : SourceFile ) : { readonly list : Node , readonly argumentIndex : number , readonly argumentCount : number , readonly argumentsSpan : TextSpan } | undefined {
173
173
const info = getArgumentOrParameterListAndIndex ( node , sourceFile ) ;
174
174
if ( ! info ) return undefined ;
175
175
const { list, argumentIndex } = info ;
176
176
177
- const argumentCount = getArgumentCount ( list ) ;
177
+ const argumentCount = getArgumentCount ( list , /*ignoreTrailingComma*/ isInString ( sourceFile , position , node ) ) ;
178
178
if ( argumentIndex !== 0 ) {
179
179
Debug . assertLessThan ( argumentIndex , argumentCount ) ;
180
180
}
@@ -222,7 +222,7 @@ namespace ts.SignatureHelp {
222
222
// Case 3:
223
223
// foo<T#, U#>(a#, #b#) -> The token is buried inside a list, and should give signature help
224
224
// Find out if 'node' is an argument, a type argument, or neither
225
- const info = getArgumentOrParameterListInfo ( node , sourceFile ) ;
225
+ const info = getArgumentOrParameterListInfo ( node , position , sourceFile ) ;
226
226
if ( ! info ) return undefined ;
227
227
const { list, argumentIndex, argumentCount, argumentsSpan } = info ;
228
228
const isTypeParameterList = ! ! parent . typeArguments && parent . typeArguments . pos === list . pos ;
@@ -299,8 +299,8 @@ namespace ts.SignatureHelp {
299
299
return isBinaryExpression ( b . left ) ? countBinaryExpressionParameters ( b . left ) + 1 : 2 ;
300
300
}
301
301
302
- function tryGetParameterInfo ( startingToken : Node , _position : number , sourceFile : SourceFile , checker : TypeChecker ) : ArgumentListInfo | undefined {
303
- const info = getContextualSignatureLocationInfo ( startingToken , sourceFile , checker ) ;
302
+ function tryGetParameterInfo ( startingToken : Node , position : number , sourceFile : SourceFile , checker : TypeChecker ) : ArgumentListInfo | undefined {
303
+ const info = getContextualSignatureLocationInfo ( startingToken , sourceFile , position , checker ) ;
304
304
if ( ! info ) return undefined ;
305
305
const { contextualType, argumentIndex, argumentCount, argumentsSpan } = info ;
306
306
@@ -315,15 +315,15 @@ namespace ts.SignatureHelp {
315
315
}
316
316
317
317
interface ContextualSignatureLocationInfo { readonly contextualType : Type ; readonly argumentIndex : number ; readonly argumentCount : number ; readonly argumentsSpan : TextSpan ; }
318
- function getContextualSignatureLocationInfo ( startingToken : Node , sourceFile : SourceFile , checker : TypeChecker ) : ContextualSignatureLocationInfo | undefined {
318
+ function getContextualSignatureLocationInfo ( startingToken : Node , sourceFile : SourceFile , position : number , checker : TypeChecker ) : ContextualSignatureLocationInfo | undefined {
319
319
if ( startingToken . kind !== SyntaxKind . OpenParenToken && startingToken . kind !== SyntaxKind . CommaToken ) return undefined ;
320
320
const { parent } = startingToken ;
321
321
switch ( parent . kind ) {
322
322
case SyntaxKind . ParenthesizedExpression :
323
323
case SyntaxKind . MethodDeclaration :
324
324
case SyntaxKind . FunctionExpression :
325
325
case SyntaxKind . ArrowFunction :
326
- const info = getArgumentOrParameterListInfo ( startingToken , sourceFile ) ;
326
+ const info = getArgumentOrParameterListInfo ( startingToken , position , sourceFile ) ;
327
327
if ( ! info ) return undefined ;
328
328
const { argumentIndex, argumentCount, argumentsSpan } = info ;
329
329
const contextualType = isMethodDeclaration ( parent ) ? checker . getContextualTypeForObjectLiteralElement ( parent ) : checker . getContextualType ( parent as ParenthesizedExpression | FunctionExpression | ArrowFunction ) ;
@@ -372,7 +372,7 @@ namespace ts.SignatureHelp {
372
372
return argumentIndex ;
373
373
}
374
374
375
- function getArgumentCount ( argumentsList : Node ) {
375
+ function getArgumentCount ( argumentsList : Node , ignoreTrailingComma : boolean ) {
376
376
// The argument count for a list is normally the number of non-comma children it has.
377
377
// For example, if you have "Foo(a,b)" then there will be three children of the arg
378
378
// list 'a' '<comma>' 'b'. So, in this case the arg count will be 2. However, there
@@ -387,10 +387,9 @@ namespace ts.SignatureHelp {
387
387
const listChildren = argumentsList . getChildren ( ) ;
388
388
389
389
let argumentCount = countWhere ( listChildren , arg => arg . kind !== SyntaxKind . CommaToken ) ;
390
- if ( listChildren . length > 0 && last ( listChildren ) . kind === SyntaxKind . CommaToken ) {
390
+ if ( ! ignoreTrailingComma && listChildren . length > 0 && last ( listChildren ) . kind === SyntaxKind . CommaToken ) {
391
391
argumentCount ++ ;
392
392
}
393
-
394
393
return argumentCount ;
395
394
}
396
395
0 commit comments