Skip to content

Commit b38fc05

Browse files
committed
Don't return list index when looking for the argument list
1 parent 102da2d commit b38fc05

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/services/servicesSyntaxUtilities.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ module ts.ServicesSyntaxUtilities {
66
}
77

88
export function findListItemInfo(node: Node): ListItemInfo {
9+
var syntaxList = findContainingList(node);
10+
var children = syntaxList.getChildren();
11+
var index = indexOf(children, node);
12+
13+
return {
14+
listItemIndex: index,
15+
list: syntaxList
16+
};
17+
}
18+
19+
export function findContainingList(node: Node): Node {
920
// The node might be a list element (nonsynthetic) or a comma (synthetic). Either way, it will
1021
// be parented by the container of the SyntaxList, not the SyntaxList itself.
1122
// In order to find the list item index, we first need to locate SyntaxList itself and then search
@@ -17,13 +28,7 @@ module ts.ServicesSyntaxUtilities {
1728
}
1829
});
1930

20-
var children = syntaxList.getChildren();
21-
var index = indexOf(children, node);
22-
23-
return {
24-
listItemIndex: index,
25-
list: syntaxList
26-
};
31+
return syntaxList;
2732
}
2833

2934
// Includes the start position of each child, but excludes the end

src/services/signatureHelp.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,15 @@ module ts.SignatureHelp {
335335

336336
export function getSignatureHelpItems(sourceFile: SourceFile, position: number, startingNode: Node, typeInfoResolver: TypeChecker): SignatureHelpItems {
337337
// Decide whether to show signature help
338-
var signatureHelpContext = getSignatureHelpArgumentContext(startingNode);
338+
var argumentList = getContainingArgumentList(startingNode);
339339

340340
// Semantic filtering of signature help
341-
if (signatureHelpContext) {
342-
var call = <CallExpression>signatureHelpContext.list.parent;
341+
if (argumentList) {
342+
var call = <CallExpression>argumentList.parent;
343343
var candidates = <Signature[]>[];
344344
var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates);
345345
return candidates.length
346-
? createSignatureHelpItems(candidates, resolvedSignature, signatureHelpContext.list)
346+
? createSignatureHelpItems(candidates, resolvedSignature, argumentList)
347347
: undefined;
348348
}
349349

@@ -352,7 +352,7 @@ module ts.SignatureHelp {
352352

353353
// If node is an argument, returns its index in the argument list
354354
// If not, returns -1
355-
function getArgumentIndexInfo(node: Node): ServicesSyntaxUtilities.ListItemInfo {
355+
function getImmediatelyContainingArgumentList(node: Node): Node {
356356
if (node.parent.kind !== SyntaxKind.CallExpression && node.parent.kind !== SyntaxKind.NewExpression) {
357357
return undefined;
358358
}
@@ -363,11 +363,7 @@ module ts.SignatureHelp {
363363
// Find the list that starts right *after* the < or ( token
364364
var list = getChildListThatStartsWithOpenerToken(parent, node, sourceFile);
365365
Debug.assert(list);
366-
// Treat the open paren / angle bracket of a call as the introduction of parameter slot 0
367-
return {
368-
listItemIndex: 0,
369-
list: list
370-
};
366+
return list;
371367
}
372368

373369
if (node.kind === SyntaxKind.GreaterThanToken
@@ -376,10 +372,10 @@ module ts.SignatureHelp {
376372
return undefined;
377373
}
378374

379-
return ServicesSyntaxUtilities.findListItemInfo(node);
375+
return ServicesSyntaxUtilities.findContainingList(node);
380376
}
381377

382-
function getSignatureHelpArgumentContext(node: Node): ServicesSyntaxUtilities.ListItemInfo {
378+
function getContainingArgumentList(node: Node): Node {
383379
// We only want this node if it is a token and it strictly contains the current position.
384380
// Otherwise we want the previous token
385381
var isToken = node.kind < SyntaxKind.Missing;
@@ -397,9 +393,9 @@ module ts.SignatureHelp {
397393
return undefined;
398394
}
399395

400-
var argumentInfo = getArgumentIndexInfo(n);
401-
if (argumentInfo) {
402-
return argumentInfo;
396+
var argumentList = getImmediatelyContainingArgumentList(n);
397+
if (argumentList) {
398+
return argumentList;
403399
}
404400

405401

0 commit comments

Comments
 (0)