Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Refactor navigation bar
  • Loading branch information
Andy Hanson committed Jun 3, 2016
commit 11b72913932acee42b2c20a64c62763640b128eb
11 changes: 11 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ namespace ts {
}
return result;
}

export function filterMutate<T>(array: T[], f: (x: T) => boolean): void {
let outIndex = 0;
for (const item of array) {
if (f(item)) {
array[outIndex] = item;
outIndex++;
}
}
array.length = outIndex;
}

export function map<T, U>(array: T[], f: (x: T) => U): U[] {
let result: U[];
Expand Down
1,178 changes: 431 additions & 747 deletions src/services/navigationBar.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6881,7 +6881,7 @@ namespace ts {
function getNavigationBarItems(fileName: string): NavigationBarItem[] {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);

return NavigationBar.getNavigationBarItems(sourceFile, host.getCompilationSettings());
return NavigationBar.getNavigationBarItems(sourceFile);
}

function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
Expand Down
8 changes: 4 additions & 4 deletions tests/cases/fourslash/navbar_contains-no-duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ verify.navigationBar([
"kindModifiers": "export,declare"
},
{
"text": "Test",
"kind": "class",
"text": "B",
"kind": "var",
"kindModifiers": "export,declare"
},
{
"text": "B",
"kind": "var",
"text": "Test",
"kind": "class",
"kindModifiers": "export,declare"
},
{
Expand Down
16 changes: 15 additions & 1 deletion tests/cases/fourslash/navbar_exportDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ goTo.file("a.ts");
verify.navigationBar([
{
"text": "\"a\"",
"kind": "module"
"kind": "module",
"childItems": [
{
"text": "default",
"kind": "class",
"kindModifiers": "export"
}
]
},
{
"text": "default",
Expand Down Expand Up @@ -52,6 +59,13 @@ verify.navigationBar([
{
"text": "\"c\"",
"kind": "module",
"childItems": [
{
"text": "default",
"kind": "function",
"kindModifiers": "export"
}
]
},
{
"text": "default",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/// <reference path="fourslash.ts" />

////global.cls = class { };
////(function() {
//// const x = () => {
//// // Presence of inner function causes x to be a top-level function.
//// function xx() {}
//// };
//// const y = {
//// // This is not a top-level function (contains nothing, but shows up in childItems of its parent.)
//// foo: function() {}
//// };
//// (function nest() {
//// function moreNest() {}
//// })();
////})();
////(function() { // Different anonymous functions are not merged
//// // These will only show up as childItems.
//// function z() {}
//// console.log(function() {})
////})
////(function classes() {
//// // Classes show up in top-level regardless of whether they have names or inner declarations.
//// const cls2 = class { };
//// console.log(class cls3 {});
//// (class { });
////})

verify.navigationBar([
{
"text": "<global>",
"kind": "module",
"childItems": [
{
"text": "<function>",
"kind": "function"
},
{
"text": "<function>",
"kind": "function"
},
{
"text": "classes",
"kind": "function"
},
{
"text": "global.cls",
"kind": "class"
}
]
},
{
"text": "<function>",
"kind": "function",
"childItems": [
{
"text": "nest",
"kind": "function"
},
{
"text": "x",
"kind": "function"
},
{
"text": "y",
"kind": "const"
}
],
"indent": 1
},
{
"text": "nest",
"kind": "function",
"childItems": [
{
"text": "moreNest",
"kind": "function"
}
],
"indent": 2
},
{
"text": "x",
"kind": "function",
"childItems": [
{
"text": "xx",
"kind": "function"
}
],
"indent": 2
},
{
"text": "<function>",
"kind": "function",
"childItems": [
{
"text": "<function>",
"kind": "function"
},
{
"text": "z",
"kind": "function"
}
],
"indent": 1
},
{
"text": "classes",
"kind": "function",
"childItems": [
{
"text": "<class>",
"kind": "class"
},
{
"text": "cls2",
"kind": "class"
},
{
"text": "cls3",
"kind": "class"
}
],
"indent": 1
},
{
"text": "<class>",
"kind": "class",
"indent": 2
},
{
"text": "cls2",
"kind": "class",
"indent": 2
},
{
"text": "cls3",
"kind": "class",
"indent": 2
},
{
"text": "global.cls",
"kind": "class",
"indent": 1
}
]);
64 changes: 64 additions & 0 deletions tests/cases/fourslash/navigationBarDeclarationExpressions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// <reference path="fourslash.ts" />

////console.log(console.log(class Y {}, class X {}), console.log(class B {}, class A {}));
////console.log(class Cls { meth() {} });

verify.navigationBar([
{
"text": "<global>",
"kind": "module",
"childItems": [
{
"text": "A",
"kind": "class"
},
{
"text": "B",
"kind": "class"
},
{
"text": "Cls",
"kind": "class"
},
{
"text": "X",
"kind": "class"
},
{
"text": "Y",
"kind": "class"
}
]
},
{
"text": "A",
"kind": "class",
"indent": 1
},
{
"text": "B",
"kind": "class",
"indent": 1
},
{
"text": "Cls",
"kind": "class",
"childItems": [
{
"text": "meth",
"kind": "method"
}
],
"indent": 1
},
{
"text": "X",
"kind": "class",
"indent": 1
},
{
"text": "Y",
"kind": "class",
"indent": 1
}
]);
48 changes: 48 additions & 0 deletions tests/cases/fourslash/navigationBarGetterAndSetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/// <reference path="fourslash.ts" />

////class X {
//// get x() {}
//// set x(value) {
//// // Inner declaration should make the setter top-level.
//// function f() {}
//// }
////}

verify.navigationBar([
{
"text": "<global>",
"kind": "module",
"childItems": [
{
"text": "X",
"kind": "class"
}
]
},
{
"text": "X",
"kind": "class",
"childItems": [
{
"text": "x",
"kind": "getter"
},
{
"text": "x",
"kind": "setter"
}
],
"indent": 1
},
{
"text": "x",
"kind": "setter",
"childItems": [
{
"text": "f",
"kind": "function"
}
],
"indent": 2
}
]);
14 changes: 14 additions & 0 deletions tests/cases/fourslash/navigationBarItemsFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ verify.navigationBar([
{
"text": "baz",
"kind": "function",
"childItems": [
{
"text": "v",
"kind": "var"
}
],
"indent": 1
},
{
Expand All @@ -41,6 +47,10 @@ verify.navigationBar([
{
"text": "bar",
"kind": "function"
},
{
"text": "x",
"kind": "var"
}
],
"indent": 1
Expand All @@ -52,6 +62,10 @@ verify.navigationBar([
{
"text": "biz",
"kind": "function"
},
{
"text": "y",
"kind": "var"
}
],
"indent": 2
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ verify.navigationBar([
{
"text": "f",
"kind": "function",
"childItems": [
{
"text": "<function>",
"kind": "function"
}
],
"indent": 1
}
]);
Loading