@@ -333,25 +333,26 @@ module ts.SignatureHelp {
333
333
//}
334
334
var emptyArray : any [ ] = [ ] ;
335
335
336
- export function getSignatureHelpItems ( sourceFile : SourceFile , position : number , startingNode : Node , typeInfoResolver : TypeChecker , cancellationToken : CancellationToken ) : SignatureHelpItems {
336
+ export function getSignatureHelpItems ( sourceFile : SourceFile , position : number , startingNode : Node , typeInfoResolver : TypeChecker , cancellationToken : CancellationTokenObject ) : SignatureHelpItems {
337
337
// Decide whether to show signature help
338
338
var argumentList = getContainingArgumentList ( startingNode ) ;
339
339
cancellationToken . throwIfCancellationRequested ( ) ;
340
340
341
341
// Semantic filtering of signature help
342
- if ( argumentList ) {
343
- var call = < CallExpression > argumentList . parent ;
344
- var candidates = < Signature [ ] > [ ] ;
345
- var resolvedSignature = typeInfoResolver . getResolvedSignature ( call , candidates ) ;
346
- cancellationToken . throwIfCancellationRequested ( ) ;
347
-
348
- return candidates . length
349
- ? createSignatureHelpItems ( candidates , resolvedSignature , argumentList )
350
- : undefined ;
342
+ if ( ! argumentList ) {
343
+ return undefined ;
351
344
}
352
345
353
- return undefined ;
346
+ var call = < CallExpression > argumentList . parent ;
347
+ var candidates = < Signature [ ] > [ ] ;
348
+ var resolvedSignature = typeInfoResolver . getResolvedSignature ( call , candidates ) ;
349
+ cancellationToken . throwIfCancellationRequested ( ) ;
350
+
351
+ if ( ! candidates . length ) {
352
+ return undefined ;
353
+ }
354
354
355
+ return createSignatureHelpItems ( candidates , resolvedSignature , argumentList ) ;
355
356
356
357
// If node is an argument, returns its index in the argument list
357
358
// If not, returns -1
@@ -420,7 +421,7 @@ module ts.SignatureHelp {
420
421
display += "?" ;
421
422
}
422
423
display += ": " + typeInfoResolver . typeToString ( typeInfoResolver . getTypeOfSymbol ( p ) , argumentListOrTypeArgumentList ) ;
423
- return new SignatureHelpParameter ( p . name , "" , display , /* isOptional*/ false ) ;
424
+ return new SignatureHelpParameter ( p . name , "" , display , isOptional ) ;
424
425
} ) ;
425
426
var callTargetNode = ( < CallExpression > argumentListOrTypeArgumentList . parent ) . func ;
426
427
var callTargetSymbol = typeInfoResolver . getSymbolInfo ( callTargetNode ) ;
@@ -439,6 +440,14 @@ module ts.SignatureHelp {
439
440
selectedItemIndex = 0 ;
440
441
}
441
442
443
+ // We use full start and skip trivia on the end because we want to include trivia on
444
+ // both sides. For example,
445
+ //
446
+ // foo( /*comment */ a, b, c /*comment*/ )
447
+ // | |
448
+ //
449
+ // The applicable span is from the first bar to the second bar (inclusive,
450
+ // but not including parentheses)
442
451
var applicableSpanStart = argumentListOrTypeArgumentList . getFullStart ( ) ;
443
452
var applicableSpanEnd = skipTrivia ( sourceFile . text , argumentListOrTypeArgumentList . end , /*stopAfterLineBreak*/ false ) ;
444
453
var applicableSpan = new TypeScript . TextSpan ( applicableSpanStart , applicableSpanEnd - applicableSpanStart ) ;
@@ -459,15 +468,14 @@ module ts.SignatureHelp {
459
468
460
469
var tokenPrecedingCurrentPosition = ServicesSyntaxUtilities . findPrecedingToken ( position , sourceFile ) ;
461
470
var call = < CallExpression > tokenPrecedingSpanStart . parent ;
471
+ Debug . assert ( call . kind === SyntaxKind . CallExpression || call . kind === SyntaxKind . NewExpression , "wrong call kind " + SyntaxKind [ call . kind ] ) ;
462
472
if ( tokenPrecedingCurrentPosition . kind === SyntaxKind . CloseParenToken || tokenPrecedingCurrentPosition . kind === SyntaxKind . GreaterThanToken ) {
463
473
if ( tokenPrecedingCurrentPosition . parent === call ) {
464
474
// This call expression is complete. Stop signature help.
465
475
return undefined ;
466
476
}
467
477
}
468
478
469
- Debug . assert ( call . kind === SyntaxKind . CallExpression || call . kind === SyntaxKind . NewExpression , "wrong call kind " + SyntaxKind [ call . kind ] ) ;
470
-
471
479
var argumentListOrTypeArgumentList = getChildListThatStartsWithOpenerToken ( call , tokenPrecedingSpanStart , sourceFile ) ;
472
480
// Debug.assert(argumentListOrTypeArgumentList.getChildCount() === 0 || argumentListOrTypeArgumentList.getChildCount() % 2 === 1, "Even number of children");
473
481
@@ -478,8 +486,6 @@ module ts.SignatureHelp {
478
486
479
487
var numberOfCommas = countWhere ( argumentListOrTypeArgumentList . getChildren ( ) , arg => arg . kind === SyntaxKind . CommaToken ) ;
480
488
var argumentCount = numberOfCommas + 1 ;
481
-
482
-
483
489
if ( argumentCount <= 1 ) {
484
490
return new SignatureHelpState ( /*argumentIndex*/ 0 , argumentCount ) ;
485
491
}
@@ -490,8 +496,8 @@ module ts.SignatureHelp {
490
496
// possible that we are to the right of all children. Assume that we are still within
491
497
// the applicable span and that we are typing the last argument
492
498
// Alternatively, we could be in range of one of the arguments, in which case we need to divide
493
- // by 2 to exclude commas
494
- var argumentIndex = indexOfNodeContainingPosition < 0 ? argumentCount - 1 : integerDivide ( indexOfNodeContainingPosition , 2 ) ;
499
+ // by 2 to exclude commas. Use bit shifting in order to take the floor of the division.
500
+ var argumentIndex = indexOfNodeContainingPosition < 0 ? argumentCount - 1 : indexOfNodeContainingPosition >> 1 ;
495
501
return new SignatureHelpState ( argumentIndex , argumentCount ) ;
496
502
}
497
503
0 commit comments