Fix signature help crash when requested outside argument list

This commit is contained in:
Jason Freeman
2014-10-13 18:25:51 -07:00
parent 16a79c5768
commit 4486c3be9d
4 changed files with 26 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,8 @@ 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.
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();