Skip to content

Commit 5c6203c

Browse files
author
Andy Hanson
committed
Refactor navigation bar, fixing many bugs along the way
1 parent 1fc1813 commit 5c6203c

13 files changed

+744
-887
lines changed

src/harness/fourslash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,7 @@ namespace FourSlash {
19941994

19951995
public printNavigationBar(showChildItems = false) {
19961996
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
1997+
19971998
const length = items && items.length;
19981999

19992000
Harness.IO.log(`Navigation bar (${length} items)`);

src/services/navigationBar.ts

Lines changed: 350 additions & 756 deletions
Large diffs are not rendered by default.

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6867,7 +6867,7 @@ namespace ts {
68676867
function getNavigationBarItems(fileName: string): NavigationBarItem[] {
68686868
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
68696869

6870-
return NavigationBar.getNavigationBarItems(sourceFile, host.getCompilationSettings());
6870+
return NavigationBar.getNavigationBarItems(sourceFile);
68716871
}
68726872

68736873
function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {

tests/cases/fourslash/navbar_contains-no-duplicates.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ verify.navigationBar([
9595
"kindModifiers": "export,declare"
9696
},
9797
{
98-
"text": "Test",
99-
"kind": "class",
98+
"text": "B",
99+
"kind": "var",
100100
"kindModifiers": "export,declare"
101101
},
102102
{
103-
"text": "B",
104-
"kind": "var",
103+
"text": "Test",
104+
"kind": "class",
105105
"kindModifiers": "export,declare"
106106
},
107107
{

tests/cases/fourslash/navigationBarAnonymousDeclarationExpressions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,4 @@ verify.navigationBar([
144144
"kind": "class",
145145
"indent": 1
146146
}
147-
]
148-
);
147+
]);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class X {
4+
//// get x() {}
5+
//// set x(value) {
6+
//// // Inner declaration should make the setter top-level.
7+
//// function f() {}
8+
//// }
9+
////}
10+
11+
verify.navigationBar([
12+
{
13+
"text": "<global>",
14+
"kind": "module",
15+
"childItems": [
16+
{
17+
"text": "X",
18+
"kind": "class"
19+
}
20+
]
21+
},
22+
{
23+
"text": "X",
24+
"kind": "class",
25+
"childItems": [
26+
{
27+
"text": "x",
28+
"kind": "getter"
29+
},
30+
{
31+
"text": "x",
32+
"kind": "setter"
33+
}
34+
],
35+
"indent": 1
36+
},
37+
{
38+
"text": "x",
39+
"kind": "setter",
40+
"childItems": [
41+
{
42+
"text": "f",
43+
"kind": "function"
44+
}
45+
],
46+
"indent": 2
47+
}
48+
]);

tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="fourslash.ts"/>
22

33
////function f() {
4-
//// function;
4+
//// function; // This is not included as a navigation item, but it causes 'f' to be considered top-level.
55
////}
66

77
verify.navigationBar([

tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ verify.navigationBar([
7676
"kind": "property"
7777
}
7878
],
79-
"indent": 2
79+
"indent": 3
8080
},
8181
{
8282
"text": "LocalFunctionInConstructor",
8383
"kind": "function",
84-
"indent": 2
84+
"indent": 3
8585
},
8686
{
8787
"text": "LocalInterfaceInConstrcutor",
8888
"kind": "interface",
89-
"indent": 2
89+
"indent": 3
9090
},
9191
{
9292
"text": "method",
@@ -116,7 +116,7 @@ verify.navigationBar([
116116
"kind": "property"
117117
}
118118
],
119-
"indent": 2
119+
"indent": 3
120120
},
121121
{
122122
"text": "LocalFunctionInMethod",
@@ -127,11 +127,11 @@ verify.navigationBar([
127127
"kind": "function"
128128
}
129129
],
130-
"indent": 2
130+
"indent": 3
131131
},
132132
{
133133
"text": "LocalInterfaceInMethod",
134134
"kind": "interface",
135-
"indent": 2
135+
"indent": 3
136136
}
137137
]);

tests/cases/fourslash/navigationBarItemsMissingName1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//// foo() {}
44
////}
55

6-
verify.navigationBar( [
6+
verify.navigationBar([
77
{
88
"text": "\"navigationBarItemsMissingName1\"",
99
"kind": "module",

tests/cases/fourslash/navigationBarItemsMissingName2.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77

88
// Anonymous classes are still included.
99
verify.navigationBar([
10-
{
11-
"text": "<global>",
12-
"kind": "module",
13-
"childItems": [
14-
{
10+
{
11+
"text": "<global>",
12+
"kind": "module",
13+
"childItems": [
14+
{
15+
"text": "<class>",
16+
"kind": "class"
17+
}
18+
]
19+
},
20+
{
1521
"text": "<class>",
16-
"kind": "class"
17-
}
18-
]
19-
},
20-
{
21-
"text": "<class>",
22-
"kind": "class",
23-
"childItems": [
24-
{
25-
"text": "foo",
26-
"kind": "method"
27-
}
28-
],
29-
"indent": 1
30-
}
22+
"kind": "class",
23+
"childItems": [
24+
{
25+
"text": "foo",
26+
"kind": "method"
27+
}
28+
],
29+
"indent": 1
30+
}
3131
]);

0 commit comments

Comments
 (0)