Skip to content

Navigation bar class expression #8648

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

Closed
wants to merge 9 commits into from
6 changes: 3 additions & 3 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ namespace FourSlash {
}
}

public printNavigationBar() {
public printNavigationBar(showChildItems = false) {
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
const length = items && items.length;

Expand Down Expand Up @@ -3190,8 +3190,8 @@ namespace FourSlashInterface {
this.state.printNavigationItems(searchValue);
}

public printNavigationBar() {
this.state.printNavigationBar();
public printNavigationBar(showChildItems = false) {
this.state.printNavigationBar(showChildItems);
}

public printReferences() {
Expand Down
334 changes: 205 additions & 129 deletions src/services/navigationBar.ts

Large diffs are not rendered by default.

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
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
148 changes: 148 additions & 0 deletions tests/cases/fourslash/navigationBarAnonymousDeclarationExpressions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/// <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");
*/
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
}
]);
10 changes: 10 additions & 0 deletions tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ verify.navigationBar([
"text": "<global>",
"kind": "module",
"childItems": [
{
"text": "<function>",
"kind": "function"
},
{
"text": "f",
"kind": "function"
Expand All @@ -19,6 +23,12 @@ verify.navigationBar([
{
"text": "f",
"kind": "function",
"childItems": [
{
"text": "<function>",
"kind": "function"
}
],
"indent": 1
}
]);
7 changes: 6 additions & 1 deletion tests/cases/fourslash/navigationBarItemsItems2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ verify.navigationBar([
"text": "\"navigationBarItemsItems2\"",
"kind": "module",
"childItems": [
{
"text": "<class>",
"kind": "class",
"kindModifiers": "export"
},
{
"text": "A",
"kind": "module"
}
]
},
{
"text": "default",
"text": "<class>",
"kind": "class",
"kindModifiers": "export",
"indent": 1
Expand Down
Loading