Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4c77e1c
Rename context "bundle" property to "inputs"
d-ronnqvist Sep 30, 2025
c4a9f77
Remove redundant "bundle" parameter from RenderHierarchyTranslator
d-ronnqvist Sep 30, 2025
3d11235
Remove redundant "bundle" parameter from RenderContentCompiler
d-ronnqvist Sep 30, 2025
a8f6248
Update test to avoid using inputs that don't belong to the context
d-ronnqvist Sep 30, 2025
c2c2196
Remove redundant "bundle" parameter from MarkupReferenceResolver
d-ronnqvist Sep 30, 2025
98492d0
Remove redundant "bundle" parameter from ReferenceResolver
d-ronnqvist Sep 30, 2025
e386863
Remove redundant "bundle" parameter from DocumentationContentRenderer
d-ronnqvist Sep 30, 2025
9bacbbd
Remove redundant "bundle" parameter from RenderNodeTranslator
d-ronnqvist Sep 30, 2025
9d08393
Remove redundant "bundle" parameter from DocumentationNodeConverter
d-ronnqvist Sep 30, 2025
4922a76
Remove redundant "bundle" parameter from DocumentationContextConverter
d-ronnqvist Sep 30, 2025
8bfd711
Remove redundant "bundle" parameter from GeneratedDocumentationTopics
d-ronnqvist Sep 30, 2025
c4bdf0b
Remove redundant "bundle" parameter from ConvertActionConverter
d-ronnqvist Sep 30, 2025
b50bc1a
Remove redundant "bundle" parameter from AutomaticCuration.seeAlso
d-ronnqvist Sep 30, 2025
a657d32
Remove redundant "bundle" parameter from RenderNodeTranslator.default…
d-ronnqvist Sep 30, 2025
faaa649
Remove redundant "bundle" parameter from DocumentationCurator
d-ronnqvist Sep 30, 2025
5898c48
Remove unused DocumentationContext.unregister method
d-ronnqvist Sep 30, 2025
061e1db
Remove redundant "bundle" parameter from PathHierarchyBasedLinkResolv…
d-ronnqvist Sep 30, 2025
299719a
Remove redundant "bundle" parameters from various private Documentati…
d-ronnqvist Sep 30, 2025
73ed112
Merge branch 'main' into remove-redundant-bundle-params
d-ronnqvist Oct 3, 2025
83fe89f
Merge branch 'main' into remove-redundant-bundle-params
d-ronnqvist Oct 7, 2025
d6f0c50
Merge branch 'main' into remove-redundant-bundle-params
d-ronnqvist Oct 10, 2025
e1c04b7
Remove to local "bundle" variables
d-ronnqvist Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public class DocumentationContextConverter {

var translator = RenderNodeTranslator(
context: context,
bundle: bundle,
identifier: node.reference,
renderContext: renderContext,
emitSymbolSourceFileURIs: shouldEmitSymbolSourceFileURIs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct DocumentationNodeConverter {
/// - node: The documentation node to convert.
/// - Returns: The render node representation of the documentation node.
public func convert(_ node: DocumentationNode) -> RenderNode {
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference)
var translator = RenderNodeTranslator(context: context, identifier: node.reference)
return translator.visit(node.semantic) as! RenderNode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public struct ConvertService: DocumentationService {
let context = try await DocumentationContext(bundle: bundle, dataProvider: dataProvider, configuration: configuration)

// Precompute the render context
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let renderContext = RenderContext(documentationContext: context)

let symbolIdentifiersMeetingRequirementsForExpandedDocumentation: [String]? = request.symbolIdentifiersWithExpandedDocumentation?.compactMap { identifier, expandedDocsRequirement in
guard let documentationNode = context.documentationCache[identifier] else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ package enum ConvertActionConverter {

// Precompute the render context
let renderContext = signposter.withIntervalSignpost("Build RenderContext", id: signposter.makeSignpostID()) {
RenderContext(documentationContext: context, bundle: bundle)
RenderContext(documentationContext: context)
}
try outputConsumer.consume(renderReferenceStore: renderContext.store)

Expand Down
14 changes: 7 additions & 7 deletions Sources/SwiftDocC/Model/Rendering/RenderContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ import SymbolKit
/// converting nodes in bulk, i.e. when converting a complete documentation model for example.
public struct RenderContext {
let documentationContext: DocumentationContext
let bundle: DocumentationBundle
let renderer: DocumentationContentRenderer

/// Creates a new render context.
/// - Warning: Creating a render context pre-renders all content that the context provides.
/// - Parameters:
/// - documentationContext: A documentation context.
/// - bundle: A documentation bundle.
public init(documentationContext: DocumentationContext, bundle: DocumentationBundle) {
public init(documentationContext: DocumentationContext) {
self.documentationContext = documentationContext
self.bundle = bundle
self.renderer = DocumentationContentRenderer(context: documentationContext)
createRenderedContent()
}

@available(*, deprecated, renamed: "init(context:)", message: "Use 'init(context:)' instead. This deprecated API will be removed after 6.4 is released.")
public init(documentationContext: DocumentationContext, bundle _: DocumentationBundle) {
self.init(documentationContext: documentationContext)
}

/// The pre-rendered content per node reference.
private(set) public var store = RenderReferenceStore()

Expand All @@ -40,10 +42,8 @@ public struct RenderContext {
private mutating func createRenderedContent() {
let references = documentationContext.knownIdentifiers
var topics = [ResolvedTopicReference: RenderReferenceStore.TopicContent]()
let renderer = self.renderer
let documentationContext = self.documentationContext

let renderContentFor: (ResolvedTopicReference) -> RenderReferenceStore.TopicContent = { reference in
let renderContentFor: (ResolvedTopicReference) -> RenderReferenceStore.TopicContent = { [renderer, documentationContext] reference in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new Swift syntax for me - does this destructure renderer and documentationContext from the reference value passed into the closure? Why isn't this written the other way around? Like this:

... = { reference [renderer, documentationContext]  in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables within angle brackets is a Swift closure is a "capture list".

The same way that the previous code was shadowing renderer and documentationContext with local variables to avoid strongly capturing self in the closure, the capture list captures renderer and documentationContext explicitly as their own variables instead of them referring to self.renderer and self.documentationContext which would capture self.

var dependencies = RenderReferenceDependencies()
let renderReference = renderer.renderReference(for: reference, dependencies: &dependencies)
let canonicalPath = documentationContext.shortestFinitePath(to: reference).flatMap { $0.isEmpty ? nil : $0 }
Expand Down
15 changes: 6 additions & 9 deletions Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
}

public mutating func visitTutorialReference(_ tutorialReference: TutorialReference) -> (any RenderTree)? {
switch context.resolve(tutorialReference.topic, in: bundle.rootReference) {
switch context.resolve(tutorialReference.topic, in: context.inputs.rootReference) {
case let .failure(reference, _):
return RenderReferenceIdentifier(reference.topicURL.absoluteString)
case let .success(resolved):
Expand Down Expand Up @@ -806,7 +806,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
for: documentationNode,
withTraits: allowedTraits,
context: context,
bundle: bundle,
bundle: context.inputs,
renderContext: renderContext,
renderer: contentRenderer
) {
Expand Down Expand Up @@ -1029,7 +1029,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
) -> [TaskGroupRenderSection] {
return topics.taskGroups.compactMap { group in
let supportedLanguages = group.directives[SupportedLanguage.directiveName]?.compactMap {
SupportedLanguage(from: $0, source: nil, for: bundle)?.language
SupportedLanguage(from: $0, source: nil, for: context.inputs)?.language
}

// If the task group has a set of supported languages, see if it should render for the allowed traits.
Expand Down Expand Up @@ -1241,7 +1241,7 @@ public struct RenderNodeTranslator: SemanticVisitor {

node.metadata.extendedModuleVariants = VariantCollection<String?>(from: symbol.extendedModuleVariants)

let defaultAvailability = defaultAvailability(for: bundle, moduleName: moduleName.symbolName, currentPlatforms: context.configuration.externalMetadata.currentPlatforms)?
let defaultAvailability = defaultAvailability(for: context.inputs, moduleName: moduleName.symbolName, currentPlatforms: context.configuration.externalMetadata.currentPlatforms)?
.filter { $0.unconditionallyUnavailable != true }
.sorted(by: AvailabilityRenderOrder.compare)

Expand Down Expand Up @@ -1648,7 +1648,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
for: documentationNode,
withTraits: allowedTraits,
context: context,
bundle: bundle,
bundle: context.inputs,
renderContext: renderContext,
renderer: contentRenderer
), !seeAlso.references.isEmpty {
Expand Down Expand Up @@ -1774,7 +1774,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
}

var context: DocumentationContext
var bundle: DocumentationBundle
var identifier: ResolvedTopicReference
var imageReferences: [String: ImageReference] = [:]
var videoReferences: [String: VideoReference] = [:]
Expand Down Expand Up @@ -1851,7 +1850,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
}

private func variants(for documentationNode: DocumentationNode) -> [RenderNode.Variant] {
let generator = PresentationURLGenerator(context: context, baseURL: bundle.baseURL)
let generator = PresentationURLGenerator(context: context, baseURL: context.inputs.baseURL)

var allVariants: [SourceLanguage: ResolvedTopicReference] = documentationNode.availableSourceLanguages.reduce(into: [:]) { partialResult, language in
partialResult[language] = identifier
Expand Down Expand Up @@ -2002,7 +2001,6 @@ public struct RenderNodeTranslator: SemanticVisitor {

init(
context: DocumentationContext,
bundle: DocumentationBundle,
identifier: ResolvedTopicReference,
renderContext: RenderContext? = nil,
emitSymbolSourceFileURIs: Bool = false,
Expand All @@ -2011,7 +2009,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
symbolIdentifiersWithExpandedDocumentation: [String]? = nil
) {
self.context = context
self.bundle = bundle
self.identifier = identifier
self.renderContext = renderContext
self.contentRenderer = DocumentationContentRenderer(context: context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DocumentationContextConverterTests: XCTestCase {
let perNodeConverter = DocumentationNodeConverter(bundle: bundle, context: context)

// We'll use these to convert nodes in bulk
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let renderContext = RenderContext(documentationContext: context)
let bulkNodeConverter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext)
let encoder = JSONEncoder()

Expand All @@ -42,7 +42,7 @@ class DocumentationContextConverterTests: XCTestCase {

func testSymbolLocationsAreOnlyIncludedWhenRequested() async throws {
let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let renderContext = RenderContext(documentationContext: context)

let fillIntroducedSymbolNode = try XCTUnwrap(
context.documentationCache["s:14FillIntroduced19macOSOnlyDeprecatedyyF"]
Expand Down Expand Up @@ -72,7 +72,7 @@ class DocumentationContextConverterTests: XCTestCase {

func testSymbolAccessLevelsAreOnlyIncludedWhenRequested() async throws {
let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let renderContext = RenderContext(documentationContext: context)

let fillIntroducedSymbolNode = try XCTUnwrap(
context.documentationCache["s:14FillIntroduced19macOSOnlyDeprecatedyyF"]
Expand Down
5 changes: 2 additions & 3 deletions Tests/SwiftDocCTests/Converter/RenderContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import XCTest

class RenderContextTests: XCTestCase {
func testCreatesRenderReferences() async throws {
let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")

let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let renderContext = RenderContext(documentationContext: context)

// Verify render references are created for all topics
XCTAssertEqual(Array(renderContext.store.topics.keys.sorted(by: { $0.absoluteString < $1.absoluteString })), context.knownIdentifiers.sorted(by: { $0.absoluteString < $1.absoluteString }), "Didn't create render references for all context topics.")
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftDocCTests/Converter/RenderNodeCodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RenderNodeCodableTests: XCTestCase {
}

func testEncodeRenderNodeWithCustomTopicSectionStyle() async throws {
let (bundle, context) = try await testBundleAndContext()
let (_, context) = try await testBundleAndContext()
var problems = [Problem]()

let source = """
Expand All @@ -185,7 +185,7 @@ class RenderNodeCodableTests: XCTestCase {

let document = Document(parsing: source, options: .parseBlockDirectives)
let article = try XCTUnwrap(
Article(from: document.root, source: nil, for: bundle, problems: &problems)
Article(from: document.root, source: nil, for: context.inputs, problems: &problems)
)

let reference = ResolvedTopicReference(
Expand All @@ -203,7 +203,7 @@ class RenderNodeCodableTests: XCTestCase {
)
context.topicGraph.addNode(topicGraphNode)

var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference)
var translator = RenderNodeTranslator(context: context, identifier: reference)
let node = try XCTUnwrap(translator.visitArticle(article) as? RenderNode)
XCTAssertEqual(node.topicSectionsStyle, .compactGrid)

Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class ExternalRenderNodeTests: XCTestCase {
let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration)
XCTAssert(context.problems.isEmpty, "Encountered unexpected problems: \(context.problems.map(\.diagnostic.summary))")

let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let renderContext = RenderContext(documentationContext: context)
let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext)
let targetURL = try createTemporaryDirectory()
let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true)
Expand Down Expand Up @@ -337,7 +337,7 @@ class ExternalRenderNodeTests: XCTestCase {
let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration)
XCTAssert(context.problems.isEmpty, "Encountered unexpected problems: \(context.problems.map(\.diagnostic.summary))")

let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let renderContext = RenderContext(documentationContext: context)
let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext)
let targetURL = try createTemporaryDirectory()
let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true)
Expand Down Expand Up @@ -415,7 +415,7 @@ class ExternalRenderNodeTests: XCTestCase {
let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration)
XCTAssert(context.problems.isEmpty, "Encountered unexpected problems: \(context.problems.map(\.diagnostic.summary))")

let renderContext = RenderContext(documentationContext: context, bundle: bundle)
let renderContext = RenderContext(documentationContext: context)
let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext)
let targetURL = try createTemporaryDirectory()
let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true)
Expand Down
18 changes: 9 additions & 9 deletions Tests/SwiftDocCTests/Indexing/IndexingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class IndexingTests: XCTestCase {

// MARK: - Tutorial
func testTutorial() async throws {
let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let tutorialReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)
let node = try context.entity(with: tutorialReference)
let tutorial = node.semantic as! Tutorial
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: tutorialReference)
var converter = RenderNodeTranslator(context: context, identifier: tutorialReference)
let renderNode = converter.visit(tutorial) as! RenderNode
let indexingRecords = try renderNode.indexingRecords(onPage: tutorialReference)
XCTAssertEqual(4, indexingRecords.count)
Expand Down Expand Up @@ -89,11 +89,11 @@ class IndexingTests: XCTestCase {
// MARK: - Article

func testArticle() async throws {
let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let articleReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)
let node = try context.entity(with: articleReference)
let article = node.semantic as! TutorialArticle
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference)
var converter = RenderNodeTranslator(context: context, identifier: articleReference)
let renderNode = converter.visit(article) as! RenderNode
let indexingRecords = try renderNode.indexingRecords(onPage: articleReference)

Expand Down Expand Up @@ -187,11 +187,11 @@ class IndexingTests: XCTestCase {
}

func testRootPageIndexingRecord() async throws {
let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
let articleReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)
let node = try context.entity(with: articleReference)
let article = node.semantic as! Symbol
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference)
var converter = RenderNodeTranslator(context: context, identifier: articleReference)
let renderNode = converter.visit(article) as! RenderNode
let indexingRecords = try renderNode.indexingRecords(onPage: articleReference)

Expand All @@ -207,8 +207,8 @@ class IndexingTests: XCTestCase {
}

func testSymbolIndexingRecord() async throws {
let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in
// Modify the documentaion to have default availability for MyKit so that there is platform availability
let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in
// Modify the documentation to have default availability for MyKit so that there is platform availability
// information for MyProtocol (both in the render node and in the indexing record.
let plistURL = url.appendingPathComponent("Info.plist")
let plistData = try Data(contentsOf: plistURL)
Expand All @@ -224,7 +224,7 @@ class IndexingTests: XCTestCase {
let articleReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift)
let node = try context.entity(with: articleReference)
let article = node.semantic as! Symbol
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference)
var converter = RenderNodeTranslator(context: context, identifier: articleReference)
let renderNode = converter.visit(article) as! RenderNode
let indexingRecords = try renderNode.indexingRecords(onPage: articleReference)

Expand Down
Loading