Include modules as childItems in navigation bar
This commit is contained in:
parent
7173fa8d02
commit
109c05863e
8 changed files with 51 additions and 46 deletions
|
@ -320,6 +320,10 @@ namespace ts.NavigationBar {
|
|||
case SyntaxKind.EnumMember:
|
||||
return createItem(node, getTextOfNode((<EnumMember>node).name), ts.ScriptElementKind.memberVariableElement);
|
||||
|
||||
//move?
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return createItem(node, getModuleName(<ModuleDeclaration>node), ts.ScriptElementKind.moduleElement);
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
return createItem(node, "()", ts.ScriptElementKind.callSignatureElement);
|
||||
|
||||
|
@ -433,26 +437,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);
|
||||
|
||||
|
@ -587,6 +571,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);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/// <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": "wow", "kind": "method" |}public wow();
|
||||
|
@ -8,8 +8,8 @@
|
|||
//// }
|
||||
//// }
|
||||
////
|
||||
//// {| "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;
|
||||
|
@ -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;
|
||||
//// }
|
||||
|
||||
|
@ -38,4 +38,4 @@ test.markers().forEach(marker => {
|
|||
marker.position);
|
||||
}
|
||||
});
|
||||
verify.navigationBarCount(12);
|
||||
verify.navigationBarCount(17);
|
|
@ -10,7 +10,7 @@
|
|||
////}
|
||||
////
|
||||
/////// 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 {
|
||||
|
@ -49,4 +49,4 @@ test.markers().forEach((marker) => {
|
|||
}
|
||||
});
|
||||
|
||||
verify.navigationBarCount(24);
|
||||
verify.navigationBarCount(25);
|
||||
|
|
|
@ -8,5 +8,5 @@ edit.insertLine("module A");
|
|||
edit.insert("export class ");
|
||||
|
||||
// should not crash
|
||||
verify.navigationBarCount(2);
|
||||
verify.navigationBarCount(4);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -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);
|
||||
|
|
|
@ -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" |}
|
||||
|
@ -38,4 +38,4 @@ test.markers().forEach((marker) => {
|
|||
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
|
||||
});
|
||||
|
||||
verify.navigationBarCount(9); // interface w/ 2 properties, class w/ 2 properties, 3 modules
|
||||
verify.navigationBarCount(13);
|
|
@ -10,7 +10,7 @@
|
|||
////}
|
||||
////
|
||||
/////// 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 {
|
||||
|
@ -49,4 +49,4 @@ test.markers().forEach((marker) => {
|
|||
}
|
||||
});
|
||||
|
||||
verify.navigationBarCount(24);
|
||||
verify.navigationBarCount(25);
|
||||
|
|
Loading…
Reference in a new issue