Skip to content

Commit 0791bb0

Browse files
authored
Merge pull request #42332 from a-tarasyuk/fix/42259
fix(42259): Outline and breadcrumb show wrong namespace name
2 parents 896a2b4 + 8eaf58f commit 0791bb0

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

src/services/navigationBar.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ namespace ts.NavigationBar {
629629
case SyntaxKind.SetAccessor:
630630
return hasSyntacticModifier(a, ModifierFlags.Static) === hasSyntacticModifier(b, ModifierFlags.Static);
631631
case SyntaxKind.ModuleDeclaration:
632-
return areSameModule(<ModuleDeclaration>a, <ModuleDeclaration>b);
632+
return areSameModule(<ModuleDeclaration>a, <ModuleDeclaration>b)
633+
&& getFullyQualifiedModuleName(<ModuleDeclaration>a) === getFullyQualifiedModuleName(<ModuleDeclaration>b);
633634
default:
634635
return true;
635636
}
@@ -649,7 +650,6 @@ namespace ts.NavigationBar {
649650
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
650651
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
651652
function areSameModule(a: ModuleDeclaration, b: ModuleDeclaration): boolean {
652-
// TODO: GH#18217
653653
return a.body!.kind === b.body!.kind && (a.body!.kind !== SyntaxKind.ModuleDeclaration || areSameModule(<ModuleDeclaration>a.body, <ModuleDeclaration>b.body));
654654
}
655655

@@ -869,6 +869,10 @@ namespace ts.NavigationBar {
869869
return getTextOfNode(moduleDeclaration.name);
870870
}
871871

872+
return getFullyQualifiedModuleName(moduleDeclaration);
873+
}
874+
875+
function getFullyQualifiedModuleName(moduleDeclaration: ModuleDeclaration): string {
872876
// Otherwise, we need to aggregate each identifier to build up the qualified name.
873877
const result = [getTextOfIdentifierOrLiteral(moduleDeclaration.name)];
874878
while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////namespace Test.A { }
4+
////
5+
////namespace Test.B {
6+
//// class Foo { }
7+
////}
8+
9+
verify.navigationTree({
10+
text: "<global>",
11+
kind: "script",
12+
childItems: [
13+
{
14+
text: "Test.A",
15+
kind: "module"
16+
},
17+
{
18+
text: "Test.B",
19+
kind: "module",
20+
childItems: [
21+
{
22+
text: "Foo",
23+
kind: "class"
24+
}
25+
]
26+
}
27+
]
28+
});
29+
30+
verify.navigationBar([
31+
{
32+
text: "<global>",
33+
kind: "script",
34+
childItems: [
35+
{
36+
text: "Test.A",
37+
kind: "module"
38+
},
39+
{
40+
text: "Test.B",
41+
kind: "module"
42+
}
43+
]
44+
},
45+
{
46+
text: "Test.A",
47+
kind: "module",
48+
indent: 1
49+
},
50+
{
51+
text: "Test.B",
52+
kind: "module",
53+
childItems: [
54+
{
55+
text: "Foo",
56+
kind: "class"
57+
}
58+
],
59+
indent: 1
60+
},
61+
{
62+
text: "Foo",
63+
kind: "class",
64+
indent: 2
65+
}
66+
]);

0 commit comments

Comments
 (0)