Skip to content

Commit 4486c3b

Browse files
committed
Fix signature help crash when requested outside argument list
1 parent 16a79c5 commit 4486c3b

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

src/services/formatting/smartIndenter.ts

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

src/services/signatureHelp.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,8 @@ module ts.SignatureHelp {
226226
};
227227
}
228228

229-
if (node.kind === SyntaxKind.GreaterThanToken
230-
|| node.kind === SyntaxKind.CloseParenToken
231-
|| node === parent.func) {
232-
return undefined;
233-
}
234-
229+
// findListItemInfo can return undefined if we are not in parent's argument list
230+
// or type argument list.
235231
return findListItemInfo(node);
236232
}
237233

src/services/utilities.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ module ts {
77

88
export function findListItemInfo(node: Node): ListItemInfo {
99
var syntaxList = findContainingList(node);
10+
11+
// It is possible at this point for syntaxList to be undefined, either if
12+
// node.parent had no list child, or if none of its list children contained
13+
// the span of node. If this happens, return undefined. The caller should
14+
// handle this case.
15+
if (!syntaxList) {
16+
return undefined;
17+
}
18+
1019
var children = syntaxList.getChildren();
1120
var index = indexOf(children, node);
1221

@@ -32,13 +41,6 @@ module ts {
3241
}
3342
});
3443

35-
// syntaxList should not be undefined here. If it is, there is a problem. Find out if
36-
// there at least is a child that is a list.
37-
if (!syntaxList) {
38-
Debug.assert(findChildOfKind(node.parent, SyntaxKind.SyntaxList),
39-
"Node of kind " + SyntaxKind[node.parent.kind] + " has no list children");
40-
}
41-
4244
return syntaxList;
4345
}
4446

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
///<reference path="fourslash.ts"/>
2+
3+
////class Foo { }
4+
////new/*1*/ Foo
5+
////new /*2*/Foo(/*3*/)
6+
7+
goTo.marker('1');
8+
verify.not.signatureHelpPresent();
9+
10+
goTo.marker('2');
11+
verify.not.signatureHelpPresent();
12+
13+
goTo.marker('3');
14+
verify.signatureHelpPresent();

0 commit comments

Comments
 (0)