Skip to content

Commit d6485c9

Browse files
committed
Adds navigation bar items on methods and constructors
1 parent 0436ba0 commit d6485c9

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

src/services/navigationBar.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ namespace ts.NavigationBar {
154154
for (let node of nodes) {
155155
switch (node.kind) {
156156
case SyntaxKind.ClassDeclaration:
157+
topLevelNodes.push(node);
158+
forEach((<ClassDeclaration>node).members, (node) => {
159+
if (node.kind === SyntaxKind.MethodDeclaration ||
160+
node.kind === SyntaxKind.Constructor) {
161+
if ((<MethodDeclaration>node).body) {
162+
addTopLevelNodes((<Block>(<MethodDeclaration>node).body).statements, topLevelNodes);
163+
}
164+
}
165+
});
166+
break;
157167
case SyntaxKind.EnumDeclaration:
158168
case SyntaxKind.InterfaceDeclaration:
159169
topLevelNodes.push(node);
@@ -193,6 +203,15 @@ namespace ts.NavigationBar {
193203
if (!isFunctionBlock(functionDeclaration.parent)) {
194204
return true;
195205
}
206+
else {
207+
// Except for parent functions that are methods and constructors.
208+
const grandParentKind = functionDeclaration.parent.parent.kind;
209+
if (grandParentKind === SyntaxKind.MethodDeclaration ||
210+
grandParentKind === SyntaxKind.Constructor) {
211+
212+
return true;
213+
}
214+
}
196215
}
197216
}
198217

@@ -407,7 +426,7 @@ namespace ts.NavigationBar {
407426

408427
function createModuleItem(node: ModuleDeclaration): NavigationBarItem {
409428
let moduleName = getModuleName(node);
410-
429+
411430
let childItems = getItemsWorker(getChildNodes((<Block>getInnermostModule(node).body).statements), createChildItem);
412431

413432
return getNavigationBarItem(moduleName,
@@ -422,7 +441,7 @@ namespace ts.NavigationBar {
422441
if (node.body && node.body.kind === SyntaxKind.Block) {
423442
let childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);
424443

425-
return getNavigationBarItem(!node.name ? "default": node.name.text ,
444+
return getNavigationBarItem(!node.name ? "default": node.name.text,
426445
ts.ScriptElementKind.functionElement,
427446
getNodeModifiers(node),
428447
[getNodeSpan(node)],
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////class Class {
4+
//// constructor() {
5+
//// {| "itemName": "LocalFunctionInConstructor", "kind": "function", "parentName": "Class"|}function LocalFunctionInConstructor() {
6+
////
7+
//// }
8+
////
9+
//// {| "itemName": "LocalInterfaceInConstrcutor", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInConstrcutor {
10+
//// }
11+
////
12+
//// enum LocalEnumInConstructor {
13+
//// {| "itemName": "LocalEnumMemberInConstructor", "kind": "property", "parentName": "LocalEnumInConstructor"|}LocalEnumMemberInConstructor,
14+
//// }
15+
//// }
16+
//// method() {
17+
//// {| "itemName": "LocalFunctionInMethod", "kind": "function", "parentName": "foo"|}function LocalFunctionInMethod() {
18+
//// {| "itemName": "LocalFunctionInLocalFunctionInMethod", "kind": "function", "parentName": "bar"|}function LocalFunctionInLocalFunctionInMethod() {
19+
////
20+
//// }
21+
//// }
22+
////
23+
//// {| "itemName": "LocalInterfaceInMethod", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInMethod {
24+
//// }
25+
////
26+
//// enum LocalEnumInMethod {
27+
//// {| "itemName": "LocalEnumMemberInMethod", "kind": "property", "parentName": "foo"|}LocalEnumMemberInMethod,
28+
//// }
29+
//// }
30+
////}
31+
32+
test.markers().forEach((marker) => {
33+
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
34+
});
35+
36+
// no other items
37+
verify.getScriptLexicalStructureListCount(12);
38+

0 commit comments

Comments
 (0)