Adds navigation bar items on methods and constructors

This commit is contained in:
Tingan Ho
2016-02-22 05:37:07 +08:00
parent 0436ba0cfb
commit d6485c9c8f
2 changed files with 59 additions and 2 deletions

View File

@@ -154,6 +154,16 @@ namespace ts.NavigationBar {
for (let node of nodes) {
switch (node.kind) {
case SyntaxKind.ClassDeclaration:
topLevelNodes.push(node);
forEach((<ClassDeclaration>node).members, (node) => {
if (node.kind === SyntaxKind.MethodDeclaration ||
node.kind === SyntaxKind.Constructor) {
if ((<MethodDeclaration>node).body) {
addTopLevelNodes((<Block>(<MethodDeclaration>node).body).statements, topLevelNodes);
}
}
});
break;
case SyntaxKind.EnumDeclaration:
case SyntaxKind.InterfaceDeclaration:
topLevelNodes.push(node);
@@ -193,6 +203,15 @@ namespace ts.NavigationBar {
if (!isFunctionBlock(functionDeclaration.parent)) {
return true;
}
else {
// Except for parent functions that are methods and constructors.
const grandParentKind = functionDeclaration.parent.parent.kind;
if (grandParentKind === SyntaxKind.MethodDeclaration ||
grandParentKind === SyntaxKind.Constructor) {
return true;
}
}
}
}
@@ -407,7 +426,7 @@ namespace ts.NavigationBar {
function createModuleItem(node: ModuleDeclaration): NavigationBarItem {
let moduleName = getModuleName(node);
let childItems = getItemsWorker(getChildNodes((<Block>getInnermostModule(node).body).statements), createChildItem);
return getNavigationBarItem(moduleName,
@@ -422,7 +441,7 @@ namespace ts.NavigationBar {
if (node.body && node.body.kind === SyntaxKind.Block) {
let childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);
return getNavigationBarItem(!node.name ? "default": node.name.text ,
return getNavigationBarItem(!node.name ? "default": node.name.text,
ts.ScriptElementKind.functionElement,
getNodeModifiers(node),
[getNodeSpan(node)],

View File

@@ -0,0 +1,38 @@
/// <reference path="fourslash.ts"/>
////class Class {
//// constructor() {
//// {| "itemName": "LocalFunctionInConstructor", "kind": "function", "parentName": "Class"|}function LocalFunctionInConstructor() {
////
//// }
////
//// {| "itemName": "LocalInterfaceInConstrcutor", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInConstrcutor {
//// }
////
//// enum LocalEnumInConstructor {
//// {| "itemName": "LocalEnumMemberInConstructor", "kind": "property", "parentName": "LocalEnumInConstructor"|}LocalEnumMemberInConstructor,
//// }
//// }
//// method() {
//// {| "itemName": "LocalFunctionInMethod", "kind": "function", "parentName": "foo"|}function LocalFunctionInMethod() {
//// {| "itemName": "LocalFunctionInLocalFunctionInMethod", "kind": "function", "parentName": "bar"|}function LocalFunctionInLocalFunctionInMethod() {
////
//// }
//// }
////
//// {| "itemName": "LocalInterfaceInMethod", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInMethod {
//// }
////
//// enum LocalEnumInMethod {
//// {| "itemName": "LocalEnumMemberInMethod", "kind": "property", "parentName": "foo"|}LocalEnumMemberInMethod,
//// }
//// }
////}
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
// no other items
verify.getScriptLexicalStructureListCount(12);