Skip to content

Commit 3c30e2f

Browse files
add support for C++ symbol graphs and namespace symbols (#766)
rdar://117904448
1 parent 1f82c3b commit 3c30e2f

File tree

9 files changed

+205
-4
lines changed

9 files changed

+205
-4
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftDocC/Infrastructure/Topic Graph/AutomaticCuration.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ extension AutomaticCuration {
205205
case .ivar: return "Instance Variables"
206206
case .macro: return "Macros"
207207
case .`method`: return "Instance Methods"
208+
case .namespace: return "Namespaces"
208209
case .`property`: return "Instance Properties"
209210
case .`protocol`: return "Protocols"
210211
case .`struct`: return "Structures"
@@ -230,6 +231,8 @@ extension AutomaticCuration {
230231
/// Add a symbol kind to `KindIdentifier.noPageKinds` if it should not generate a page in the
231232
/// documentation hierarchy.
232233
static let groupKindOrder: [SymbolGraph.Symbol.KindIdentifier] = [
234+
.namespace,
235+
233236
.`class`,
234237
.`protocol`,
235238
.`struct`,

Sources/SwiftDocC/Model/DocumentationNode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ public struct DocumentationNode {
533533
case .ivar: return .instanceVariable
534534
case .macro: return .macro
535535
case .`method`: return .instanceMethod
536+
case .namespace: return .namespace
536537
case .`property`: return .instanceProperty
537538
case .`protocol`: return .protocol
538539
case .snippet: return .snippet

Sources/SwiftDocC/Model/Kind.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ extension DocumentationNode.Kind {
9595
public static let dictionary = DocumentationNode.Kind(name: "Dictionary", id: "org.swift.docc.kind.dictionary", isSymbol: true)
9696
/// Documentation about an HTTP request.
9797
public static let httpRequest = DocumentationNode.Kind(name: "HTTP Request", id: "org.swift.docc.kind.httpRequest", isSymbol: true)
98-
98+
/// Documentation about a namespace.
99+
public static let namespace = DocumentationNode.Kind(name: "Namespace", id: "org.swift.docc.kind.namespace", isSymbol: true)
100+
99101
// Leaves
100102

101103
/// Documentation about a local variable.
@@ -192,7 +194,7 @@ extension DocumentationNode.Kind {
192194
// Conceptual
193195
.root, .module, .article, .sampleCode, .technologyOverview, .volume, .chapter, .tutorial, .tutorialArticle, .onPageLandmark,
194196
// Containers
195-
.class, .structure, .enumeration, .protocol, .technology, .extension, .dictionary, .httpRequest,
197+
.class, .structure, .enumeration, .protocol, .technology, .extension, .dictionary, .httpRequest, .namespace,
196198
// Leaves
197199
.localVariable, .globalVariable, .typeAlias, .typeDef, .typeConstant, .associatedType, .function, .operator, .macro, .union,
198200
// Member-only leaves

Sources/SwiftDocC/Model/SourceLanguage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public struct SourceLanguage: Hashable, Codable {
135135
"objective-c",
136136
"objc",
137137
"c", // FIXME: DocC should display C as its own language (github.com/apple/swift-docc/issues/169).
138+
"c++", // FIXME: DocC should display C++ and Objective-C++ as their own languages (https://github.com/apple/swift-docc/issues/767)
139+
"objective-c++",
140+
"objc++",
141+
"occ++",
138142
],
139143
linkDisambiguationID: "c"
140144
)

Tests/SwiftDocCTests/Infrastructure/AutomaticCurationTests.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,34 @@ class AutomaticCurationTests: XCTestCase {
539539
]
540540
)
541541
}
542-
542+
543+
func testNamespacesAreCuratedProperly() throws {
544+
let (bundle, context) = try testBundleAndContext(named: "CxxNamespaces")
545+
546+
let rootDocumentationNode = try context.entity(
547+
with: .init(
548+
bundleIdentifier: bundle.identifier,
549+
path: "/documentation/CxxNamespaces",
550+
sourceLanguage: .objectiveC
551+
)
552+
)
553+
let topics = try AutomaticCuration.topics(
554+
for: rootDocumentationNode,
555+
withTraits: [.objectiveC],
556+
context: context
557+
)
558+
559+
XCTAssertEqual(
560+
topics.flatMap { taskGroup in
561+
[taskGroup.title] + taskGroup.references.map(\.path)
562+
},
563+
[
564+
"Namespaces",
565+
"/documentation/CxxNamespaces/Foo",
566+
]
567+
)
568+
}
569+
543570
// Ensures that manually curated sample code articles are not also
544571
// automatically curated.
545572
func testSampleCodeArticlesRespectManualCuration() throws {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ``CxxNamespaces``
2+
3+
This bundle contains a small symbol graph that demonstrates a C++ namespace, as reflected in the
4+
current implementation on Clang's main branch.
5+
6+
<!-- Copyright (c) 2023 Apple Inc and the Swift Project authors. All Rights Reserved. -->
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"metadata": {
3+
"formatVersion": {
4+
"major": 0,
5+
"minor": 5,
6+
"patch": 3
7+
},
8+
"generator": "?"
9+
},
10+
"module": {
11+
"name": "CxxNamespaces",
12+
"platform": {
13+
"architecture": "arm64",
14+
"operatingSystem": {
15+
"minimumVersion": {
16+
"major": 11,
17+
"minor": 0,
18+
"patch": 0
19+
},
20+
"name": "macosx"
21+
},
22+
"vendor": "apple"
23+
}
24+
},
25+
"relationships": [
26+
{
27+
"kind": "memberOf",
28+
"source": "c:@N@Foo@S@Bar",
29+
"target": "c:@N@Foo",
30+
"targetFallback": "Foo"
31+
}
32+
],
33+
"symbols": [
34+
{
35+
"accessLevel": "public",
36+
"declarationFragments": [
37+
{
38+
"kind": "keyword",
39+
"spelling": "namespace"
40+
},
41+
{
42+
"kind": "text",
43+
"spelling": " "
44+
},
45+
{
46+
"kind": "identifier",
47+
"spelling": "Foo"
48+
},
49+
{
50+
"kind": "text",
51+
"spelling": ";"
52+
}
53+
],
54+
"identifier": {
55+
"interfaceLanguage": "c++",
56+
"precise": "c:@N@Foo"
57+
},
58+
"kind": {
59+
"displayName": "Namespace",
60+
"identifier": "c++.namespace"
61+
},
62+
"location": {
63+
"position": {
64+
"character": 10,
65+
"line": 0
66+
},
67+
"uri": "file:///path/to/namespace.cpp.tmp/input.h"
68+
},
69+
"names": {
70+
"navigator": [
71+
{
72+
"kind": "identifier",
73+
"spelling": "Foo"
74+
}
75+
],
76+
"subHeading": [
77+
{
78+
"kind": "identifier",
79+
"spelling": "Foo"
80+
}
81+
],
82+
"title": "Foo"
83+
},
84+
"pathComponents": [
85+
"Foo"
86+
]
87+
},
88+
{
89+
"accessLevel": "public",
90+
"declarationFragments": [
91+
{
92+
"kind": "keyword",
93+
"spelling": "class"
94+
},
95+
{
96+
"kind": "text",
97+
"spelling": " "
98+
},
99+
{
100+
"kind": "identifier",
101+
"spelling": "Bar"
102+
},
103+
{
104+
"kind": "text",
105+
"spelling": ";"
106+
}
107+
],
108+
"identifier": {
109+
"interfaceLanguage": "c++",
110+
"precise": "c:@N@Foo@S@Bar"
111+
},
112+
"kind": {
113+
"displayName": "Class",
114+
"identifier": "c++.class"
115+
},
116+
"location": {
117+
"position": {
118+
"character": 8,
119+
"line": 1
120+
},
121+
"uri": "file:///path/to/namespace.cpp.tmp/input.h"
122+
},
123+
"names": {
124+
"navigator": [
125+
{
126+
"kind": "identifier",
127+
"spelling": "Bar"
128+
}
129+
],
130+
"subHeading": [
131+
{
132+
"kind": "identifier",
133+
"spelling": "Bar"
134+
}
135+
],
136+
"title": "Bar"
137+
},
138+
"pathComponents": [
139+
"Foo",
140+
"Bar"
141+
]
142+
}
143+
]
144+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleVersion</key>
6+
<string>0.1.0</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>org.swift.docc.example</string>
9+
<key>CFBundleDisplayName</key>
10+
<string>C++ Namespaces</string>
11+
<key>CFBundleName</key>
12+
<string>CxxNamespaces</string>
13+
</dict>
14+
</plist>

0 commit comments

Comments
 (0)