Merge pull request #890 from Microsoft/sigHelpCrash

Fix signature help crash when requested outside argument list
This commit is contained in:
Jason Freeman 2014-10-14 12:00:17 -07:00
commit 6bc3ed8062
4 changed files with 30 additions and 14 deletions

View File

@ -108,7 +108,7 @@ module ts.formatting {
function getActualIndentationForListItemBeforeComma(commaToken: Node, sourceFile: SourceFile, options: TypeScript.FormattingOptions): number {
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
var commaItemInfo = findListItemInfo(commaToken);
Debug.assert(commaItemInfo.listItemIndex > 0);
Debug.assert(commaItemInfo && commaItemInfo.listItemIndex > 0);
// The item we're interested in is right before the comma
return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options);
}

View File

@ -226,12 +226,12 @@ module ts.SignatureHelp {
};
}
if (node.kind === SyntaxKind.GreaterThanToken
|| node.kind === SyntaxKind.CloseParenToken
|| node === parent.func) {
return undefined;
}
// findListItemInfo can return undefined if we are not in parent's argument list
// or type argument list. This includes cases where the cursor is:
// - To the right of the closing paren
// - Between the type arguments and the arguments (greater than token)
// - On the target of the call (parent.func)
// - On the 'new' keyword in a 'new' expression
return findListItemInfo(node);
}

View File

@ -7,6 +7,15 @@ module ts {
export function findListItemInfo(node: Node): ListItemInfo {
var syntaxList = findContainingList(node);
// It is possible at this point for syntaxList to be undefined, either if
// node.parent had no list child, or if none of its list children contained
// the span of node. If this happens, return undefined. The caller should
// handle this case.
if (!syntaxList) {
return undefined;
}
var children = syntaxList.getChildren();
var index = indexOf(children, node);
@ -32,13 +41,6 @@ module ts {
}
});
// syntaxList should not be undefined here. If it is, there is a problem. Find out if
// there at least is a child that is a list.
if (!syntaxList) {
Debug.assert(findChildOfKind(node.parent, SyntaxKind.SyntaxList),
"Node of kind " + SyntaxKind[node.parent.kind] + " has no list children");
}
return syntaxList;
}

View File

@ -0,0 +1,14 @@
///<reference path="fourslash.ts"/>
////class Foo { }
////new/*1*/ Foo
////new /*2*/Foo(/*3*/)
goTo.marker('1');
verify.not.signatureHelpPresent();
goTo.marker('2');
verify.not.signatureHelpPresent();
goTo.marker('3');
verify.signatureHelpPresent();