diff --git a/src/services/servicesSyntaxUtilities.ts b/src/services/servicesSyntaxUtilities.ts index b7e58ebe567..5edd72bdd3f 100644 --- a/src/services/servicesSyntaxUtilities.ts +++ b/src/services/servicesSyntaxUtilities.ts @@ -6,6 +6,17 @@ module ts.ServicesSyntaxUtilities { } export function findListItemInfo(node: Node): ListItemInfo { + var syntaxList = findContainingList(node); + var children = syntaxList.getChildren(); + var index = indexOf(children, node); + + return { + listItemIndex: index, + list: syntaxList + }; + } + + export function findContainingList(node: Node): Node { // The node might be a list element (nonsynthetic) or a comma (synthetic). Either way, it will // be parented by the container of the SyntaxList, not the SyntaxList itself. // 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 { } }); - var children = syntaxList.getChildren(); - var index = indexOf(children, node); - - return { - listItemIndex: index, - list: syntaxList - }; + return syntaxList; } // Includes the start position of each child, but excludes the end diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 145bc58d806..a873b9fb1c9 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -335,15 +335,15 @@ module ts.SignatureHelp { export function getSignatureHelpItems(sourceFile: SourceFile, position: number, startingNode: Node, typeInfoResolver: TypeChecker): SignatureHelpItems { // Decide whether to show signature help - var signatureHelpContext = getSignatureHelpArgumentContext(startingNode); + var argumentList = getContainingArgumentList(startingNode); // Semantic filtering of signature help - if (signatureHelpContext) { - var call = signatureHelpContext.list.parent; + if (argumentList) { + var call = argumentList.parent; var candidates = []; var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates); return candidates.length - ? createSignatureHelpItems(candidates, resolvedSignature, signatureHelpContext.list) + ? createSignatureHelpItems(candidates, resolvedSignature, argumentList) : undefined; } @@ -352,7 +352,7 @@ module ts.SignatureHelp { // If node is an argument, returns its index in the argument list // If not, returns -1 - function getArgumentIndexInfo(node: Node): ServicesSyntaxUtilities.ListItemInfo { + function getImmediatelyContainingArgumentList(node: Node): Node { if (node.parent.kind !== SyntaxKind.CallExpression && node.parent.kind !== SyntaxKind.NewExpression) { return undefined; } @@ -363,11 +363,7 @@ module ts.SignatureHelp { // Find the list that starts right *after* the < or ( token var list = getChildListThatStartsWithOpenerToken(parent, node, sourceFile); Debug.assert(list); - // Treat the open paren / angle bracket of a call as the introduction of parameter slot 0 - return { - listItemIndex: 0, - list: list - }; + return list; } if (node.kind === SyntaxKind.GreaterThanToken @@ -376,10 +372,10 @@ module ts.SignatureHelp { return undefined; } - return ServicesSyntaxUtilities.findListItemInfo(node); + return ServicesSyntaxUtilities.findContainingList(node); } - function getSignatureHelpArgumentContext(node: Node): ServicesSyntaxUtilities.ListItemInfo { + function getContainingArgumentList(node: Node): Node { // We only want this node if it is a token and it strictly contains the current position. // Otherwise we want the previous token var isToken = node.kind < SyntaxKind.Missing; @@ -397,9 +393,9 @@ module ts.SignatureHelp { return undefined; } - var argumentInfo = getArgumentIndexInfo(n); - if (argumentInfo) { - return argumentInfo; + var argumentList = getImmediatelyContainingArgumentList(n); + if (argumentList) { + return argumentList; }