Skip to content

Commit 27a1e91

Browse files
author
Andy
committed
Merge pull request #8814 from Microsoft/navbar_modules
Include modules as childItems in navigation bar
2 parents cd5a443 + 1be09c9 commit 27a1e91

8 files changed

+52
-46
lines changed

src/services/navigationBar.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,13 @@ namespace ts.NavigationBar {
320320
case SyntaxKind.EnumMember:
321321
return createItem(node, getTextOfNode((<EnumMember>node).name), ts.ScriptElementKind.memberVariableElement);
322322

323+
case SyntaxKind.ModuleDeclaration:
324+
return createItem(node, getModuleName(<ModuleDeclaration>node), ts.ScriptElementKind.moduleElement);
325+
323326
case SyntaxKind.InterfaceDeclaration:
324327
return createItem(node, getTextOfNode((<InterfaceDeclaration>node).name), ts.ScriptElementKind.interfaceElement);
325328

329+
326330
case SyntaxKind.CallSignature:
327331
return createItem(node, "()", ts.ScriptElementKind.callSignatureElement);
328332

@@ -439,26 +443,6 @@ namespace ts.NavigationBar {
439443

440444
return undefined;
441445

442-
function getModuleName(moduleDeclaration: ModuleDeclaration): string {
443-
// We want to maintain quotation marks.
444-
if (isAmbientModule(moduleDeclaration)) {
445-
return getTextOfNode(moduleDeclaration.name);
446-
}
447-
448-
// Otherwise, we need to aggregate each identifier to build up the qualified name.
449-
const result: string[] = [];
450-
451-
result.push(moduleDeclaration.name.text);
452-
453-
while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) {
454-
moduleDeclaration = <ModuleDeclaration>moduleDeclaration.body;
455-
456-
result.push(moduleDeclaration.name.text);
457-
}
458-
459-
return result.join(".");
460-
}
461-
462446
function createModuleItem(node: ModuleDeclaration): NavigationBarItem {
463447
const moduleName = getModuleName(node);
464448

@@ -593,6 +577,26 @@ namespace ts.NavigationBar {
593577
}
594578
}
595579

580+
function getModuleName(moduleDeclaration: ModuleDeclaration): string {
581+
// We want to maintain quotation marks.
582+
if (isAmbientModule(moduleDeclaration)) {
583+
return getTextOfNode(moduleDeclaration.name);
584+
}
585+
586+
// Otherwise, we need to aggregate each identifier to build up the qualified name.
587+
const result: string[] = [];
588+
589+
result.push(moduleDeclaration.name.text);
590+
591+
while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) {
592+
moduleDeclaration = <ModuleDeclaration>moduleDeclaration.body;
593+
594+
result.push(moduleDeclaration.name.text);
595+
}
596+
597+
return result.join(".");
598+
}
599+
596600
function removeComputedProperties(node: EnumDeclaration): Declaration[] {
597601
return filter<Declaration>(node.members, member => member.name === undefined || member.name.kind !== SyntaxKind.ComputedPropertyName);
598602
}

tests/cases/fourslash/navbar_contains-no-duplicates.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/// <reference path="fourslash.ts" />
2-
//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows {
3-
//// {| "itemName": "Foundation", "kind": "module", "parentName": "" |}export module Foundation {
2+
//// {| "itemName": "Windows", "kind": "module", "parentName": "<global>" |}declare module Windows {
3+
//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows" |}export module Foundation {
44
//// export var {| "itemName": "A", "kind": "var" |}A;
55
//// {| "itemName": "Test", "kind": "class", "parentName": "Foundation" |}export class Test {
66
//// {| "itemName": "wow", "kind": "method" |}public wow();
77
//// }
88
//// }
99
//// }
1010
////
11-
//// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows {
12-
//// {| "itemName": "Foundation", "kind": "module", "parentName": "", "isAdditionalRange": true |}export module Foundation {
11+
//// {| "itemName": "Windows", "kind": "module", "parentName": "<global>", "isAdditionalRange": true |}declare module Windows {
12+
//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows", "isAdditionalRange": true |}export module Foundation {
1313
//// export var {| "itemName": "B", "kind": "var" |}B;
1414
//// {| "itemName": "Test", "kind": "module" |}export module Test {
1515
//// {| "itemName": "Boom", "kind": "function" |}export function Boom(): number;
@@ -23,7 +23,7 @@
2323
//// }
2424
//// }
2525
////
26-
//// {| "itemName": "ABC", "kind": "module", "parentName": "" |}module ABC {
26+
//// {| "itemName": "ABC", "kind": "module", "parentName": "<global>" |}module ABC {
2727
//// export var {| "itemName": "x", "kind": "var" |}x = 3;
2828
//// }
2929

@@ -38,4 +38,5 @@ test.markers().forEach(marker => {
3838
marker.position);
3939
}
4040
});
41-
verify.navigationBarCount(15);
41+
42+
verify.navigationBarCount(19);

tests/cases/fourslash/navigationBarItemsItems.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
////}
1111
////
1212
/////// Module
13-
////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes {
13+
////{| "itemName": "Shapes", "kind": "module", "parentName": "<global>" |}module Shapes {
1414
////
1515
//// // Class
1616
//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint {
@@ -49,4 +49,4 @@ test.markers().forEach((marker) => {
4949
}
5050
});
5151

52-
verify.navigationBarCount(26);
52+
verify.navigationBarCount(27);

tests/cases/fourslash/navigationBarItemsItems2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ edit.insertLine("module A");
88
edit.insert("export class ");
99

1010
// should not crash
11-
verify.navigationBarCount(2);
11+
verify.navigationBarCount(4);
1212

tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ goTo.marker("file1");
2222
verify.navigationBarContains("Module1", "module");
2323
verify.navigationBarContains("x", "var");
2424
// nothing else should show up
25-
verify.navigationBarCount(2);
25+
verify.navigationBarCount(4); // <global>, its child, Module1, its child
2626

2727
goTo.marker("file2");
2828
verify.navigationBarContains("Module1.SubModule", "module");
2929
verify.navigationBarContains("y", "var");
30-
verify.navigationBarCount(2);
30+
verify.navigationBarCount(4);
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1+
/// <reference path="fourslash.ts"/>
12

2-
////{| "itemName": "\"X.Y.Z\"", "kind": "module" |}
3+
////{| "itemName": "\"X.Y.Z\"", "kind": "module", "parentName": "<global>" |}
34
////declare module "X.Y.Z" {
45
////}
56
////
6-
////{| "itemName": "'X2.Y2.Z2'", "kind": "module" |}
7+
////{| "itemName": "'X2.Y2.Z2'", "kind": "module", "parentName": "<global>" |}
78
////declare module 'X2.Y2.Z2' {
89
////}
910
////
10-
////{| "itemName": "A.B.C", "kind": "module" |}
11+
////{| "itemName": "A.B.C", "kind": "module", "parentName": "<global>" |}
1112
////module A.B.C {
1213
//// {| "itemName": "x", "kind": "var", "parentName": "A.B.C" |}
1314
//// export var x;
1415
////}
1516
////
16-
////{| "itemName": "A.B", "kind": "module" |}
17+
////{| "itemName": "A.B", "kind": "module", "parentName": "<global>" |}
1718
////module A.B {
1819
//// {| "itemName": "y", "kind": "var", "parentName": "A.B" |}
1920
//// export var y;
2021
////}
2122
////
22-
////{| "itemName": "A", "kind": "module" |}
23+
////{| "itemName": "A", "kind": "module", "parentName": "<global>" |}
2324
////module A {
2425
//// {| "itemName": "z", "kind": "var", "parentName": "A" |}
2526
//// export var z;
2627
////}
2728
////
28-
////{| "itemName": "A", "kind": "module" |}
29+
////{| "itemName": "A", "kind": "module", "parentName": "<global>" |}
2930
////module A {
30-
//// {| "itemName": "B", "kind": "module", "parentName": "" |}
31+
//// {| "itemName": "B", "kind": "module", "parentName": "A" |}
3132
//// module B {
32-
//// {| "itemName": "C", "kind": "module", "parentName": "" |}
33+
//// {| "itemName": "C", "kind": "module", "parentName": "B" |}
3334
//// module C {
3435
//// {| "itemName": "x", "kind": "var", "parentName": "C" |}
3536
//// declare var x;
@@ -45,4 +46,4 @@ test.markers().forEach((marker) => {
4546
/// We have 8 module keywords, and 4 var keywords.
4647
/// The declarations of A.B.C.x do not get merged, so the 4 vars are independent.
4748
/// The two 'A' modules, however, do get merged, so in reality we have 7 modules.
48-
verify.navigationBarCount(11);
49+
verify.navigationBarCount(19);

tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module" |}
2+
////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module", "parentName": "<global>" |}
33
////declare module "Multiline\r\nMadness" {
44
////}
55
////
6-
////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module" |}
6+
////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module", "parentName": "<global>" |}
77
////declare module "Multiline\
88
////Madness" {
99
////}
10-
////{| "itemName": "\"MultilineMadness\"", "kind": "module" |}
10+
////{| "itemName": "\"MultilineMadness\"", "kind": "module", "parentName": "<global>" |}
1111
////declare module "MultilineMadness" {}
1212
////
1313
////{| "itemName": "Foo", "kind": "interface", "parentName": "<global>" |}
@@ -38,4 +38,4 @@ test.markers().forEach((marker) => {
3838
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
3939
});
4040

41-
verify.navigationBarCount(12); // global + 1 child, interface w/ 2 properties, class w/ 2 properties, 3 modules
41+
verify.navigationBarCount(15);

tests/cases/fourslash/server/navbar01.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
////}
1111
////
1212
/////// Module
13-
////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes {
13+
////{| "itemName": "Shapes", "kind": "module", "parentName": "<global>" |}module Shapes {
1414
////
1515
//// // Class
1616
//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint {
@@ -49,4 +49,4 @@ test.markers().forEach((marker) => {
4949
}
5050
});
5151

52-
verify.navigationBarCount(26);
52+
verify.navigationBarCount(27);

0 commit comments

Comments
 (0)