Skip to content

Commit f822296

Browse files
committed
[SymbolGraph] Use fully qualified name for type's page titles
rdar://64047985
1 parent 8f0569d commit f822296

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

lib/SymbolGraphGen/Symbol.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,22 @@ void Symbol::serializeNames(llvm::json::OStream &OS) const {
125125
OS.attributeObject("names", [&](){
126126
SmallVector<SmallString<32>, 8> PathComponents;
127127
getPathComponents(PathComponents);
128-
129-
OS.attribute("title", PathComponents.back());
128+
129+
if (isa<GenericTypeDecl>(VD)) {
130+
SmallString<64> FullyQualifiedTitle;
131+
132+
for (const auto *It = PathComponents.begin(); It != PathComponents.end(); ++It) {
133+
if (It != PathComponents.begin()) {
134+
FullyQualifiedTitle.push_back('.');
135+
}
136+
FullyQualifiedTitle.append(*It);
137+
}
138+
139+
OS.attribute("title", FullyQualifiedTitle.str());
140+
} else {
141+
OS.attribute("title", PathComponents.back());
142+
}
143+
130144
Graph->serializeNavigatorDeclarationFragments("navigator", *this, OS);
131145
Graph->serializeSubheadingDeclarationFragments("subHeading", *this, OS);
132146
// "prose": null

test/SymbolGraph/Symbols/Names.swift

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,30 @@
22
// RUN: %target-build-swift %s -module-name Names -emit-module -emit-module-path %t/
33
// RUN: %target-swift-symbolgraph-extract -module-name Names -I %t -pretty-print -output-dir %t
44
// RUN: %FileCheck %s --input-file %t/Names.symbols.json
5+
// RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=FUNC
6+
// RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=INNERTYPE
7+
// RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=INNERTYPEALIAS
58

6-
public struct MyStruct {}
9+
public struct MyStruct {
10+
public struct InnerStruct {}
711

12+
public typealias InnerTypeAlias = InnerStruct
13+
14+
public func foo() {}
15+
}
16+
17+
// CHECK-LABEL: "precise": "s:5Names8MyStructV"
818
// CHECK: names
919
// CHECK-NEXT: "title": "MyStruct"
20+
21+
// FUNC-LABEL: "precise": "s:5Names8MyStructV3fooyyF",
22+
// FUNC: names
23+
// FUNC-NEXT: "title": "foo()"
24+
25+
// INNERTYPE-LABEL: "precise": "s:5Names8MyStructV05InnerC0V"
26+
// INNERTYPE: names
27+
// INNERTYPE-NEXT: "title": "MyStruct.InnerStruct"
28+
29+
// INNERTYPEALIAS-LABEL: "precise": "s:5Names8MyStructV14InnerTypeAliasa"
30+
// INNERTYPEALIAS: names
31+
// INNERTYPEALIAS-NEXT: "title": "MyStruct.InnerTypeAlias"

0 commit comments

Comments
 (0)