Skip to content
11 changes: 11 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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[];
if (array) {
Expand Down
1,122 changes: 398 additions & 724 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 @@ -6867,7 +6867,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
2 changes: 1 addition & 1 deletion tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ declare namespace FourSlashInterface {
printBreakpointAtCurrentLocation(): void;
printNameOrDottedNameSpans(pos: number): void;
printErrorList(): void;
printNavigationBar(): void;
printNavigationBar(showChildItems?: boolean): void;
printNavigationItems(searchValue?: string): void;
printScriptLexicalStructureItems(): void;
printReferences(): void;
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
147 changes: 147 additions & 0 deletions tests/cases/fourslash/navigationBarAnonymousDeclarationExpressions.ts
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
}
]);
76 changes: 76 additions & 0 deletions tests/cases/fourslash/navigationBarDeclarationExpressions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/// <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
}
]);

/*
verify.navigationBarCount(6);
verify.navigationBarIndex("A", 0);
verify.navigationBarIndex("B", 1);
verify.navigationBarIndex("Cls", 2);
verify.navigationBarIndex("X", 3);
verify.navigationBarIndex("Y", 4);

verify.navigationBarContains("Cls", "class");
verify.navigationBarChildItem("Cls", "meth", "method");
*/
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
Loading