Skip to content

Commit 8f60280

Browse files
committed
Respond to PR comments
1 parent 945eb7c commit 8f60280

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4137,6 +4137,10 @@ module ts {
41374137

41384138
// For error recovery, since we have parsed OmittedExpressions for any extra commas
41394139
// in the argument list, if we see any OmittedExpressions, just return true.
4140+
// The reason this is ok is because omitted expressions here are syntactically
4141+
// illegal, and will cause a parse error.
4142+
// Note: It may be worth keeping the upper bound check on arity, but removing
4143+
// the lower bound check if there are omitted expressions.
41404144
if (!isCorrect && forEach(node.arguments, arg => arg.kind === SyntaxKind.OmittedExpression)) {
41414145
return true;
41424146
}
@@ -4287,7 +4291,7 @@ module ts {
42874291
// If candidate is undefined, it means that no candidates had a suitable arity. In that case,
42884292
// skip the checkApplicableSignature check.
42894293
if (candidateWithCorrectArity) {
4290-
checkApplicableSignature(node, candidateWithCorrectArity, relation, undefined, /*reportErrors*/ true);
4294+
checkApplicableSignature(node, candidateWithCorrectArity, relation, /*excludeArgument*/ undefined, /*reportErrors*/ true);
42914295
}
42924296
else {
42934297
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);

src/compiler/core.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ module ts {
121121
}
122122

123123
return ~low;
124-
}
125-
126-
export function integerDivide(numerator: number, denominator: number): number {
127-
return (numerator / denominator) >> 0;
128124
}
129125

130126
var hasOwnProperty = Object.prototype.hasOwnProperty;

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,6 @@ module ts {
11741174

11751175
export interface CancellationToken {
11761176
isCancellationRequested(): boolean;
1177-
throwIfCancellationRequested?(): void;
11781177
}
11791178

11801179
export interface CompilerHost {

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ module FourSlash {
959959
var state = this.languageService.getSignatureHelpCurrentArgumentState(this.activeFile.fileName, this.currentCaretPosition, help.applicableSpan.start());
960960

961961
// Same logic as in getActiveSignatureHelp - this value might be -1 until a parameter value actually gets typed
962-
var currentParam = state === null || state.argumentIndex < 0 ? 0 : state.argumentIndex;
962+
var currentParam = state === undefined ? 0 : state.argumentIndex;
963963
return item.parameters[currentParam];
964964
}
965965

src/services/services.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ module ts {
966966

967967
export class OperationCanceledException { }
968968

969-
class CancellationTokenObject {
969+
export class CancellationTokenObject {
970970

971971
public static None: CancellationTokenObject = new CancellationTokenObject(null)
972972

@@ -3480,6 +3480,7 @@ module ts {
34803480
}
34813481

34823482
// Signature help
3483+
// This is a semantic operation
34833484
function getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems {
34843485
synchronizeHostData();
34853486

@@ -3490,6 +3491,7 @@ module ts {
34903491
return SignatureHelp.getSignatureHelpItems(sourceFile, position, node, typeInfoResolver, cancellationToken);
34913492
}
34923493

3494+
// This is a syntactic operation
34933495
function getSignatureHelpCurrentArgumentState(fileName: string, position: number, applicableSpanStart: number): SignatureHelpState {
34943496
fileName = TypeScript.switchToForwardSlashes(fileName);
34953497
var sourceFile = getCurrentSourceFile(fileName);

src/services/signatureHelp.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,26 @@ module ts.SignatureHelp {
333333
//}
334334
var emptyArray: any[] = [];
335335

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 {
337337
// Decide whether to show signature help
338338
var argumentList = getContainingArgumentList(startingNode);
339339
cancellationToken.throwIfCancellationRequested();
340340

341341
// 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;
351344
}
352345

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+
}
354354

355+
return createSignatureHelpItems(candidates, resolvedSignature, argumentList);
355356

356357
// If node is an argument, returns its index in the argument list
357358
// If not, returns -1
@@ -420,7 +421,7 @@ module ts.SignatureHelp {
420421
display += "?";
421422
}
422423
display += ": " + typeInfoResolver.typeToString(typeInfoResolver.getTypeOfSymbol(p), argumentListOrTypeArgumentList);
423-
return new SignatureHelpParameter(p.name, "", display, /*isOptional*/ false);
424+
return new SignatureHelpParameter(p.name, "", display, isOptional);
424425
});
425426
var callTargetNode = (<CallExpression>argumentListOrTypeArgumentList.parent).func;
426427
var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode);
@@ -439,6 +440,14 @@ module ts.SignatureHelp {
439440
selectedItemIndex = 0;
440441
}
441442

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)
442451
var applicableSpanStart = argumentListOrTypeArgumentList.getFullStart();
443452
var applicableSpanEnd = skipTrivia(sourceFile.text, argumentListOrTypeArgumentList.end, /*stopAfterLineBreak*/ false);
444453
var applicableSpan = new TypeScript.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
@@ -459,15 +468,14 @@ module ts.SignatureHelp {
459468

460469
var tokenPrecedingCurrentPosition = ServicesSyntaxUtilities.findPrecedingToken(position, sourceFile);
461470
var call = <CallExpression>tokenPrecedingSpanStart.parent;
471+
Debug.assert(call.kind === SyntaxKind.CallExpression || call.kind === SyntaxKind.NewExpression, "wrong call kind " + SyntaxKind[call.kind]);
462472
if (tokenPrecedingCurrentPosition.kind === SyntaxKind.CloseParenToken || tokenPrecedingCurrentPosition.kind === SyntaxKind.GreaterThanToken) {
463473
if (tokenPrecedingCurrentPosition.parent === call) {
464474
// This call expression is complete. Stop signature help.
465475
return undefined;
466476
}
467477
}
468478

469-
Debug.assert(call.kind === SyntaxKind.CallExpression || call.kind === SyntaxKind.NewExpression, "wrong call kind " + SyntaxKind[call.kind]);
470-
471479
var argumentListOrTypeArgumentList = getChildListThatStartsWithOpenerToken(call, tokenPrecedingSpanStart, sourceFile);
472480
// Debug.assert(argumentListOrTypeArgumentList.getChildCount() === 0 || argumentListOrTypeArgumentList.getChildCount() % 2 === 1, "Even number of children");
473481

@@ -478,8 +486,6 @@ module ts.SignatureHelp {
478486

479487
var numberOfCommas = countWhere(argumentListOrTypeArgumentList.getChildren(), arg => arg.kind === SyntaxKind.CommaToken);
480488
var argumentCount = numberOfCommas + 1;
481-
482-
483489
if (argumentCount <= 1) {
484490
return new SignatureHelpState(/*argumentIndex*/ 0, argumentCount);
485491
}
@@ -490,8 +496,8 @@ module ts.SignatureHelp {
490496
// possible that we are to the right of all children. Assume that we are still within
491497
// the applicable span and that we are typing the last argument
492498
// 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;
495501
return new SignatureHelpState(argumentIndex, argumentCount);
496502
}
497503

0 commit comments

Comments
 (0)