Skip to content

Commit 338f54c

Browse files
accept sameShape constraint kind from SymbolKit
rdar://129338238
1 parent 3268e73 commit 338f54c

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
137137
.package(url: "https://github.com/swiftlang/swift-markdown.git", branch: "main"),
138138
.package(url: "https://github.com/swiftlang/swift-lmdb.git", branch: "main"),
139139
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"),
140-
.package(url: "https://github.com/swiftlang/swift-docc-symbolkit.git", branch: "main"),
140+
// .package(url: "https://github.com/swiftlang/swift-docc-symbolkit.git", branch: "main"),
141+
.package(url: "https://github.com/QuietMisdreavus/swift-docc-symbolkit.git", branch: "same-shape"),
141142
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
142143
.package(url: "https://github.com/swiftlang/swift-docc-plugin.git", from: "1.2.0"),
143144
]

Sources/SwiftDocC/Model/Rendering/Symbol/ConformanceSection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extension Constraint.Kind {
2020
case .conformance: return "conforms to"
2121
case .sameType: return "is"
2222
case .superclass: return "inherits"
23+
case .sameShape: return "is the same shape as"
2324
}
2425
}
2526
}

Tests/SwiftDocCTests/Rendering/ConstraintsRenderSectionTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,43 @@ class ConstraintsRenderSectionTests: XCTestCase {
273273
// Verify we've removed the "Self." prefix in the type names
274274
XCTAssertEqual(renderReference.conformance?.constraints.map(flattenInlineElements).joined(), "Element conforms to MyProtocol and Index conforms to Equatable.")
275275
}
276+
277+
func testRenderSameShape() async throws {
278+
let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in
279+
// Add constraints to `MyClass`
280+
let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json")
281+
var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL))
282+
283+
// "Inject" generic constraints
284+
graph.symbols = try graph.symbols.mapValues({ symbol -> SymbolGraph.Symbol in
285+
guard symbol.identifier.precise == "s:5MyKit0A5ClassC10myFunctionyyF" else { return symbol }
286+
var symbol = symbol
287+
symbol.mixins[SymbolGraph.Symbol.Swift.Extension.mixinKey] = try jsonDecoder.decode(SymbolGraph.Symbol.Swift.Extension.self, from: """
288+
{"extendedModule": "MyKit",
289+
"constraints": [
290+
{ "kind" : "sameShape", "lhs" : "Element", "rhs" : "MyProtocol" }
291+
]}
292+
""".data(using: .utf8)!)
293+
return symbol
294+
})
295+
try jsonEncoder.encode(graph).write(to: graphURL)
296+
}
297+
298+
// Compile docs and verify contents
299+
let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift))
300+
let symbol = node.semantic as! Symbol
301+
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference)
302+
let renderNode = translator.visitSymbol(symbol) as! RenderNode
303+
304+
guard let renderReference = renderNode.references.first(where: { (key, value) -> Bool in
305+
return key.hasSuffix("myFunction()")
306+
})?.value as? TopicRenderReference else {
307+
XCTFail("Did not find render reference to myFunction()")
308+
return
309+
}
310+
311+
XCTAssertEqual(renderReference.conformance?.constraints.map(flattenInlineElements).joined(), "Element is the same shape as MyProtocol.")
312+
}
276313
}
277314

278315
fileprivate func flattenInlineElements(el: RenderInlineContent) -> String {

0 commit comments

Comments
 (0)