mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Fixing issue where the top level source file item was not being selected.
This commit is contained in:
parent
e1bb169607
commit
e2c4d7d0d9
@ -117,13 +117,25 @@ module ts.NavigationBar {
|
||||
}
|
||||
|
||||
function isTopLevelFunctionDeclaration(functionDeclaration: FunctionDeclaration) {
|
||||
// A function declaration is 'top level' if it contains any function declarations
|
||||
// within it.
|
||||
return functionDeclaration.kind === SyntaxKind.FunctionDeclaration &&
|
||||
functionDeclaration.body &&
|
||||
functionDeclaration.body.kind === SyntaxKind.FunctionBlock &&
|
||||
forEach((<Block>functionDeclaration.body).statements,
|
||||
s => s.kind === SyntaxKind.FunctionDeclaration && !isEmpty((<FunctionDeclaration>s).name.text));
|
||||
if (functionDeclaration.kind === SyntaxKind.FunctionDeclaration) {
|
||||
// A function declaration is 'top level' if it contains any function declarations
|
||||
// within it.
|
||||
if (functionDeclaration.body && functionDeclaration.body.kind === SyntaxKind.FunctionBlock) {
|
||||
if (forEach((<Block>functionDeclaration.body).statements,
|
||||
s => s.kind === SyntaxKind.FunctionDeclaration && !isEmpty((<FunctionDeclaration>s).name.text))) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Or if it is not parented by another function. i.e all functions
|
||||
// at module scope are 'top level'.
|
||||
if (functionDeclaration.parent.kind !== SyntaxKind.FunctionBlock) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getItemsWorker(nodes: Node[], createItem: (n: Node) => ts.NavigationBarItem): ts.NavigationBarItem[] {
|
||||
@ -402,7 +414,9 @@ module ts.NavigationBar {
|
||||
}
|
||||
|
||||
function getNodeSpan(node: Node) {
|
||||
return TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd());
|
||||
return node.kind === SyntaxKind.SourceFile
|
||||
? TypeScript.TextSpan.fromBounds(node.getFullStart(), node.getEnd())
|
||||
: TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd());
|
||||
}
|
||||
|
||||
function getTextOfNode(node: Node): string {
|
||||
|
||||
@ -20,4 +20,4 @@ test.markers().forEach((marker) => {
|
||||
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
|
||||
});
|
||||
|
||||
verify.getScriptLexicalStructureListCount(7); // 4 functions + global. Note: there are 7 because of the functions show up at the top level and as child items.
|
||||
verify.getScriptLexicalStructureListCount(8); // 4 functions + global. Note: there are 8 because of the functions show up at the top level and as child items.
|
||||
|
||||
@ -9,4 +9,4 @@ test.markers().forEach((marker) => {
|
||||
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
|
||||
});
|
||||
|
||||
verify.getScriptLexicalStructureListCount(2); // <global> and 'f'.
|
||||
verify.getScriptLexicalStructureListCount(3); // <global> and 'f'.
|
||||
@ -10,4 +10,4 @@ test.markers().forEach((marker) => {
|
||||
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
|
||||
});
|
||||
|
||||
verify.getScriptLexicalStructureListCount(2); // <global> and 'f'
|
||||
verify.getScriptLexicalStructureListCount(3); // <global> and 'f'
|
||||
@ -41,4 +41,4 @@ goTo.marker("file3");
|
||||
verify.getScriptLexicalStructureListContains("<global>", "module");
|
||||
verify.getScriptLexicalStructureListContains("foo", "function");
|
||||
verify.getScriptLexicalStructureListContains("bar", "function");
|
||||
verify.getScriptLexicalStructureListCount(3);
|
||||
verify.getScriptLexicalStructureListCount(5);
|
||||
Loading…
x
Reference in New Issue
Block a user