diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 2896031eb960f..bcf0726ffd58d 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -320,9 +320,13 @@ namespace ts.NavigationBar { case SyntaxKind.EnumMember: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); + case SyntaxKind.ModuleDeclaration: + return createItem(node, getModuleName(node), ts.ScriptElementKind.moduleElement); + case SyntaxKind.InterfaceDeclaration: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.interfaceElement); + case SyntaxKind.CallSignature: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); @@ -333,6 +337,9 @@ namespace ts.NavigationBar { case SyntaxKind.PropertySignature: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); + case SyntaxKind.ClassDeclaration: + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.classElement); + case SyntaxKind.FunctionDeclaration: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); @@ -436,26 +443,6 @@ namespace ts.NavigationBar { return undefined; - function getModuleName(moduleDeclaration: ModuleDeclaration): string { - // We want to maintain quotation marks. - if (isAmbientModule(moduleDeclaration)) { - return getTextOfNode(moduleDeclaration.name); - } - - // Otherwise, we need to aggregate each identifier to build up the qualified name. - const result: string[] = []; - - result.push(moduleDeclaration.name.text); - - while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) { - moduleDeclaration = moduleDeclaration.body; - - result.push(moduleDeclaration.name.text); - } - - return result.join("."); - } - function createModuleItem(node: ModuleDeclaration): NavigationBarItem { const moduleName = getModuleName(node); @@ -590,6 +577,26 @@ namespace ts.NavigationBar { } } + function getModuleName(moduleDeclaration: ModuleDeclaration): string { + // We want to maintain quotation marks. + if (isAmbientModule(moduleDeclaration)) { + return getTextOfNode(moduleDeclaration.name); + } + + // Otherwise, we need to aggregate each identifier to build up the qualified name. + const result: string[] = []; + + result.push(moduleDeclaration.name.text); + + while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) { + moduleDeclaration = moduleDeclaration.body; + + result.push(moduleDeclaration.name.text); + } + + return result.join("."); + } + function removeComputedProperties(node: EnumDeclaration): Declaration[] { return filter(node.members, member => member.name === undefined || member.name.kind !== SyntaxKind.ComputedPropertyName); } diff --git a/tests/cases/fourslash/getNavigationBarItems.ts b/tests/cases/fourslash/getNavigationBarItems.ts index 8e9b8de5b051c..cd09f61011e97 100644 --- a/tests/cases/fourslash/getNavigationBarItems.ts +++ b/tests/cases/fourslash/getNavigationBarItems.ts @@ -5,7 +5,7 @@ //// ["bar"]: string; ////} -verify.navigationBarCount(3); +verify.navigationBarCount(5); verify.navigationBarContains("C", "class"); verify.navigationBarChildItem("C", "[\"bar\"]", "property"); verify.navigationBarChildItem("C", "foo", "property"); diff --git a/tests/cases/fourslash/navbar_contains-no-duplicates.ts b/tests/cases/fourslash/navbar_contains-no-duplicates.ts index ec86e4b2f201a..42b33a722ada5 100644 --- a/tests/cases/fourslash/navbar_contains-no-duplicates.ts +++ b/tests/cases/fourslash/navbar_contains-no-duplicates.ts @@ -1,15 +1,15 @@ /// -//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "" |}export module Foundation { +//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows { +//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows" |}export module Foundation { //// export var {| "itemName": "A", "kind": "var" |}A; -//// {| "itemName": "Test", "kind": "class" |}export class Test { +//// {| "itemName": "Test", "kind": "class", "parentName": "Foundation" |}export class Test { //// {| "itemName": "wow", "kind": "method" |}public wow(); //// } //// } //// } //// -//// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "", "isAdditionalRange": true |}export module Foundation { +//// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows { +//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows", "isAdditionalRange": true |}export module Foundation { //// export var {| "itemName": "B", "kind": "var" |}B; //// {| "itemName": "Test", "kind": "module" |}export module Test { //// {| "itemName": "Boom", "kind": "function" |}export function Boom(): number; @@ -23,7 +23,7 @@ //// } //// } //// -//// {| "itemName": "ABC", "kind": "module", "parentName": "" |}module ABC { +//// {| "itemName": "ABC", "kind": "module", "parentName": "" |}module ABC { //// export var {| "itemName": "x", "kind": "var" |}x = 3; //// } @@ -38,4 +38,5 @@ test.markers().forEach(marker => { marker.position); } }); -verify.navigationBarCount(12); \ No newline at end of file + +verify.navigationBarCount(19); diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts index 84c1d09efe7fb..24979e141e541 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts @@ -11,4 +11,4 @@ //// } ////} -verify.navigationBarCount(6); // 2x(class + field + constructor) +verify.navigationBarCount(9); // global + 2 children + 2x(class + field + constructor) diff --git a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts index 2255d29e293b8..a80f4c596d49e 100644 --- a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts @@ -9,4 +9,4 @@ verify.navigationBarContains("Test", "class"); verify.navigationBarContains("constructor", "constructor"); // no other items -verify.navigationBarCount(2); \ No newline at end of file +verify.navigationBarCount(4); // global + 1 child, Test + 1 child \ No newline at end of file diff --git a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts index d6fb0a91eb2ae..8d93d241ae195 100644 --- a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts @@ -39,4 +39,4 @@ test.markers().forEach((marker) => { }); // no other items -verify.navigationBarCount(21); +verify.navigationBarCount(23); diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index d9ae3d35dff4b..e8e9fd40824cb 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -10,10 +10,10 @@ ////} //// /////// Module -////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { +////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { +//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { //// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } //// //// // Instance member @@ -49,4 +49,4 @@ test.markers().forEach((marker) => { } }); -verify.navigationBarCount(25); +verify.navigationBarCount(27); diff --git a/tests/cases/fourslash/navigationBarItemsItems2.ts b/tests/cases/fourslash/navigationBarItemsItems2.ts index d4ffde5405193..013f27b4d716b 100644 --- a/tests/cases/fourslash/navigationBarItemsItems2.ts +++ b/tests/cases/fourslash/navigationBarItemsItems2.ts @@ -8,5 +8,5 @@ edit.insertLine("module A"); edit.insert("export class "); // should not crash -verify.navigationBarCount(2); +verify.navigationBarCount(4); diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts index 64a595cafb19e..7b2e0def4bf2b 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts @@ -1,6 +1,6 @@ /// -////{| "itemName": "Bar", "kind": "class" |}export class Bar { +////{| "itemName": "Bar", "kind": "class", "parentName": "\"navigationBarItemsItemsExternalModules\"" |}export class Bar { //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} @@ -8,4 +8,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(2); // external module node + class + property +verify.navigationBarCount(4); // external module node + class + property diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts index 7c1c32cff7645..9087493b298b4 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts @@ -1,7 +1,7 @@ /// // @Filename: test/file.ts -////{| "itemName": "Bar", "kind": "class" |}export class Bar { +////{| "itemName": "Bar", "kind": "class", "parentName": "\"file\"" |}export class Bar { //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} ////{| "itemName": "\"file\"", "kind": "module" |} @@ -12,4 +12,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(4); // external module node + variable in module + class + property +verify.navigationBarCount(5); // external module node + variable in module + class + property diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts index 6e6dc9871cc48..a00b3a131dd10 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts @@ -1,7 +1,7 @@ /// // @Filename: test/my fil"e.ts -////{| "itemName": "Bar", "kind": "class" |}export class Bar { +////{| "itemName": "Bar", "kind": "class", "parentName": "\"my fil\\\"e\"" |}export class Bar { //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} ////{| "itemName": "\"my fil\\\"e\"", "kind": "module" |} @@ -12,4 +12,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(4); // external module node + variable in module + class + property +verify.navigationBarCount(5); // external module node + 2 children + class + property diff --git a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts index afc1acfb9cb01..5429011888c03 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts @@ -22,9 +22,9 @@ goTo.marker("file1"); verify.navigationBarContains("Module1", "module"); verify.navigationBarContains("x", "var"); // nothing else should show up -verify.navigationBarCount(2); +verify.navigationBarCount(4); // , its child, Module1, its child goTo.marker("file2"); verify.navigationBarContains("Module1.SubModule", "module"); verify.navigationBarContains("y", "var"); -verify.navigationBarCount(2); +verify.navigationBarCount(4); diff --git a/tests/cases/fourslash/navigationBarItemsMissingName1.ts b/tests/cases/fourslash/navigationBarItemsMissingName1.ts index 98321039c5af9..59f2911f3aaa7 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName1.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName1.ts @@ -2,7 +2,7 @@ /////** //// * This is a class. //// */ -////{| "itemName": "C", "kind": "class" |} class C { +////{| "itemName": "C", "kind": "class", "parentName": "\"navigationBarItemsMissingName1\"" |} class C { //// {| "itemName": "foo", "kind": "method" |} foo() { //// } ////} @@ -12,5 +12,5 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -/// Only have two named elements. -verify.navigationBarCount(2); +/// Root + 1 child, class + 1 child +verify.navigationBarCount(4); diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts index 895a9e23a06e8..237ec8eb275ef 100644 --- a/tests/cases/fourslash/navigationBarItemsModules.ts +++ b/tests/cases/fourslash/navigationBarItemsModules.ts @@ -1,35 +1,36 @@ +/// -////{| "itemName": "\"X.Y.Z\"", "kind": "module" |} +////{| "itemName": "\"X.Y.Z\"", "kind": "module", "parentName": "" |} ////declare module "X.Y.Z" { ////} //// -////{| "itemName": "'X2.Y2.Z2'", "kind": "module" |} +////{| "itemName": "'X2.Y2.Z2'", "kind": "module", "parentName": "" |} ////declare module 'X2.Y2.Z2' { ////} //// -////{| "itemName": "A.B.C", "kind": "module" |} +////{| "itemName": "A.B.C", "kind": "module", "parentName": "" |} ////module A.B.C { //// {| "itemName": "x", "kind": "var", "parentName": "A.B.C" |} //// export var x; ////} //// -////{| "itemName": "A.B", "kind": "module" |} +////{| "itemName": "A.B", "kind": "module", "parentName": "" |} ////module A.B { //// {| "itemName": "y", "kind": "var", "parentName": "A.B" |} //// export var y; ////} //// -////{| "itemName": "A", "kind": "module" |} +////{| "itemName": "A", "kind": "module", "parentName": "" |} ////module A { //// {| "itemName": "z", "kind": "var", "parentName": "A" |} //// export var z; ////} //// -////{| "itemName": "A", "kind": "module" |} +////{| "itemName": "A", "kind": "module", "parentName": "" |} ////module A { -//// {| "itemName": "B", "kind": "module", "parentName": "" |} +//// {| "itemName": "B", "kind": "module", "parentName": "A" |} //// module B { -//// {| "itemName": "C", "kind": "module", "parentName": "" |} +//// {| "itemName": "C", "kind": "module", "parentName": "B" |} //// module C { //// {| "itemName": "x", "kind": "var", "parentName": "C" |} //// declare var x; @@ -45,4 +46,4 @@ test.markers().forEach((marker) => { /// We have 8 module keywords, and 4 var keywords. /// The declarations of A.B.C.x do not get merged, so the 4 vars are independent. /// The two 'A' modules, however, do get merged, so in reality we have 7 modules. -verify.navigationBarCount(11); +verify.navigationBarCount(19); diff --git a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts index f779c7a058098..6bd3d799171d5 100644 --- a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts +++ b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts @@ -1,13 +1,13 @@ -////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module" |} +////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module", "parentName": "" |} ////declare module "Multiline\r\nMadness" { ////} //// -////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module" |} +////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module", "parentName": "" |} ////declare module "Multiline\ ////Madness" { ////} -////{| "itemName": "\"MultilineMadness\"", "kind": "module" |} +////{| "itemName": "\"MultilineMadness\"", "kind": "module", "parentName": "" |} ////declare module "MultilineMadness" {} //// ////{| "itemName": "Foo", "kind": "interface", "parentName": "" |} @@ -20,7 +20,7 @@ //// b"(): Foo; ////} //// -////{| "itemName": "Bar", "kind": "class" |} +////{| "itemName": "Bar", "kind": "class", "parentName": "" |} ////class Bar implements Foo { //// {| "itemName": "'a1\\\\\\r\\nb'", "kind": "property", "parentName": "Bar" |} //// 'a1\\\r\nb': Foo; @@ -38,4 +38,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(11); // interface w/ 2 properties, class w/ 2 properties, 3 modules \ No newline at end of file +verify.navigationBarCount(15); diff --git a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts index 9b3f4aacd9cdc..8e1981f6101c1 100644 --- a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts @@ -12,4 +12,4 @@ verify.navigationBarContains("a", "property"); verify.navigationBarContains("b", "property"); // no other items -verify.navigationBarCount(4); \ No newline at end of file +verify.navigationBarCount(6); \ No newline at end of file diff --git a/tests/cases/fourslash/navigationBarItemsSymbols1.ts b/tests/cases/fourslash/navigationBarItemsSymbols1.ts index c9df85b3ece49..6d55812fa0e29 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols1.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols1.ts @@ -1,6 +1,6 @@ /// -////{| "itemName": "C", "kind": "class", "parentName": "" |} +////{| "itemName": "C", "kind": "class", "parentName": "" |} ////class C { //// {| "itemName": "[Symbol.isRegExp]", "kind": "property", "parentName": "C" |} //// [Symbol.isRegExp] = 0; @@ -14,4 +14,5 @@ test.markers().forEach(marker => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(test.markers().length); \ No newline at end of file +// 2 lack markers: and its child +verify.navigationBarCount(2 + test.markers().length); \ No newline at end of file diff --git a/tests/cases/fourslash/server/navbar01.ts b/tests/cases/fourslash/server/navbar01.ts index 05e92c2835f94..fea424317dbe8 100644 --- a/tests/cases/fourslash/server/navbar01.ts +++ b/tests/cases/fourslash/server/navbar01.ts @@ -10,10 +10,10 @@ ////} //// /////// Module -////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { +////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { +//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { //// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } //// //// // Instance member @@ -49,4 +49,4 @@ test.markers().forEach((marker) => { } }); -verify.navigationBarCount(25); +verify.navigationBarCount(27);