Skip to content

Include modules as childItems in navigation bar #8814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
6 commits merged into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions src/services/navigationBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,13 @@ namespace ts.NavigationBar {
case SyntaxKind.EnumMember:
return createItem(node, getTextOfNode((<EnumMember>node).name), ts.ScriptElementKind.memberVariableElement);

case SyntaxKind.ModuleDeclaration:
return createItem(node, getModuleName(<ModuleDeclaration>node), ts.ScriptElementKind.moduleElement);

case SyntaxKind.InterfaceDeclaration:
return createItem(node, getTextOfNode((<InterfaceDeclaration>node).name), ts.ScriptElementKind.interfaceElement);


case SyntaxKind.CallSignature:
return createItem(node, "()", ts.ScriptElementKind.callSignatureElement);

Expand All @@ -333,6 +337,9 @@ namespace ts.NavigationBar {
case SyntaxKind.PropertySignature:
return createItem(node, getTextOfNode((<PropertyDeclaration>node).name), ts.ScriptElementKind.memberVariableElement);

case SyntaxKind.ClassDeclaration:
return createItem(node, getTextOfNode((<ClassDeclaration>node).name), ts.ScriptElementKind.classElement);

case SyntaxKind.FunctionDeclaration:
return createItem(node, getTextOfNode((<FunctionLikeDeclaration>node).name), ts.ScriptElementKind.functionElement);

Expand Down Expand Up @@ -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>moduleDeclaration.body;

result.push(moduleDeclaration.name.text);
}

return result.join(".");
}

function createModuleItem(node: ModuleDeclaration): NavigationBarItem {
const moduleName = getModuleName(node);

Expand Down Expand Up @@ -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>moduleDeclaration.body;

result.push(moduleDeclaration.name.text);
}

return result.join(".");
}

function removeComputedProperties(node: EnumDeclaration): Declaration[] {
return filter<Declaration>(node.members, member => member.name === undefined || member.name.kind !== SyntaxKind.ComputedPropertyName);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/fourslash/getNavigationBarItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
15 changes: 8 additions & 7 deletions tests/cases/fourslash/navbar_contains-no-duplicates.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/// <reference path="fourslash.ts" />
//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows {
//// {| "itemName": "Foundation", "kind": "module", "parentName": "" |}export module Foundation {
//// {| "itemName": "Windows", "kind": "module", "parentName": "<global>" |}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": "<global>", "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;
Expand All @@ -23,7 +23,7 @@
//// }
//// }
////
//// {| "itemName": "ABC", "kind": "module", "parentName": "" |}module ABC {
//// {| "itemName": "ABC", "kind": "module", "parentName": "<global>" |}module ABC {
//// export var {| "itemName": "x", "kind": "var" |}x = 3;
//// }

Expand All @@ -38,4 +38,5 @@ test.markers().forEach(marker => {
marker.position);
}
});
verify.navigationBarCount(12);

verify.navigationBarCount(19);
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
//// }
////}

verify.navigationBarCount(6); // 2x(class + field + constructor)
verify.navigationBarCount(9); // global + 2 children + 2x(class + field + constructor)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ verify.navigationBarContains("Test", "class");
verify.navigationBarContains("constructor", "constructor");

// no other items
verify.navigationBarCount(2);
verify.navigationBarCount(4); // global + 1 child, Test + 1 child
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ test.markers().forEach((marker) => {
});

// no other items
verify.navigationBarCount(21);
verify.navigationBarCount(23);
6 changes: 3 additions & 3 deletions tests/cases/fourslash/navigationBarItemsItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
////}
////
/////// Module
////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes {
////{| "itemName": "Shapes", "kind": "module", "parentName": "<global>" |}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
Expand Down Expand Up @@ -49,4 +49,4 @@ test.markers().forEach((marker) => {
}
});

verify.navigationBarCount(25);
verify.navigationBarCount(27);
2 changes: 1 addition & 1 deletion tests/cases/fourslash/navigationBarItemsItems2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edit.insertLine("module A");
edit.insert("export class ");

// should not crash
verify.navigationBarCount(2);
verify.navigationBarCount(4);

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// <reference path="fourslash.ts"/>

////{| "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;
////}

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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="fourslash.ts"/>

// @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" |}
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="fourslash.ts"/>

// @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" |}
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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); // <global>, its child, Module1, its child

goTo.marker("file2");
verify.navigationBarContains("Module1.SubModule", "module");
verify.navigationBarContains("y", "var");
verify.navigationBarCount(2);
verify.navigationBarCount(4);
6 changes: 3 additions & 3 deletions tests/cases/fourslash/navigationBarItemsMissingName1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
//// }
////}
Expand All @@ -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);
19 changes: 10 additions & 9 deletions tests/cases/fourslash/navigationBarItemsModules.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
/// <reference path="fourslash.ts"/>

////{| "itemName": "\"X.Y.Z\"", "kind": "module" |}
////{| "itemName": "\"X.Y.Z\"", "kind": "module", "parentName": "<global>" |}
////declare module "X.Y.Z" {
////}
////
////{| "itemName": "'X2.Y2.Z2'", "kind": "module" |}
////{| "itemName": "'X2.Y2.Z2'", "kind": "module", "parentName": "<global>" |}
////declare module 'X2.Y2.Z2' {
////}
////
////{| "itemName": "A.B.C", "kind": "module" |}
////{| "itemName": "A.B.C", "kind": "module", "parentName": "<global>" |}
////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": "<global>" |}
////module A.B {
//// {| "itemName": "y", "kind": "var", "parentName": "A.B" |}
//// export var y;
////}
////
////{| "itemName": "A", "kind": "module" |}
////{| "itemName": "A", "kind": "module", "parentName": "<global>" |}
////module A {
//// {| "itemName": "z", "kind": "var", "parentName": "A" |}
//// export var z;
////}
////
////{| "itemName": "A", "kind": "module" |}
////{| "itemName": "A", "kind": "module", "parentName": "<global>" |}
////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;
Expand All @@ -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);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module" |}
////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module", "parentName": "<global>" |}
////declare module "Multiline\r\nMadness" {
////}
////
////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module" |}
////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module", "parentName": "<global>" |}
////declare module "Multiline\
////Madness" {
////}
////{| "itemName": "\"MultilineMadness\"", "kind": "module" |}
////{| "itemName": "\"MultilineMadness\"", "kind": "module", "parentName": "<global>" |}
////declare module "MultilineMadness" {}
////
////{| "itemName": "Foo", "kind": "interface", "parentName": "<global>" |}
Expand All @@ -20,7 +20,7 @@
//// b"(): Foo;
////}
////
////{| "itemName": "Bar", "kind": "class" |}
////{| "itemName": "Bar", "kind": "class", "parentName": "<global>" |}
////class Bar implements Foo {
//// {| "itemName": "'a1\\\\\\r\\nb'", "kind": "property", "parentName": "Bar" |}
//// 'a1\\\r\nb': Foo;
Expand All @@ -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
verify.navigationBarCount(15);
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ verify.navigationBarContains("a", "property");
verify.navigationBarContains("b", "property");

// no other items
verify.navigationBarCount(4);
verify.navigationBarCount(6);
5 changes: 3 additions & 2 deletions tests/cases/fourslash/navigationBarItemsSymbols1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="fourslash.ts"/>

////{| "itemName": "C", "kind": "class", "parentName": "" |}
////{| "itemName": "C", "kind": "class", "parentName": "<global>" |}
////class C {
//// {| "itemName": "[Symbol.isRegExp]", "kind": "property", "parentName": "C" |}
//// [Symbol.isRegExp] = 0;
Expand All @@ -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);
// 2 lack markers: <global> and its child
verify.navigationBarCount(2 + test.markers().length);
6 changes: 3 additions & 3 deletions tests/cases/fourslash/server/navbar01.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
////}
////
/////// Module
////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes {
////{| "itemName": "Shapes", "kind": "module", "parentName": "<global>" |}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
Expand Down Expand Up @@ -49,4 +49,4 @@ test.markers().forEach((marker) => {
}
});

verify.navigationBarCount(25);
verify.navigationBarCount(27);