From 4c77e1c52c2fd42ceb5fc9c2dea7a3459e82698b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 10:29:19 +0200 Subject: [PATCH 01/19] Rename context "bundle" property to "inputs" --- .../Convert/ConvertService.swift | 2 +- .../Infrastructure/DocumentationContext.swift | 19 +++------------- .../Link Resolution/LinkResolver.swift | 22 +++++++++---------- .../LinkTargets/LinkDestinationSummary.swift | 2 +- .../Model/Rendering/LinkTitleResolver.swift | 4 ++-- .../DocumentationContextTests.swift | 2 +- .../Infrastructure/SnippetResolverTests.swift | 2 +- ...OutOfProcessReferenceResolverV2Tests.swift | 4 ++-- .../ConvertActionTests.swift | 4 ++-- 9 files changed, 24 insertions(+), 37 deletions(-) diff --git a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift index fc22a5c35..36c1bb80d 100644 --- a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift +++ b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift @@ -243,7 +243,7 @@ public struct ConvertService: DocumentationService { .compactMap { (value, isDocumentationExtensionContent) -> (ResolvedTopicReference, RenderReferenceStore.TopicContent)? in let (topicReference, article) = value - let bundle = context.bundle + let bundle = context.inputs guard bundle.id == topicReference.bundleID else { return nil } let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle) diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index b4200ae07..ffec8287a 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -70,8 +70,8 @@ public class DocumentationContext { /// The data provider that the context can use to read the contents of files that belong to ``bundle``. let dataProvider: any DataProvider - /// The documentation bundle that is registered with the context. - let bundle: DocumentationBundle + /// The collection of input files that the context was created from. + let inputs: DocumentationContext.Inputs /// A collection of configuration for this context. public let configuration: Configuration @@ -211,7 +211,7 @@ public class DocumentationContext { diagnosticEngine: DiagnosticEngine = .init(), configuration: Configuration = .init() ) async throws { - self.bundle = bundle + self.inputs = bundle self.dataProvider = dataProvider self.diagnosticEngine = diagnosticEngine self.configuration = configuration @@ -220,19 +220,6 @@ public class DocumentationContext { ResolvedTopicReference.enableReferenceCaching(for: bundle.id) try register(bundle) } - - // Remove these when removing `registeredBundles` and `bundle(identifier:)`. - // These exist so that internal code that need to be compatible with legacy data providers can access the bundles without deprecation warnings. - @available(*, deprecated, renamed: "bundle", message: "REMOVE THIS") - var _registeredBundles: [DocumentationBundle] { - [bundle] - } - - @available(*, deprecated, renamed: "bundle", message: "REMOVE THIS") - func _bundle(identifier: String) -> DocumentationBundle? { - assert(bundle.id.rawValue == identifier, "New code shouldn't pass unknown bundle identifiers to 'DocumentationContext.bundle(identifier:)'.") - return bundle.id.rawValue == identifier ? bundle : nil - } /// Perform semantic analysis on a given `document` at a given `source` location and append any problems found to `problems`. /// diff --git a/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift b/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift index de1a3bbbf..d7a5f331c 100644 --- a/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift +++ b/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift @@ -59,8 +59,8 @@ public class LinkResolver { // Check if this is a link to an external documentation source that should have previously been resolved in `DocumentationContext.preResolveExternalLinks(...)` if let bundleID = unresolvedReference.bundleID, - context.bundle.id != bundleID, - urlReadablePath(context.bundle.displayName) != bundleID.rawValue + context.inputs.id != bundleID, + urlReadablePath(context.inputs.displayName) != bundleID.rawValue { return .failure(unresolvedReference, TopicReferenceResolutionErrorInfo("No external resolver registered for '\(bundleID)'.")) } @@ -136,8 +136,8 @@ private final class FallbackResolverBasedLinkResolver { // Check if a fallback reference resolver should resolve this let referenceBundleID = unresolvedReference.bundleID ?? parent.bundleID guard let fallbackResolver = context.configuration.convertServiceConfiguration.fallbackResolver, - fallbackResolver.bundleID == context.bundle.id, - context.bundle.id == referenceBundleID || urlReadablePath(context.bundle.displayName) == referenceBundleID.rawValue + fallbackResolver.bundleID == context.inputs.id, + context.inputs.id == referenceBundleID || urlReadablePath(context.inputs.displayName) == referenceBundleID.rawValue else { return nil } @@ -155,16 +155,16 @@ private final class FallbackResolverBasedLinkResolver { ) allCandidateURLs.append(alreadyResolved.url) - let currentBundle = context.bundle + let currentInputs = context.inputs if !isCurrentlyResolvingSymbolLink { // First look up articles path allCandidateURLs.append(contentsOf: [ // First look up articles path - currentBundle.articlesDocumentationRootReference.url.appendingPathComponent(unresolvedReference.path), + currentInputs.articlesDocumentationRootReference.url.appendingPathComponent(unresolvedReference.path), // Then technology tutorials root path (for individual tutorial pages) - currentBundle.tutorialsContainerReference.url.appendingPathComponent(unresolvedReference.path), + currentInputs.tutorialsContainerReference.url.appendingPathComponent(unresolvedReference.path), // Then tutorials root path (for tutorial table of contents pages) - currentBundle.tutorialTableOfContentsContainer.url.appendingPathComponent(unresolvedReference.path), + currentInputs.tutorialTableOfContentsContainer.url.appendingPathComponent(unresolvedReference.path), ]) } // Try resolving in the local context (as child) @@ -179,8 +179,8 @@ private final class FallbackResolverBasedLinkResolver { // Check that the parent is not an article (ignoring if absolute or relative link) // because we cannot resolve in the parent context if it's not a symbol. - if parent.path.hasPrefix(currentBundle.documentationRootReference.path) && parentPath.count > 2 { - let rootPath = currentBundle.documentationRootReference.appendingPath(parentPath[2]) + if parent.path.hasPrefix(currentInputs.documentationRootReference.path) && parentPath.count > 2 { + let rootPath = currentInputs.documentationRootReference.appendingPath(parentPath[2]) let resolvedInRoot = rootPath.url.appendingPathComponent(unresolvedReference.path) // Confirm here that we we're not already considering this link. We only need to specifically @@ -190,7 +190,7 @@ private final class FallbackResolverBasedLinkResolver { } } - allCandidateURLs.append(currentBundle.documentationRootReference.url.appendingPathComponent(unresolvedReference.path)) + allCandidateURLs.append(currentInputs.documentationRootReference.url.appendingPathComponent(unresolvedReference.path)) for candidateURL in allCandidateURLs { guard let candidateReference = ValidatedURL(candidateURL).map({ UnresolvedTopicReference(topicURL: $0) }) else { diff --git a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift index a092359f2..8f7a3f1c1 100644 --- a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift +++ b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift @@ -431,7 +431,7 @@ public extension DocumentationNode { renderNode: RenderNode, includeTaskGroups: Bool = true ) -> [LinkDestinationSummary] { - let bundle = context.bundle + let bundle = context.inputs guard bundle.id == reference.bundleID else { // Don't return anything for external references that don't have a bundle in the context. return [] diff --git a/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift b/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift index 73f85a43f..2aceb26ec 100644 --- a/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift +++ b/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift @@ -31,11 +31,11 @@ struct LinkTitleResolver { var problems = [Problem]() switch directive.name { case Tutorial.directiveName: - if let tutorial = Tutorial(from: directive, source: source, for: context.bundle, problems: &problems) { + if let tutorial = Tutorial(from: directive, source: source, for: context.inputs, problems: &problems) { return .init(defaultVariantValue: tutorial.intro.title) } case TutorialTableOfContents.directiveName: - if let overview = TutorialTableOfContents(from: directive, source: source, for: context.bundle, problems: &problems) { + if let overview = TutorialTableOfContents(from: directive, source: source, for: context.inputs, problems: &problems) { return .init(defaultVariantValue: overview.name) } default: break diff --git a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift index acc5b9d50..e63b282bd 100644 --- a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift @@ -3286,7 +3286,7 @@ let expected = """ ]) // Verify that the links are resolved in the render model. - let bundle = try XCTUnwrap(context.bundle) + let bundle = try XCTUnwrap(context.inputs) let converter = DocumentationNodeConverter(bundle: bundle, context: context) let renderNode = converter.convert(entity) diff --git a/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift index de88a9ab4..ddff13df6 100644 --- a/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift @@ -235,7 +235,7 @@ class SnippetResolverTests: XCTestCase { let reference = try XCTUnwrap(context.soleRootModuleReference, file: file, line: line) let moduleNode = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: context.bundle, context: context).convert(moduleNode) + let renderNode = DocumentationNodeConverter(bundle: context.inputs, context: context).convert(moduleNode) let renderBlocks = try XCTUnwrap(renderNode.primaryContentSections.first as? ContentRenderSection, file: file, line: line).content diff --git a/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift b/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift index 8a8e4ccc7..0983c98de 100644 --- a/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift +++ b/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift @@ -391,11 +391,11 @@ class OutOfProcessReferenceResolverV2Tests: XCTestCase { let reference = try XCTUnwrap(context.soleRootModuleReference, "This example catalog only has a root page") let converter = DocumentationContextConverter( - bundle: context.bundle, + bundle: context.inputs, context: context, renderContext: RenderContext( documentationContext: context, - bundle: context.bundle + bundle: context.inputs ) ) let renderNode = try XCTUnwrap(converter.renderNode(for: context.entity(with: reference))) diff --git a/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift b/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift index 72f42ba47..a4f76bcd5 100644 --- a/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift +++ b/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift @@ -2898,7 +2898,7 @@ class ConvertActionTests: XCTestCase { ) let (_, context) = try await action.perform(logHandle: .none) - let bundle = try XCTUnwrap(context.bundle, "Should have registered the generated test bundle.") + let bundle = try XCTUnwrap(context.inputs, "Should have registered the generated test bundle.") XCTAssertEqual(bundle.displayName, "MyKit") XCTAssertEqual(bundle.id, "MyKit") } @@ -2976,7 +2976,7 @@ class ConvertActionTests: XCTestCase { ) let (_, context) = try await action.perform(logHandle: .none) - let bundle = try XCTUnwrap(context.bundle, "Should have registered the generated test bundle.") + let bundle = try XCTUnwrap(context.inputs, "Should have registered the generated test bundle.") XCTAssertEqual(bundle.displayName, "Something") XCTAssertEqual(bundle.id, "com.example.test") } From c4a9f774944ff17de29955bf68ff5be0ccbf18b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 11:19:14 +0200 Subject: [PATCH 02/19] Remove redundant "bundle" parameter from RenderHierarchyTranslator --- .../Navigation Tree/RenderHierarchyTranslator.swift | 11 ++++------- .../Model/Rendering/RenderNodeTranslator.swift | 10 +++++----- .../Infrastructure/SymbolBreadcrumbTests.swift | 4 ++-- .../Model/RenderHierarchyTranslatorTests.swift | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Sources/SwiftDocC/Model/Rendering/Navigation Tree/RenderHierarchyTranslator.swift b/Sources/SwiftDocC/Model/Rendering/Navigation Tree/RenderHierarchyTranslator.swift index 25c670833..c62907e75 100644 --- a/Sources/SwiftDocC/Model/Rendering/Navigation Tree/RenderHierarchyTranslator.swift +++ b/Sources/SwiftDocC/Model/Rendering/Navigation Tree/RenderHierarchyTranslator.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2024 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -13,18 +13,15 @@ import Foundation /// A hierarchy translator that converts a part of the topic graph into a hierarchy tree. struct RenderHierarchyTranslator { var context: DocumentationContext - var bundle: DocumentationBundle var collectedTopicReferences = Set() var linkReferences = [String: LinkReference]() - /// Creates a new translator for the given bundle in the given context. + /// Creates a new translator for the given context. /// - Parameters: /// - context: The documentation context for the conversion. - /// - bundle: The documentation bundle for the conversion. - init(context: DocumentationContext, bundle: DocumentationBundle) { + init(context: DocumentationContext) { self.context = context - self.bundle = bundle } static let assessmentsAnchor = urlReadableFragment(TutorialAssessmentsRenderSection.title) @@ -164,7 +161,7 @@ struct RenderHierarchyTranslator { let assessmentReference = ResolvedTopicReference(bundleID: tutorialReference.bundleID, path: tutorialReference.path, fragment: RenderHierarchyTranslator.assessmentsAnchor, sourceLanguage: .swift) renderHierarchyTutorial.landmarks.append(RenderHierarchyLandmark(reference: RenderReferenceIdentifier(assessmentReference.absoluteString), kind: .assessment)) - let urlGenerator = PresentationURLGenerator(context: context, baseURL: bundle.baseURL) + let urlGenerator = PresentationURLGenerator(context: context, baseURL: context.inputs.baseURL) let assessmentLinkReference = LinkReference( identifier: RenderReferenceIdentifier(assessmentReference.absoluteString), title: "Check Your Understanding", diff --git a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift index aad67d6b8..c3ec505f3 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift @@ -134,7 +134,7 @@ public struct RenderNodeTranslator: SemanticVisitor { public mutating func visitTutorial(_ tutorial: Tutorial) -> (any RenderTree)? { var node = RenderNode(identifier: identifier, kind: .tutorial) - var hierarchyTranslator = RenderHierarchyTranslator(context: context, bundle: bundle) + var hierarchyTranslator = RenderHierarchyTranslator(context: context) if let hierarchy = hierarchyTranslator.visitTutorialTableOfContentsNode(identifier) { let tutorialTableOfContents = try! context.entity(with: hierarchy.tutorialTableOfContents).semantic as! TutorialTableOfContents @@ -401,7 +401,7 @@ public struct RenderNodeTranslator: SemanticVisitor { node.sections.append(visitResources(resources) as! ResourcesRenderSection) } - var hierarchyTranslator = RenderHierarchyTranslator(context: context, bundle: bundle) + var hierarchyTranslator = RenderHierarchyTranslator(context: context) if let (hierarchyVariants, _) = hierarchyTranslator.visitTutorialTableOfContentsNode(identifier, omittingChapters: true) { node.hierarchyVariants = hierarchyVariants collectedTopicReferences.append(contentsOf: hierarchyTranslator.collectedTopicReferences) @@ -624,7 +624,7 @@ public struct RenderNodeTranslator: SemanticVisitor { let documentationNode = try! context.entity(with: identifier) - var hierarchyTranslator = RenderHierarchyTranslator(context: context, bundle: bundle) + var hierarchyTranslator = RenderHierarchyTranslator(context: context) let hierarchyVariants = hierarchyTranslator.visitArticle(identifier) collectedTopicReferences.append(contentsOf: hierarchyTranslator.collectedTopicReferences) node.hierarchyVariants = hierarchyVariants @@ -878,7 +878,7 @@ public struct RenderNodeTranslator: SemanticVisitor { public mutating func visitTutorialArticle(_ article: TutorialArticle) -> (any RenderTree)? { var node = RenderNode(identifier: identifier, kind: .article) - var hierarchyTranslator = RenderHierarchyTranslator(context: context, bundle: bundle) + var hierarchyTranslator = RenderHierarchyTranslator(context: context) guard let hierarchy = hierarchyTranslator.visitTutorialTableOfContentsNode(identifier) else { // This tutorial article is not curated, so we don't generate a render node. // We've warned about this during semantic analysis. @@ -1333,7 +1333,7 @@ public struct RenderNodeTranslator: SemanticVisitor { let contentRenderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle) node.metadata.tags = contentRenderer.tags(for: identifier) - var hierarchyTranslator = RenderHierarchyTranslator(context: context, bundle: bundle) + var hierarchyTranslator = RenderHierarchyTranslator(context: context) let hierarchyVariants = hierarchyTranslator.visitSymbol(identifier) collectedTopicReferences.append(contentsOf: hierarchyTranslator.collectedTopicReferences) node.hierarchyVariants = hierarchyVariants diff --git a/Tests/SwiftDocCTests/Infrastructure/SymbolBreadcrumbTests.swift b/Tests/SwiftDocCTests/Infrastructure/SymbolBreadcrumbTests.swift index d1d8f14fa..0389cea89 100644 --- a/Tests/SwiftDocCTests/Infrastructure/SymbolBreadcrumbTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/SymbolBreadcrumbTests.swift @@ -140,7 +140,7 @@ class SymbolBreadcrumbTests: XCTestCase { file: StaticString = #filePath, line: UInt = #line ) { - var hierarchyTranslator = RenderHierarchyTranslator(context: context, bundle: bundle) + var hierarchyTranslator = RenderHierarchyTranslator(context: context) let hierarchyVariants = hierarchyTranslator.visitSymbol(reference) XCTAssertNotNil(hierarchyVariants.defaultValue, "Should always have default breadcrumbs", file: file, line: line) @@ -154,7 +154,7 @@ class SymbolBreadcrumbTests: XCTestCase { file: StaticString = #filePath, line: UInt = #line ) { - var hierarchyTranslator = RenderHierarchyTranslator(context: context, bundle: bundle) + var hierarchyTranslator = RenderHierarchyTranslator(context: context) let hierarchyVariants = hierarchyTranslator.visitSymbol(reference) XCTAssertNotNil(hierarchyVariants.defaultValue, "Should always have default breadcrumbs", file: file, line: line) diff --git a/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift b/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift index 6fe80c94f..6110717c5 100644 --- a/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift +++ b/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift @@ -16,7 +16,7 @@ class RenderHierarchyTranslatorTests: XCTestCase { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let technologyReference = ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/TestOverview", sourceLanguage: .swift) - var translator = RenderHierarchyTranslator(context: context, bundle: bundle) + var translator = RenderHierarchyTranslator(context: context) let renderHierarchyVariants = translator.visitTutorialTableOfContentsNode(technologyReference)?.hierarchyVariants XCTAssertEqual(renderHierarchyVariants?.variants, [], "Unexpected variant hierarchies for tutorial table of content page") let renderHierarchy = renderHierarchyVariants?.defaultValue From 3d11235e196a0efc2bdad6af67a5540e6fc19b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 10:38:09 +0200 Subject: [PATCH 03/19] Remove redundant "bundle" parameter from RenderContentCompiler --- .../LinkTargets/LinkDestinationSummary.swift | 2 +- .../Rendering/DocumentationContentRenderer.swift | 2 +- .../Model/Rendering/RenderContentCompiler.swift | 8 +++----- .../Model/Rendering/RenderContentConvertible.swift | 2 +- .../Model/Rendering/RenderNodeTranslator.swift | 8 ++++---- .../Model/RenderContentMetadataTests.swift | 14 +++++++------- .../Model/SemaToRenderNodeTests.swift | 6 +++--- .../RenderBlockContent_ThematicBreakTests.swift | 6 +++--- .../Rendering/RenderContentCompilerTests.swift | 6 +++--- Tests/SwiftDocCTests/Rendering/TermListTests.swift | 4 ++-- .../XCTestCase+LoadingTestData.swift | 3 +-- 11 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift index 8f7a3f1c1..93223fa2b 100644 --- a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift +++ b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift @@ -439,7 +439,7 @@ public extension DocumentationNode { let urlGenerator = PresentationURLGenerator(context: context, baseURL: bundle.baseURL) let relativePresentationURL = urlGenerator.presentationURLForReference(reference).withoutHostAndPortAndScheme() - var compiler = RenderContentCompiler(context: context, bundle: bundle, identifier: reference) + var compiler = RenderContentCompiler(context: context, identifier: reference) let platforms = renderNode.metadata.platforms diff --git a/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift b/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift index 465a58aa8..3d7487741 100644 --- a/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift +++ b/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift @@ -326,7 +326,7 @@ public class DocumentationContentRenderer { // Topic render references require the URLs to be relative, even if they're external. let presentationURL = urlGenerator.presentationURLForReference(reference) - var contentCompiler = RenderContentCompiler(context: documentationContext, bundle: bundle, identifier: reference) + var contentCompiler = RenderContentCompiler(context: documentationContext, identifier: reference) let abstractContent: VariantCollection<[RenderInlineContent]> var abstractedNode = node diff --git a/Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift b/Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift index 58fabcced..119a3d763 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2024 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -20,7 +20,6 @@ extension RenderInlineContent: RenderContent {} struct RenderContentCompiler: MarkupVisitor { var context: DocumentationContext - var bundle: DocumentationBundle var identifier: ResolvedTopicReference var imageReferences: [String: ImageReference] = [:] var videoReferences: [String: VideoReference] = [:] @@ -28,9 +27,8 @@ struct RenderContentCompiler: MarkupVisitor { var collectedTopicReferences = GroupedSequence { $0.absoluteString } var linkReferences: [String: LinkReference] = [:] - init(context: DocumentationContext, bundle: DocumentationBundle, identifier: ResolvedTopicReference) { + init(context: DocumentationContext, identifier: ResolvedTopicReference) { self.context = context - self.bundle = bundle self.identifier = identifier } @@ -47,7 +45,7 @@ struct RenderContentCompiler: MarkupVisitor { mutating func visitCodeBlock(_ codeBlock: CodeBlock) -> [any RenderContent] { // Default to the bundle's code listing syntax if one is not explicitly declared in the code block. - return [RenderBlockContent.codeListing(.init(syntax: codeBlock.language ?? bundle.info.defaultCodeListingLanguage, code: codeBlock.code.splitByNewlines, metadata: nil))] + return [RenderBlockContent.codeListing(.init(syntax: codeBlock.language ?? context.inputs.info.defaultCodeListingLanguage, code: codeBlock.code.splitByNewlines, metadata: nil))] } mutating func visitHeading(_ heading: Heading) -> [any RenderContent] { diff --git a/Sources/SwiftDocC/Model/Rendering/RenderContentConvertible.swift b/Sources/SwiftDocC/Model/Rendering/RenderContentConvertible.swift index 6e7325c80..18e358d94 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderContentConvertible.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderContentConvertible.swift @@ -24,7 +24,7 @@ extension RenderableDirectiveConvertible { _ blockDirective: BlockDirective, with contentCompiler: inout RenderContentCompiler ) -> [any RenderContent] { - guard let directive = Self.init(from: blockDirective, for: contentCompiler.bundle) else { + guard let directive = Self.init(from: blockDirective, for: contentCompiler.context.inputs) else { return [] } diff --git a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift index c3ec505f3..39eb9a11a 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift @@ -315,7 +315,7 @@ public struct RenderNodeTranslator: SemanticVisitor { // Visits a container and expects the elements to be block level elements public mutating func visitMarkupContainer(_ markupContainer: MarkupContainer) -> (any RenderTree)? { - var contentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: identifier) + var contentCompiler = RenderContentCompiler(context: context, identifier: identifier) let content = markupContainer.elements.reduce(into: [], { result, item in result.append(contentsOf: contentCompiler.visit(item))}) as! [RenderBlockContent] collectedTopicReferences.append(contentsOf: contentCompiler.collectedTopicReferences) // Copy all the image references found in the markup container. @@ -327,7 +327,7 @@ public struct RenderNodeTranslator: SemanticVisitor { // Visits a collection of inline markup elements. public mutating func visitMarkup(_ markup: [any Markup]) -> (any RenderTree)? { - var contentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: identifier) + var contentCompiler = RenderContentCompiler(context: context, identifier: identifier) let content = markup.reduce(into: [], { result, item in result.append(contentsOf: contentCompiler.visit(item))}) as! [RenderInlineContent] collectedTopicReferences.append(contentsOf: contentCompiler.collectedTopicReferences) // Copy all the image references. @@ -600,7 +600,7 @@ public struct RenderNodeTranslator: SemanticVisitor { public mutating func visitArticle(_ article: Article) -> (any RenderTree)? { var node = RenderNode(identifier: identifier, kind: .article) // Contains symbol references declared in the Topics section. - var topicSectionContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: identifier) + var topicSectionContentCompiler = RenderContentCompiler(context: context, identifier: identifier) node.metadata.title = article.title!.plainText @@ -1201,7 +1201,7 @@ public struct RenderNodeTranslator: SemanticVisitor { let identifier = identifier.addingSourceLanguages(documentationNode.availableSourceLanguages) var node = RenderNode(identifier: identifier, kind: .symbol) - var contentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: identifier) + var contentCompiler = RenderContentCompiler(context: context, identifier: identifier) /* FIXME: We shouldn't be doing this kind of crawling here. diff --git a/Tests/SwiftDocCTests/Model/RenderContentMetadataTests.swift b/Tests/SwiftDocCTests/Model/RenderContentMetadataTests.swift index 23da7c124..5bcf65262 100644 --- a/Tests/SwiftDocCTests/Model/RenderContentMetadataTests.swift +++ b/Tests/SwiftDocCTests/Model/RenderContentMetadataTests.swift @@ -68,7 +68,7 @@ class RenderContentMetadataTests: XCTestCase { func testRenderingTables() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ | Column 1 | Column 2 | @@ -109,7 +109,7 @@ class RenderContentMetadataTests: XCTestCase { func testRenderingTableSpans() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ | one | two | three | @@ -162,7 +162,7 @@ class RenderContentMetadataTests: XCTestCase { func testRenderingTableColumnAlignments() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ | one | two | three | four | @@ -204,7 +204,7 @@ class RenderContentMetadataTests: XCTestCase { /// Verifies that a table with `nil` alignments and a table with all-unset alignments still compare as equal. func testRenderedTableEquality() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ | Column 1 | Column 2 | @@ -230,7 +230,7 @@ class RenderContentMetadataTests: XCTestCase { /// Verifies that two tables with otherwise-identical contents but different column alignments compare as unequal. func testRenderedTableInequality() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let decodedTableWithUnsetColumns: RenderBlockContent.Table do { @@ -277,7 +277,7 @@ class RenderContentMetadataTests: XCTestCase { func testStrikethrough() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ ~~Striken~~ text. @@ -300,7 +300,7 @@ class RenderContentMetadataTests: XCTestCase { func testHeadingAnchorShouldBeEncoded() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ ## ใƒ†ใ‚นใƒˆ diff --git a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift index 2a16c9db8..9f56c8fcd 100644 --- a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift +++ b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift @@ -1641,7 +1641,7 @@ Document @1:1-11:19 markup.debugDescription(options: .printSourceLocations)) let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var contentTranslator = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestTutorial", sourceLanguage: .swift)) + var contentTranslator = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestTutorial", sourceLanguage: .swift)) let renderContent = try XCTUnwrap(markup.children.reduce(into: [], { result, item in result.append(contentsOf: contentTranslator.visit(item))}) as? [RenderBlockContent]) let expectedContent: [RenderBlockContent] = [ .paragraph(.init(inlineContent: [ @@ -1683,7 +1683,7 @@ Document markup.debugDescription()) let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var contentTranslator = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestTutorial", sourceLanguage: .swift)) + var contentTranslator = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestTutorial", sourceLanguage: .swift)) let renderContent = try XCTUnwrap(markup.children.reduce(into: [], { result, item in result.append(contentsOf: contentTranslator.visit(item))}) as? [RenderBlockContent]) let expectedContent: [RenderBlockContent] = [ .paragraph(.init(inlineContent: [ @@ -3618,7 +3618,7 @@ Document let (bundle, context) = try await testBundleAndContext() - var contentTranslator = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) + var contentTranslator = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) let renderContent = try XCTUnwrap(markup.children.reduce(into: [], { result, item in result.append(contentsOf: contentTranslator.visit(item))}) as? [RenderBlockContent]) let expectedContent: [RenderBlockContent] = [ diff --git a/Tests/SwiftDocCTests/Rendering/RenderBlockContent_ThematicBreakTests.swift b/Tests/SwiftDocCTests/Rendering/RenderBlockContent_ThematicBreakTests.swift index 0ec1d9c8d..5f2a70ee7 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderBlockContent_ThematicBreakTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderBlockContent_ThematicBreakTests.swift @@ -40,7 +40,7 @@ class RenderBlockContent_ThematicBreakTests: XCTestCase { let (bundle, context) = try await testBundleAndContext() - var contentTranslator = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) + var contentTranslator = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) let renderContent = try XCTUnwrap(markup.children.reduce(into: [], { result, item in result.append(contentsOf: contentTranslator.visit(item))}) as? [RenderBlockContent]) let expectedContent: [RenderBlockContent] = [ @@ -67,7 +67,7 @@ class RenderBlockContent_ThematicBreakTests: XCTestCase { let (bundle, context) = try await testBundleAndContext() - var contentTranslator = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) + var contentTranslator = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) let renderContent = try XCTUnwrap(markup.children.reduce(into: [], { result, item in result.append(contentsOf: contentTranslator.visit(item))}) as? [RenderBlockContent]) let expectedContent: [RenderBlockContent] = [ @@ -97,7 +97,7 @@ class RenderBlockContent_ThematicBreakTests: XCTestCase { let (bundle, context) = try await testBundleAndContext() - var contentTranslator = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) + var contentTranslator = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/TestThematicBreak", sourceLanguage: .swift)) let renderContent = try XCTUnwrap(markup.children.reduce(into: [], { result, item in result.append(contentsOf: contentTranslator.visit(item))}) as? [RenderBlockContent]) let expectedContent: [RenderBlockContent] = [ diff --git a/Tests/SwiftDocCTests/Rendering/RenderContentCompilerTests.swift b/Tests/SwiftDocCTests/Rendering/RenderContentCompilerTests.swift index 8a23b1324..01022a78d 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderContentCompilerTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderContentCompilerTests.swift @@ -16,7 +16,7 @@ import XCTest class RenderContentCompilerTests: XCTestCase { func testLinkOverrideTitle() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var compiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var compiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ [Example](http://example.com) @@ -134,7 +134,7 @@ class RenderContentCompilerTests: XCTestCase { func testLineBreak() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var compiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var compiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = #""" Backslash before new line\ @@ -199,7 +199,7 @@ class RenderContentCompilerTests: XCTestCase { func testThematicBreak() async throws { let (bundle, context) = try await testBundleAndContext() - var compiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var compiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = #""" diff --git a/Tests/SwiftDocCTests/Rendering/TermListTests.swift b/Tests/SwiftDocCTests/Rendering/TermListTests.swift index bb03e0c28..426df3d6a 100644 --- a/Tests/SwiftDocCTests/Rendering/TermListTests.swift +++ b/Tests/SwiftDocCTests/Rendering/TermListTests.swift @@ -162,7 +162,7 @@ class TermListTests: XCTestCase { } let (bundle, context) = try await testBundleAndContext() - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ - term First term : A paragraph that @@ -205,7 +205,7 @@ class TermListTests: XCTestCase { } let (bundle, context) = try await testBundleAndContext() - var renderContentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) + var renderContentCompiler = RenderContentCompiler(context: context, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift)) let source = """ - Not a term list, and diff --git a/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift b/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift index 4207fc3d1..d131ae21f 100644 --- a/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift +++ b/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift @@ -313,9 +313,8 @@ extension XCTestCase { var contentCompiler = RenderContentCompiler( context: context, - bundle: bundle, identifier: ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/test-path-123", sourceLanguage: .swift ) From a8f62481288da6f97c05ea59b7a09ff55a8af3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 10:44:47 +0200 Subject: [PATCH 04/19] Update test to avoid using inputs that don't belong to the context --- .../FilesAndFolders.swift | 24 +++- .../DefaultCodeListingSyntaxTests.swift | 133 ++++++------------ 2 files changed, 62 insertions(+), 95 deletions(-) diff --git a/Sources/SwiftDocCTestUtilities/FilesAndFolders.swift b/Sources/SwiftDocCTestUtilities/FilesAndFolders.swift index 248dcdc9d..406366c28 100644 --- a/Sources/SwiftDocCTestUtilities/FilesAndFolders.swift +++ b/Sources/SwiftDocCTestUtilities/FilesAndFolders.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2024 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -94,11 +94,17 @@ public struct InfoPlist: File, DataRepresentable { /// The information that the Into.plist file contains. public let content: Content - public init(displayName: String? = nil, identifier: String? = nil, defaultAvailability: [String: [DefaultAvailability.ModuleAvailability]]? = nil) { + public init( + displayName: String? = nil, + identifier: String? = nil, + defaultAvailability: [String: [DefaultAvailability.ModuleAvailability]]? = nil, + defaultCodeListingLanguage: String? = nil + ) { self.content = Content( displayName: displayName, identifier: identifier, - defaultAvailability: defaultAvailability + defaultAvailability: defaultAvailability, + defaultCodeListingLanguage: defaultCodeListingLanguage ) } @@ -106,25 +112,29 @@ public struct InfoPlist: File, DataRepresentable { public let displayName: String? public let identifier: String? public let defaultAvailability: [String: [DefaultAvailability.ModuleAvailability]]? - - fileprivate init(displayName: String?, identifier: String?, defaultAvailability: [String: [DefaultAvailability.ModuleAvailability]]?) { + public let defaultCodeListingLanguage: String? + + fileprivate init(displayName: String?, identifier: String?, defaultAvailability: [String: [DefaultAvailability.ModuleAvailability]]?, defaultCodeListingLanguage: String?) { self.displayName = displayName self.identifier = identifier self.defaultAvailability = defaultAvailability + self.defaultCodeListingLanguage = defaultCodeListingLanguage } public init(from decoder: any Decoder) throws { - let container = try decoder.container(keyedBy: DocumentationBundle.Info.CodingKeys.self) + let container = try decoder.container(keyedBy: DocumentationContext.Inputs.Info.CodingKeys.self) displayName = try container.decodeIfPresent(String.self, forKey: .displayName) identifier = try container.decodeIfPresent(String.self, forKey: .id) defaultAvailability = try container.decodeIfPresent([String : [DefaultAvailability.ModuleAvailability]].self, forKey: .defaultAvailability) + defaultCodeListingLanguage = try container.decodeIfPresent(String.self, forKey: .defaultCodeListingLanguage) } public func encode(to encoder: any Encoder) throws { - var container = encoder.container(keyedBy: DocumentationBundle.Info.CodingKeys.self) + var container = encoder.container(keyedBy: DocumentationContext.Inputs.Info.CodingKeys.self) try container.encodeIfPresent(displayName, forKey: .displayName) try container.encodeIfPresent(identifier, forKey: .id) try container.encodeIfPresent(defaultAvailability, forKey: .defaultAvailability) + try container.encodeIfPresent(defaultCodeListingLanguage, forKey: .defaultCodeListingLanguage) } } diff --git a/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift b/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift index 5f13c4085..fd60141b2 100644 --- a/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift @@ -11,105 +11,62 @@ import Foundation import XCTest @testable import SwiftDocC +import SwiftDocCTestUtilities class DefaultCodeBlockSyntaxTests: XCTestCase { - enum Errors: Error { - case noCodeBlockFound + func testCodeBlockWithoutAnyLanguageOrDefault() async throws { + let codeListing = try await makeCodeBlock(fenceLanguage: nil, infoPlistLanguage: nil) + XCTAssertEqual(codeListing.language, nil) } - var renderSectionWithLanguageDefault: ContentRenderSection! - var renderSectionWithoutLanguageDefault: ContentRenderSection! - - var testBundleWithLanguageDefault: DocumentationBundle! - var testBundleWithoutLanguageDefault: DocumentationBundle! - - override func setUp() async throws { - try await super.setUp() - - func renderSection(for bundle: DocumentationBundle, in context: DocumentationContext) throws -> ContentRenderSection { - let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/Test-Bundle/Default-Code-Listing-Syntax", fragment: nil, sourceLanguage: .swift) - - let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) - let renderNode = translator.visit(node.semantic) as! RenderNode - - return renderNode.primaryContentSections.first! as! ContentRenderSection - } - - let (_, bundleWithLanguageDefault, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") - - testBundleWithLanguageDefault = bundleWithLanguageDefault - - // Copy the bundle but explicitly set `defaultCodeListingLanguage` to `nil` to mimic having no default language set. - testBundleWithoutLanguageDefault = DocumentationBundle( - info: DocumentationBundle.Info( - displayName: testBundleWithLanguageDefault.displayName, - id: testBundleWithLanguageDefault.id, - defaultCodeListingLanguage: nil - ), - baseURL: testBundleWithLanguageDefault.baseURL, - symbolGraphURLs: testBundleWithLanguageDefault.symbolGraphURLs, - markupURLs: testBundleWithLanguageDefault.markupURLs, - miscResourceURLs: testBundleWithLanguageDefault.miscResourceURLs - ) - - renderSectionWithLanguageDefault = try renderSection(for: testBundleWithLanguageDefault, in: context) - renderSectionWithoutLanguageDefault = try renderSection(for: testBundleWithoutLanguageDefault, in: context) - } - - struct CodeListing { - var language: String? - var lines: [String] + func testExplicitFencedCodeBlockLanguage() async throws { + let codeListing = try await makeCodeBlock(fenceLanguage: "swift", infoPlistLanguage: nil) + XCTAssertEqual(codeListing.language, "swift") } - private func codeListing(at index: Int, in renderSection: ContentRenderSection, file: StaticString = #filePath, line: UInt = #line) throws -> CodeListing { - if case let .codeListing(l) = renderSection.content[index] { - return CodeListing(language: l.syntax, lines: l.code) - } - - XCTFail("Expected code listing at index \(index)", file: (file), line: line) - throw Errors.noCodeBlockFound + func testDefaultCodeBlockLanguage() async throws { + let codeListing = try await makeCodeBlock(fenceLanguage: nil, infoPlistLanguage: "swift") + XCTAssertEqual(codeListing.language, "swift") } - func testDefaultCodeBlockSyntaxForFencedCodeListingWithoutExplicitLanguage() throws { - let fencedCodeListing = try codeListing(at: 1, in: renderSectionWithLanguageDefault) - - XCTAssertEqual("swift", fencedCodeListing.language, "Default a language of 'CDDefaultCodeListingLanguage' if it is set in the 'Info.plist'") - - XCTAssertEqual(fencedCodeListing.lines, [ - "// With no language set, this should highlight to 'swift' because the 'CDDefaultCodeListingLanguage' key is set to 'swift'.", - "func foo()", - ]) + func testExplicitlySetLanguageOverridesDefaultLanguage() async throws { + let codeListing = try await makeCodeBlock(fenceLanguage: "objective-c", infoPlistLanguage: "swift") + XCTAssertEqual(codeListing.language, "objective-c", "The explicit language of the code listing should override the bundle's default language") } - func testDefaultCodeBlockSyntaxForNonFencedCodeListing() throws { - let indentedCodeListing = try codeListing(at: 2, in: renderSectionWithLanguageDefault) - - XCTAssertEqual("swift", indentedCodeListing.language, "Default a language of 'CDDefaultCodeListingLanguage' if it is set in the 'Info.plist'") - XCTAssertEqual(indentedCodeListing.lines, [ - "/// This is a non fenced code listing and should also default to the 'CDDefaultCodeListingLanguage' language.", - "func foo()", - ]) + private struct CodeListing { + var language: String? + var lines: [String] } - - func testExplicitlySetLanguageOverridesBundleDefault() throws { - let explicitlySetLanguageCodeListing = try codeListing(at: 3, in: renderSectionWithLanguageDefault) - - XCTAssertEqual("objective-c", explicitlySetLanguageCodeListing.language, "The explicit language of the code listing should override the bundle's default language") - - XCTAssertEqual(explicitlySetLanguageCodeListing.lines, [ - "/// This is a fenced code block with an explicit language set, and it should override the default language for the bundle.", - "- (void)foo;", + + private func makeCodeBlock(fenceLanguage: String?, infoPlistLanguage: String?) async throws -> CodeListing { + let catalog = Folder(name: "Something.docc", content: [ + InfoPlist(defaultCodeListingLanguage: infoPlistLanguage), + + TextFile(name: "Root.md", utf8Content: """ + # Root + + This article contains a code block + + ```\(fenceLanguage ?? "") + Some code goes + ``` + """) ]) - } - - func testHasNoLanguageWhenNoPlistKeySetAndNoExplicitLanguageProvided() throws { - let fencedCodeListing = try codeListing(at: 1, in: renderSectionWithoutLanguageDefault) - let indentedCodeListing = try codeListing(at: 2, in: renderSectionWithoutLanguageDefault) - let explicitlySetLanguageCodeListing = try codeListing(at: 3, in: renderSectionWithoutLanguageDefault) - - XCTAssertEqual(fencedCodeListing.language, nil) - XCTAssertEqual(indentedCodeListing.language, nil) - XCTAssertEqual(explicitlySetLanguageCodeListing.language, "objective-c") + + let (_, context) = try await loadBundle(catalog: catalog) + let reference = try XCTUnwrap(context.soleRootModuleReference) + let converter = DocumentationNodeConverter(bundle: context.inputs, context: context) + + let renderNode = converter.convert(try context.entity(with: reference)) + let renderSection = try XCTUnwrap(renderNode.primaryContentSections.first as? ContentRenderSection) + + guard case .codeListing(let codeListing)? = renderSection.content.last else { + struct Error: DescribedError { + let errorDescription = "Didn't fide code block is known markup" + } + throw Error() + } + return CodeListing(language: codeListing.syntax, lines: codeListing.code) } } From c2c21968348febf9da4fa6bfd04e53c34efff37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 10:48:36 +0200 Subject: [PATCH 05/19] Remove redundant "bundle" parameter from MarkupReferenceResolver --- .../Semantics/MarkupReferenceResolver.swift | 15 ++++++------- .../Semantics/ReferenceResolver.swift | 2 +- .../MarkupReferenceResolverTests.swift | 4 ++-- .../Semantics/SnippetTests.swift | 8 +++---- .../XCTestCase+LoadingTestData.swift | 21 +++++++------------ 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Sources/SwiftDocC/Semantics/MarkupReferenceResolver.swift b/Sources/SwiftDocC/Semantics/MarkupReferenceResolver.swift index 00b57e589..f70557855 100644 --- a/Sources/SwiftDocC/Semantics/MarkupReferenceResolver.swift +++ b/Sources/SwiftDocC/Semantics/MarkupReferenceResolver.swift @@ -39,13 +39,11 @@ private func removedLinkDestinationProblem(reference: ResolvedTopicReference, ra */ struct MarkupReferenceResolver: MarkupRewriter { var context: DocumentationContext - var bundle: DocumentationBundle var problems = [Problem]() var rootReference: ResolvedTopicReference - init(context: DocumentationContext, bundle: DocumentationBundle, rootReference: ResolvedTopicReference) { + init(context: DocumentationContext, rootReference: ResolvedTopicReference) { self.context = context - self.bundle = bundle self.rootReference = rootReference } @@ -79,14 +77,14 @@ struct MarkupReferenceResolver: MarkupRewriter { return nil } - let uncuratedArticleMatch = context.uncuratedArticles[bundle.articlesDocumentationRootReference.appendingPathOfReference(unresolved)]?.source + let uncuratedArticleMatch = context.uncuratedArticles[context.inputs.articlesDocumentationRootReference.appendingPathOfReference(unresolved)]?.source problems.append(unresolvedReferenceProblem(source: range?.source, range: range, severity: severity, uncuratedArticleMatch: uncuratedArticleMatch, errorInfo: error, fromSymbolLink: fromSymbolLink)) return nil } } mutating func visitImage(_ image: Image) -> (any Markup)? { - if let reference = image.reference(in: bundle), !context.resourceExists(with: reference) { + if let reference = image.reference(in: context.inputs), !context.resourceExists(with: reference) { problems.append(unresolvedResourceProblem(resource: reference, source: image.range?.source, range: image.range, severity: .warning)) } @@ -167,7 +165,7 @@ struct MarkupReferenceResolver: MarkupRewriter { switch blockDirective.name { case Snippet.directiveName: var ignoredParsingProblems = [Problem]() // Any argument parsing problems have already been reported elsewhere - guard let snippet = Snippet(from: blockDirective, source: source, for: bundle, problems: &ignoredParsingProblems) else { + guard let snippet = Snippet(from: blockDirective, source: source, for: context.inputs, problems: &ignoredParsingProblems) else { return blockDirective } @@ -184,7 +182,7 @@ struct MarkupReferenceResolver: MarkupRewriter { return blockDirective } case ImageMedia.directiveName: - guard let imageMedia = ImageMedia(from: blockDirective, source: source, for: bundle) else { + guard let imageMedia = ImageMedia(from: blockDirective, source: source, for: context.inputs) else { return blockDirective } @@ -202,7 +200,7 @@ struct MarkupReferenceResolver: MarkupRewriter { return blockDirective case VideoMedia.directiveName: - guard let videoMedia = VideoMedia(from: blockDirective, source: source, for: bundle) else { + guard let videoMedia = VideoMedia(from: blockDirective, source: source, for: context.inputs) else { return blockDirective } @@ -240,4 +238,3 @@ struct MarkupReferenceResolver: MarkupRewriter { } } } - diff --git a/Sources/SwiftDocC/Semantics/ReferenceResolver.swift b/Sources/SwiftDocC/Semantics/ReferenceResolver.swift index 2bb44a90e..35ed8adff 100644 --- a/Sources/SwiftDocC/Semantics/ReferenceResolver.swift +++ b/Sources/SwiftDocC/Semantics/ReferenceResolver.swift @@ -215,7 +215,7 @@ struct ReferenceResolver: SemanticVisitor { } mutating func visitMarkupContainer(_ markupContainer: MarkupContainer) -> Semantic { - var markupResolver = MarkupReferenceResolver(context: context, bundle: bundle, rootReference: rootReference) + var markupResolver = MarkupReferenceResolver(context: context, rootReference: rootReference) let parent = inheritanceParentReference let context = self.context diff --git a/Tests/SwiftDocCTests/Semantics/MarkupReferenceResolverTests.swift b/Tests/SwiftDocCTests/Semantics/MarkupReferenceResolverTests.swift index b99628501..79c0914cb 100644 --- a/Tests/SwiftDocCTests/Semantics/MarkupReferenceResolverTests.swift +++ b/Tests/SwiftDocCTests/Semantics/MarkupReferenceResolverTests.swift @@ -14,7 +14,7 @@ import Markdown class MarkupReferenceResolverTests: XCTestCase { func testArbitraryReferenceInComment() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let source = """ @Comment { ``hello`` and ``world`` are 2 arbitrary symbol links. @@ -23,7 +23,7 @@ class MarkupReferenceResolverTests: XCTestCase { } """ let document = Document(parsing: source, options: [.parseBlockDirectives, .parseSymbolLinks]) - var resolver = MarkupReferenceResolver(context: context, bundle: bundle, rootReference: context.rootModules[0]) + var resolver = MarkupReferenceResolver(context: context, rootReference: context.rootModules[0]) _ = resolver.visit(document) XCTAssertEqual(0, resolver.problems.count) } diff --git a/Tests/SwiftDocCTests/Semantics/SnippetTests.swift b/Tests/SwiftDocCTests/Semantics/SnippetTests.swift index 5eda29ec2..a692c5511 100644 --- a/Tests/SwiftDocCTests/Semantics/SnippetTests.swift +++ b/Tests/SwiftDocCTests/Semantics/SnippetTests.swift @@ -59,7 +59,7 @@ class SnippetTests: XCTestCase { XCTAssertTrue(problems.isEmpty) } func testLinkResolvesWithoutOptionalPrefix() async throws { - let (bundle, context) = try await testBundleAndContext(named: "Snippets") + let (_, context) = try await testBundleAndContext(named: "Snippets") for snippetPath in [ "/Test/Snippets/MySnippet", @@ -71,14 +71,14 @@ class SnippetTests: XCTestCase { @Snippet(path: "\(snippetPath)") """ let document = Document(parsing: source, options: .parseBlockDirectives) - var resolver = MarkupReferenceResolver(context: context, bundle: bundle, rootReference: try XCTUnwrap(context.soleRootModuleReference)) + var resolver = MarkupReferenceResolver(context: context, rootReference: try XCTUnwrap(context.soleRootModuleReference)) _ = resolver.visit(document) XCTAssertTrue(resolver.problems.isEmpty, "Unexpected problems: \(resolver.problems.map(\.diagnostic.summary))") } } func testWarningAboutUnresolvedSnippetPath() async throws { - let (bundle, context) = try await testBundleAndContext(named: "Snippets") + let (_, context) = try await testBundleAndContext(named: "Snippets") for snippetPath in [ "/Test/Snippets/DoesNotExist", @@ -90,7 +90,7 @@ class SnippetTests: XCTestCase { @Snippet(path: "\(snippetPath)") """ let document = Document(parsing: source, options: .parseBlockDirectives) - var resolver = MarkupReferenceResolver(context: context, bundle: bundle, rootReference: try XCTUnwrap(context.soleRootModuleReference)) + var resolver = MarkupReferenceResolver(context: context, rootReference: try XCTUnwrap(context.soleRootModuleReference)) _ = resolver.visit(document) XCTAssertEqual(1, resolver.problems.count) let problem = try XCTUnwrap(resolver.problems.first) diff --git a/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift b/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift index d131ae21f..0ae2ec07a 100644 --- a/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift +++ b/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift @@ -208,8 +208,8 @@ extension XCTestCase { directive: Directive?, collectedReferences: [String : any RenderReference] ) { - let (bundle, context) = try await loadBundle(catalog: catalog) - return try parseDirective(directive, bundle: bundle, context: context, content: content, file: file, line: line) + let (_, context) = try await loadBundle(catalog: catalog) + return try parseDirective(directive, context: context, content: content, file: file, line: line) } func parseDirective( @@ -242,20 +242,17 @@ extension XCTestCase { directive: Directive?, collectedReferences: [String : any RenderReference] ) { - let bundle: DocumentationBundle let context: DocumentationContext - if let bundleName { - (bundle, context) = try await testBundleAndContext(named: bundleName) + (_, context) = try await testBundleAndContext(named: bundleName) } else { - (bundle, context) = try await testBundleAndContext() + (_, context) = try await testBundleAndContext() } - return try parseDirective(directive, bundle: bundle, context: context, content: content, file: file, line: line) + return try parseDirective(directive, context: context, content: content, file: file, line: line) } private func parseDirective( _ directive: Directive.Type, - bundle: DocumentationBundle, context: DocumentationContext, content: () -> String, file: StaticString = #filePath, @@ -273,15 +270,11 @@ extension XCTestCase { let blockDirectiveContainer = try XCTUnwrap(document.child(at: 0) as? BlockDirective, file: file, line: line) - var analyzer = SemanticAnalyzer(source: source, bundle: bundle) + var analyzer = SemanticAnalyzer(source: source, bundle: context.inputs) let result = analyzer.visit(blockDirectiveContainer) context.diagnosticEngine.emit(analyzer.problems) - var referenceResolver = MarkupReferenceResolver( - context: context, - bundle: bundle, - rootReference: bundle.rootReference - ) + var referenceResolver = MarkupReferenceResolver(context: context, rootReference: context.inputs.rootReference) _ = referenceResolver.visit(blockDirectiveContainer) context.diagnosticEngine.emit(referenceResolver.problems) From 98492d016b0a828bc892da6fcfba513b30a73811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 10:53:37 +0200 Subject: [PATCH 06/19] Remove redundant "bundle" parameter from ReferenceResolver --- .../Infrastructure/DocumentationContext.swift | 8 ++-- .../Semantics/ReferenceResolver.swift | 22 +++++------ .../Diagnostics/DiagnosticTests.swift | 4 +- .../ReferenceResolverTests.swift | 38 +++++++++---------- 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index ffec8287a..a66321a92 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -431,7 +431,7 @@ public class DocumentationContext { return } - var resolver = ReferenceResolver(context: self, bundle: bundle, rootReference: reference, inheritanceParentReference: symbolOriginReference) + var resolver = ReferenceResolver(context: self, rootReference: reference, inheritanceParentReference: symbolOriginReference) // Update the node with the markup that contains resolved references instead of authored links. documentationNode.semantic = autoreleasepool { @@ -561,7 +561,7 @@ public class DocumentationContext { for tableOfContentsResult in tutorialTableOfContentsResults { autoreleasepool { let url = tableOfContentsResult.source - var resolver = ReferenceResolver(context: self, bundle: bundle) + var resolver = ReferenceResolver(context: self) let tableOfContents = resolver.visit(tableOfContentsResult.value) as! TutorialTableOfContents diagnosticEngine.emit(resolver.problems) @@ -633,7 +633,7 @@ public class DocumentationContext { autoreleasepool { let url = tutorialResult.source let unresolvedTutorial = tutorialResult.value - var resolver = ReferenceResolver(context: self, bundle: bundle) + var resolver = ReferenceResolver(context: self) let tutorial = resolver.visit(unresolvedTutorial) as! Tutorial diagnosticEngine.emit(resolver.problems) @@ -667,7 +667,7 @@ public class DocumentationContext { autoreleasepool { let url = articleResult.source let unresolvedTutorialArticle = articleResult.value - var resolver = ReferenceResolver(context: self, bundle: bundle) + var resolver = ReferenceResolver(context: self) let article = resolver.visit(unresolvedTutorialArticle) as! TutorialArticle diagnosticEngine.emit(resolver.problems) diff --git a/Sources/SwiftDocC/Semantics/ReferenceResolver.swift b/Sources/SwiftDocC/Semantics/ReferenceResolver.swift index 35ed8adff..399abe203 100644 --- a/Sources/SwiftDocC/Semantics/ReferenceResolver.swift +++ b/Sources/SwiftDocC/Semantics/ReferenceResolver.swift @@ -95,9 +95,6 @@ struct ReferenceResolver: SemanticVisitor { /// The context to use to resolve references. var context: DocumentationContext - /// The bundle in which visited documents reside. - var bundle: DocumentationBundle - /// Problems found while trying to resolve references. var problems = [Problem]() @@ -106,10 +103,9 @@ struct ReferenceResolver: SemanticVisitor { /// If the documentation is inherited, the reference of the parent symbol. var inheritanceParentReference: ResolvedTopicReference? - init(context: DocumentationContext, bundle: DocumentationBundle, rootReference: ResolvedTopicReference? = nil, inheritanceParentReference: ResolvedTopicReference? = nil) { + init(context: DocumentationContext, rootReference: ResolvedTopicReference? = nil, inheritanceParentReference: ResolvedTopicReference? = nil) { self.context = context - self.bundle = bundle - self.rootReference = rootReference ?? bundle.rootReference + self.rootReference = rootReference ?? context.inputs.rootReference self.inheritanceParentReference = inheritanceParentReference } @@ -119,7 +115,7 @@ struct ReferenceResolver: SemanticVisitor { return .success(resolved) case let .failure(unresolved, error): - let uncuratedArticleMatch = context.uncuratedArticles[bundle.documentationRootReference.appendingPathOfReference(unresolved)]?.source + let uncuratedArticleMatch = context.uncuratedArticles[context.inputs.documentationRootReference.appendingPathOfReference(unresolved)]?.source problems.append(unresolvedReferenceProblem(source: range?.source, range: range, severity: severity, uncuratedArticleMatch: uncuratedArticleMatch, errorInfo: error, fromSymbolLink: false)) return .failure(unresolved, error) } @@ -172,9 +168,9 @@ struct ReferenceResolver: SemanticVisitor { // Change the context of the project file to `download` if let projectFiles = tutorial.projectFiles, - var resolvedDownload = context.resolveAsset(named: projectFiles.path, in: bundle.rootReference) { + var resolvedDownload = context.resolveAsset(named: projectFiles.path, in: rootReference) { resolvedDownload.context = .download - context.updateAsset(named: projectFiles.path, asset: resolvedDownload, in: bundle.rootReference) + context.updateAsset(named: projectFiles.path, asset: resolvedDownload, in: rootReference) } return Tutorial(originalMarkup: tutorial.originalMarkup, durationMinutes: tutorial.durationMinutes, projectFiles: tutorial.projectFiles, requirements: newRequirements, intro: newIntro, sections: newSections, assessments: newAssessments, callToActionImage: newCallToActionImage, redirects: tutorial.redirects) @@ -315,7 +311,7 @@ struct ReferenceResolver: SemanticVisitor { // i.e. doc:/${SOME_TECHNOLOGY}/${PROJECT} or doc://${BUNDLE_ID}/${SOME_TECHNOLOGY}/${PROJECT} switch tutorialReference.topic { case .unresolved: - let maybeResolved = resolve(tutorialReference.topic, in: bundle.tutorialsContainerReference, + let maybeResolved = resolve(tutorialReference.topic, in: context.inputs.tutorialsContainerReference, range: tutorialReference.originalMarkup.range, severity: .warning) return TutorialReference(originalMarkup: tutorialReference.originalMarkup, tutorial: .resolved(maybeResolved)) @@ -369,10 +365,10 @@ struct ReferenceResolver: SemanticVisitor { visitMarkupContainer($0) as? MarkupContainer } // If there's a call to action with a local-file reference, change its context to `download` - if let downloadFile = article.metadata?.callToAction?.resolveFile(for: bundle, in: context, problems: &problems), - var resolvedDownload = context.resolveAsset(named: downloadFile.path, in: bundle.rootReference) { + if let downloadFile = article.metadata?.callToAction?.resolveFile(for: context.inputs, in: context, problems: &problems), + var resolvedDownload = context.resolveAsset(named: downloadFile.path, in: rootReference) { resolvedDownload.context = .download - context.updateAsset(named: downloadFile.path, asset: resolvedDownload, in: bundle.rootReference) + context.updateAsset(named: downloadFile.path, asset: resolvedDownload, in: rootReference) } return Article( diff --git a/Tests/SwiftDocCTests/Diagnostics/DiagnosticTests.swift b/Tests/SwiftDocCTests/Diagnostics/DiagnosticTests.swift index 17d945f5c..f22e88897 100644 --- a/Tests/SwiftDocCTests/Diagnostics/DiagnosticTests.swift +++ b/Tests/SwiftDocCTests/Diagnostics/DiagnosticTests.swift @@ -79,7 +79,7 @@ class DiagnosticTests: XCTestCase { /// Test offsetting diagnostic ranges func testOffsetDiagnostics() async throws { - let (bundle, context) = try await loadBundle(catalog: Folder(name: "unit-test.docc", content: [ + let (_, context) = try await loadBundle(catalog: Folder(name: "unit-test.docc", content: [ JSONFile(name: "SomeModuleName.symbols.json", content: makeSymbolGraph(moduleName: "SomeModuleName")) ])) @@ -87,7 +87,7 @@ class DiagnosticTests: XCTestCase { let markup = Document(parsing: content, source: URL(string: "/tmp/foo.symbols.json"), options: .parseSymbolLinks) let moduleReference = try XCTUnwrap(context.soleRootModuleReference) - var resolver = ReferenceResolver(context: context, bundle: bundle, rootReference: moduleReference) + var resolver = ReferenceResolver(context: context, rootReference: moduleReference) // Resolve references _ = resolver.visitMarkup(markup) diff --git a/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift index 3067845fe..e43620429 100644 --- a/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift @@ -24,11 +24,11 @@ class ReferenceResolverTests: XCTestCase { """ let document = Document(parsing: source, options: .parseBlockDirectives) let directive = document.child(at: 0)! as! BlockDirective - let (bundle, context) = try await testBundleAndContext() + let (_, context) = try await testBundleAndContext() var problems = [Problem]() - let intro = Intro(from: directive, source: nil, for: bundle, problems: &problems)! + let intro = Intro(from: directive, source: nil, for: context.inputs, problems: &problems)! - var resolver = ReferenceResolver(context: context, bundle: bundle) + var resolver = ReferenceResolver(context: context) _ = resolver.visitIntro(intro) XCTAssertEqual(resolver.problems.count, 1) } @@ -43,11 +43,11 @@ class ReferenceResolverTests: XCTestCase { """ let document = Document(parsing: source, options: .parseBlockDirectives) let directive = document.child(at: 0)! as! BlockDirective - let (bundle, context) = try await testBundleAndContext() + let (_, context) = try await testBundleAndContext() var problems = [Problem]() - let contentAndMedia = ContentAndMedia(from: directive, source: nil, for: bundle, problems: &problems)! + let contentAndMedia = ContentAndMedia(from: directive, source: nil, for: context.inputs, problems: &problems)! - var resolver = ReferenceResolver(context: context, bundle: bundle) + var resolver = ReferenceResolver(context: context) _ = resolver.visit(contentAndMedia) XCTAssertEqual(resolver.problems.count, 1) } @@ -60,11 +60,11 @@ class ReferenceResolverTests: XCTestCase { """ let document = Document(parsing: source, options: .parseBlockDirectives) let directive = document.child(at: 0)! as! BlockDirective - let (bundle, context) = try await testBundleAndContext() + let (_, context) = try await testBundleAndContext() var problems = [Problem]() - let intro = Intro(from: directive, source: nil, for: bundle, problems: &problems)! + let intro = Intro(from: directive, source: nil, for: context.inputs, problems: &problems)! - var resolver = ReferenceResolver(context: context, bundle: bundle) + var resolver = ReferenceResolver(context: context) guard let container = resolver.visit(intro).children.first as? MarkupContainer, let firstElement = container.elements.first, @@ -560,11 +560,11 @@ class ReferenceResolverTests: XCTestCase { """ let document = Document(parsing: source, options: .parseBlockDirectives) let directive = document.child(at: 0)! as! BlockDirective - let (bundle, context) = try await testBundleAndContext() + let (_, context) = try await testBundleAndContext() var problems = [Problem]() - let chapter = try XCTUnwrap(Chapter(from: directive, source: nil, for: bundle, problems: &problems)) - var resolver = ReferenceResolver(context: context, bundle: bundle) + let chapter = try XCTUnwrap(Chapter(from: directive, source: nil, for: context.inputs, problems: &problems)) + var resolver = ReferenceResolver(context: context) _ = resolver.visitChapter(chapter) XCTAssertFalse(resolver.problems.containsErrors) XCTAssertEqual(resolver.problems.count, 1) @@ -580,11 +580,11 @@ class ReferenceResolverTests: XCTestCase { Discussion link to ``SideKit``. """ - let (bundle, context) = try await testBundleAndContext() + let (_, context) = try await testBundleAndContext() let document = Document(parsing: source, options: [.parseBlockDirectives, .parseSymbolLinks]) let article = try XCTUnwrap(Article(markup: document, metadata: nil, redirects: nil, options: [:])) - var resolver = ReferenceResolver(context: context, bundle: bundle) + var resolver = ReferenceResolver(context: context) let resolvedArticle = try XCTUnwrap(resolver.visitArticle(article) as? Article) let abstractSection = try XCTUnwrap(resolvedArticle.abstractSection) @@ -612,9 +612,9 @@ class ReferenceResolverTests: XCTestCase { } func testForwardsSymbolPropertiesThatAreUnmodifiedDuringLinkResolution() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var resolver = ReferenceResolver(context: context, bundle: bundle) + var resolver = ReferenceResolver(context: context) let symbol = try XCTUnwrap(context.documentationCache["s:5MyKit0A5ClassC"]?.semantic as? Symbol) @@ -768,7 +768,7 @@ class ReferenceResolverTests: XCTestCase { mixins: [:] ) - let (bundle, context) = try await testBundleAndContext() + let (_, context) = try await testBundleAndContext() let documentationExtensionContent = """ # ``Something`` @@ -785,7 +785,7 @@ class ReferenceResolverTests: XCTestCase { let article = Article( from: Document(parsing: documentationExtensionContent, source: documentationExtensionURL, options: [.parseSymbolLinks, .parseBlockDirectives]), source: documentationExtensionURL, - for: bundle, + for: context.inputs, problems: &ignoredProblems ) XCTAssert(ignoredProblems.isEmpty, "Unexpected problems creating article") @@ -801,7 +801,7 @@ class ReferenceResolverTests: XCTestCase { XCTAssertEqual(node.docChunks.count, 2, "This node has content from both the in-source comment and the documentation extension file.") - var resolver = ReferenceResolver(context: context, bundle: bundle) + var resolver = ReferenceResolver(context: context) _ = resolver.visitSymbol(node.semantic as! Symbol) let problems = resolver.problems.sorted(by: \.diagnostic.summary) From e386863ffc569af2448061ed4ac528978369c105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 11:02:47 +0200 Subject: [PATCH 07/19] Remove redundant "bundle" parameter from DocumentationContentRenderer --- .../Convert/ConvertService.swift | 2 +- .../DocumentationContentRenderer.swift | 56 ++++++++++--------- .../Model/Rendering/RenderContext.swift | 2 +- .../Rendering/RenderNodeTranslator.swift | 6 +- .../Model/SemaToRenderNodeTests.swift | 8 +-- .../DocumentationContentRendererTests.swift | 4 +- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift index 36c1bb80d..f7ea6ed5b 100644 --- a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift +++ b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift @@ -245,7 +245,7 @@ public struct ConvertService: DocumentationService { let bundle = context.inputs guard bundle.id == topicReference.bundleID else { return nil } - let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle) + let renderer = DocumentationContentRenderer(context: context) let documentationNodeKind: DocumentationNode.Kind = isDocumentationExtensionContent ? .unknownSymbol : .article let overridingDocumentationNode = DocumentationContext.documentationNodeAndTitle(for: article, kind: documentationNodeKind, in: bundle)?.node diff --git a/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift b/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift index 3d7487741..0d6ee8dd4 100644 --- a/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift +++ b/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift @@ -47,18 +47,20 @@ extension RenderReferenceDependencies: Codable { /// A collection of functions that render a piece of documentation content. public class DocumentationContentRenderer { - let documentationContext: DocumentationContext - let bundle: DocumentationBundle + let context: DocumentationContext let urlGenerator: PresentationURLGenerator - /// Creates a new content renderer for the given documentation context and bundle. + /// Creates a new content renderer for the given documentation context. /// - Parameters: - /// - documentationContext: A documentation context. - /// - bundle: A documentation bundle. - public init(documentationContext: DocumentationContext, bundle: DocumentationBundle) { - self.documentationContext = documentationContext - self.bundle = bundle - self.urlGenerator = PresentationURLGenerator(context: documentationContext, baseURL: bundle.baseURL) + /// - context: A documentation context. + public init(context: DocumentationContext) { + self.context = context + self.urlGenerator = PresentationURLGenerator(context: context, baseURL: context.inputs.baseURL) + } + + @available(*, deprecated, renamed: "init(context:)", message: "Use 'init(context:)' instead. This deprecated API will be removed after 6.4 is released.") + public convenience init(documentationContext: DocumentationContext, bundle _: DocumentationBundle) { + self.init(context: documentationContext) } /// For symbol nodes, returns the declaration render section if any. @@ -171,7 +173,7 @@ public class DocumentationContentRenderer { // Generates a generic conformance section for the given reference. func conformanceSectionFor(_ reference: ResolvedTopicReference, collectedConstraints: [TopicReference: [SymbolGraph.Symbol.Swift.GenericConstraint]]) -> ConformanceSection? { - guard let node = try? documentationContext.entity(with: reference), + guard let node = try? context.entity(with: reference), let symbol = node.symbol else { // Couldn't find the node for this reference return nil @@ -192,8 +194,8 @@ public class DocumentationContentRenderer { } let isLeaf = SymbolReference.isLeaf(symbol) - let parentName = documentationContext.parents(of: reference).first - .flatMap { try? documentationContext.entity(with: $0).symbol?.names.title } + let parentName = context.parents(of: reference).first + .flatMap { try? context.entity(with: $0).symbol?.names.title } let options = ConformanceSection.ConstraintRenderOptions( isLeaf: isLeaf, @@ -211,7 +213,7 @@ public class DocumentationContentRenderer { // We verify that this is a symbol with defined availability // and that we're feeding in a current set of platforms to the context. guard let symbol = node.semantic as? Symbol, - let currentPlatforms = documentationContext.configuration.externalMetadata.currentPlatforms, + let currentPlatforms = context.configuration.externalMetadata.currentPlatforms, !currentPlatforms.isEmpty, let symbolAvailability = symbol.availability?.availability.filter({ !$0.isUnconditionallyUnavailable }), // symbol that's unconditionally unavailable in all the platforms can't be in beta. !symbolAvailability.isEmpty // A symbol without availability items can't be in beta. @@ -230,7 +232,7 @@ public class DocumentationContentRenderer { guard let name = availability.domain.map({ PlatformName(operatingSystemName: $0.rawValue) }), // Use the display name of the platform when looking up the current platforms // as we expect that form on the command line. - let current = documentationContext.configuration.externalMetadata.currentPlatforms?[name.displayName] + let current = context.configuration.externalMetadata.currentPlatforms?[name.displayName] else { return false } @@ -287,14 +289,14 @@ public class DocumentationContentRenderer { /// /// - Returns: The rendered documentation node. func renderReference(for reference: ResolvedTopicReference, with overridingDocumentationNode: DocumentationNode? = nil, dependencies: inout RenderReferenceDependencies) -> TopicRenderReference { - let resolver = LinkTitleResolver(context: documentationContext, source: reference.url) + let resolver = LinkTitleResolver(context: context, source: reference.url) let titleVariants: DocumentationDataVariants - let node = try? overridingDocumentationNode ?? documentationContext.entity(with: reference) + let node = try? overridingDocumentationNode ?? context.entity(with: reference) if let node, let resolvedTitle = resolver.title(for: node) { titleVariants = resolvedTitle - } else if let anchorSection = documentationContext.nodeAnchorSections[reference] { + } else if let anchorSection = context.nodeAnchorSections[reference] { // No need to continue, return a section topic reference return TopicRenderReference( identifier: RenderReferenceIdentifier(reference.absoluteString), @@ -304,11 +306,11 @@ public class DocumentationContentRenderer { kind: .section, estimatedTime: nil ) - } else if let topicGraphOnlyNode = documentationContext.topicGraph.nodeWithReference(reference) { + } else if let topicGraphOnlyNode = context.topicGraph.nodeWithReference(reference) { // Some nodes are artificially inserted into the topic graph, // try resolving that way as a fallback after looking up `documentationCache`. titleVariants = .init(defaultVariantValue: topicGraphOnlyNode.title) - } else if let external = documentationContext.externalCache[reference] { + } else if let external = context.externalCache[reference] { let renderDependencies = external.makeRenderDependencies() dependencies.topicReferences.append(contentsOf: renderDependencies.topicReferences) @@ -326,7 +328,7 @@ public class DocumentationContentRenderer { // Topic render references require the URLs to be relative, even if they're external. let presentationURL = urlGenerator.presentationURLForReference(reference) - var contentCompiler = RenderContentCompiler(context: documentationContext, identifier: reference) + var contentCompiler = RenderContentCompiler(context: context, identifier: reference) let abstractContent: VariantCollection<[RenderInlineContent]> var abstractedNode = node @@ -337,7 +339,7 @@ public class DocumentationContentRenderer { path: reference.path, sourceLanguages: reference.sourceLanguages ) - abstractedNode = try? documentationContext.entity(with: containerReference) + abstractedNode = try? context.entity(with: containerReference) } func extractAbstract(from paragraph: Paragraph?) -> [RenderInlineContent] { @@ -397,13 +399,13 @@ public class DocumentationContentRenderer { renderReference.images = node?.metadata?.pageImages.compactMap { pageImage -> TopicImage? in guard let image = TopicImage( pageImage: pageImage, - with: documentationContext, + with: context, in: reference ) else { return nil } - guard let asset = documentationContext.resolveAsset( + guard let asset = context.resolveAsset( named: image.identifier.identifier, in: reference ) else { @@ -460,7 +462,7 @@ public class DocumentationContentRenderer { var result = [RenderNode.Tag]() /// Add an SPI tag to SPI symbols. - if let node = try? documentationContext.entity(with: reference), + if let node = try? context.entity(with: reference), let symbol = node.semantic as? Symbol, symbol.isSPI { result.append(.spi) @@ -479,7 +481,7 @@ public class DocumentationContentRenderer { /// Returns the task groups for a given node reference. func taskGroups(for reference: ResolvedTopicReference) -> [ReferenceGroup]? { - guard let node = try? documentationContext.entity(with: reference) else { return nil } + guard let node = try? context.entity(with: reference) else { return nil } let groups: [TaskGroup]? switch node.semantic { @@ -505,7 +507,7 @@ public class DocumentationContentRenderer { // For external links, verify they've resolved successfully and return `nil` otherwise. if linkHost != reference.bundleID.rawValue { - if let url = ValidatedURL(destination), case .success(let externalReference) = documentationContext.externallyResolvedLinks[url] { + if let url = ValidatedURL(destination), case .success(let externalReference) = context.externallyResolvedLinks[url] { return externalReference } return nil @@ -518,7 +520,7 @@ public class DocumentationContentRenderer { } let supportedLanguages = group.directives[SupportedLanguage.directiveName]?.compactMap { - SupportedLanguage(from: $0, source: nil, for: bundle)?.language + SupportedLanguage(from: $0, source: nil, for: context.inputs)?.language } return ReferenceGroup( diff --git a/Sources/SwiftDocC/Model/Rendering/RenderContext.swift b/Sources/SwiftDocC/Model/Rendering/RenderContext.swift index 26a299c10..e4a5ab403 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderContext.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderContext.swift @@ -28,7 +28,7 @@ public struct RenderContext { public init(documentationContext: DocumentationContext, bundle: DocumentationBundle) { self.documentationContext = documentationContext self.bundle = bundle - self.renderer = DocumentationContentRenderer(documentationContext: documentationContext, bundle: bundle) + self.renderer = DocumentationContentRenderer(context: documentationContext) createRenderedContent() } diff --git a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift index 39eb9a11a..4b1ed22a0 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift @@ -419,7 +419,7 @@ public struct RenderNodeTranslator: SemanticVisitor { private mutating func createTopicRenderReferences() -> [String: any RenderReference] { var renderReferences: [String: any RenderReference] = [:] - let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle) + let renderer = DocumentationContentRenderer(context: context) for reference in collectedTopicReferences { var renderReference: TopicRenderReference @@ -1330,7 +1330,7 @@ public struct RenderNodeTranslator: SemanticVisitor { collectedTopicReferences.append(identifier) - let contentRenderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle) + let contentRenderer = DocumentationContentRenderer(context: context) node.metadata.tags = contentRenderer.tags(for: identifier) var hierarchyTranslator = RenderHierarchyTranslator(context: context) @@ -2014,7 +2014,7 @@ public struct RenderNodeTranslator: SemanticVisitor { self.bundle = bundle self.identifier = identifier self.renderContext = renderContext - self.contentRenderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle) + self.contentRenderer = DocumentationContentRenderer(context: context) self.shouldEmitSymbolSourceFileURIs = emitSymbolSourceFileURIs self.shouldEmitSymbolAccessLevels = emitSymbolAccessLevels self.sourceRepository = sourceRepository diff --git a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift index 9f56c8fcd..a1be7f393 100644 --- a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift +++ b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift @@ -1944,7 +1944,7 @@ Document XCTAssertEqual(renderNode.metadata.platforms?.first?.isBeta, false) } - // Symbol with an empty set of availbility items. + // Symbol with an empty set of availability items. do { @@ -1953,7 +1953,7 @@ Document ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) (node.semantic as? Symbol)?.availability = SymbolGraph.Symbol.Availability(availability: []) - let documentationContentRendered = DocumentationContentRenderer(documentationContext: context, bundle: bundle) + let documentationContentRendered = DocumentationContentRenderer(context: context) let isBeta = documentationContentRendered.isBeta(node) // Verify that the symbol is not beta since it does not contains availability info. XCTAssertFalse(isBeta) @@ -2096,12 +2096,12 @@ Document // Set all platforms as unconditionally unavailable and test that the symbol is not marked as beta. do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (_, context, reference) = try await makeTestBundle(currentPlatforms: [ "iOS": PlatformVersion(VersionTriplet(100, 0, 0), beta: true) ], referencePath: "/documentation/MyKit/MyClass") let node = try context.entity(with: reference) (node.semantic as? Symbol)?.availability = SymbolGraph.Symbol.Availability(availability: [.init(domain: SymbolGraph.Symbol.Availability.Domain(rawValue: "iOS"), introducedVersion: nil, deprecatedVersion: nil, obsoletedVersion: nil, message: nil, renamed: nil, isUnconditionallyDeprecated: false, isUnconditionallyUnavailable: true, willEventuallyBeDeprecated: false)]) - let documentationContentRendered = DocumentationContentRenderer(documentationContext: context, bundle: bundle) + let documentationContentRendered = DocumentationContentRenderer(context: context) let isBeta = documentationContentRendered.isBeta(node) // Verify that the symbol is not beta since it's unavailable in all the platforms. XCTAssertFalse(isBeta) diff --git a/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift b/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift index 09ca5e064..daf92c4e1 100644 --- a/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift @@ -139,8 +139,8 @@ private extension DocumentationDataVariantsTrait { private extension DocumentationContentRendererTests { func makeDocumentationContentRenderer() async throws -> DocumentationContentRenderer { - let (bundle, context) = try await testBundleAndContext() - return DocumentationContentRenderer(documentationContext: context, bundle: bundle) + let (_, context) = try await testBundleAndContext() + return DocumentationContentRenderer(context: context) } var nodeWithSubheadingAndNavigatorVariants: DocumentationNode { From 9bacbbd539b868f8c29cd5fd924cd84cd653670a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 11:15:54 +0200 Subject: [PATCH 08/19] Remove redundant "bundle" parameter from RenderNodeTranslator --- .../DocumentationContextConverter.swift | 1 - .../DocumentationNodeConverter.swift | 2 +- .../Convert/ConvertService.swift | 2 +- .../ConvertActionConverter.swift | 2 +- .../Model/Rendering/RenderContext.swift | 14 +- .../Rendering/RenderNodeTranslator.swift | 15 +- .../DocumentationContextConverterTests.swift | 6 +- .../Converter/RenderContextTests.swift | 5 +- .../Converter/RenderNodeCodableTests.swift | 6 +- .../Indexing/ExternalRenderNodeTests.swift | 6 +- .../Indexing/IndexingTests.swift | 18 +- .../Indexing/NavigatorIndexTests.swift | 20 +- .../Indexing/RenderIndexTests.swift | 2 +- .../AutoCapitalizationTests.swift | 18 +- .../AutomaticCurationTests.swift | 74 +++-- .../DocumentationContextTests.swift | 18 +- .../ExternalPathHierarchyResolverTests.swift | 4 +- .../Infrastructure/NodeTagsTests.swift | 10 +- .../ReferenceResolverTests.swift | 58 ++-- .../RenderHierarchyTranslatorTests.swift | 8 +- .../Model/RenderNodeDiffingBundleTests.swift | 6 +- .../Model/RenderNodeSerializationTests.swift | 32 +- .../SemaToRenderNodeMultiLanguageTests.swift | 6 +- .../Model/SemaToRenderNodeTests.swift | 275 +++++++++--------- ...OutOfProcessReferenceResolverV2Tests.swift | 5 +- .../Rendering/AutomaticSeeAlsoTests.swift | 30 +- .../AvailabilityRenderOrderTests.swift | 9 +- .../ConstraintsRenderSectionTests.swift | 48 +-- .../DeclarationsRenderSectionTests.swift | 22 +- .../Rendering/DefaultAvailabilityTests.swift | 28 +- .../Rendering/DeprecationSummaryTests.swift | 52 ++-- .../Rendering/ExternalLinkTitleTests.swift | 4 +- .../Rendering/HeadingAnchorTests.swift | 2 +- .../MentionsRenderSectionTests.swift | 14 +- .../Rendering/PageKindTests.swift | 2 +- .../Rendering/PlatformAvailabilityTests.swift | 28 +- .../Rendering/RESTSymbolsTests.swift | 8 +- .../Rendering/RenderMetadataTests.swift | 12 +- ...derNodeTranslatorSymbolVariantsTests.swift | 13 +- .../Rendering/RenderNodeTranslatorTests.swift | 60 ++-- .../SwiftDocCTests/Rendering/RoleTests.swift | 12 +- .../Rendering/SampleDownloadTests.swift | 6 +- .../Rendering/SymbolAvailabilityTests.swift | 6 +- .../Semantics/DoxygenTests.swift | 6 +- .../Semantics/VideoMediaTests.swift | 8 +- .../XCTestCase+LoadingTestData.swift | 6 +- 46 files changed, 481 insertions(+), 508 deletions(-) diff --git a/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift b/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift index 72e23665b..a18f97980 100644 --- a/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift +++ b/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift @@ -91,7 +91,6 @@ public class DocumentationContextConverter { var translator = RenderNodeTranslator( context: context, - bundle: bundle, identifier: node.reference, renderContext: renderContext, emitSymbolSourceFileURIs: shouldEmitSymbolSourceFileURIs, diff --git a/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift b/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift index 77804359e..be69ef9e1 100644 --- a/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift +++ b/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift @@ -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 } } diff --git a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift index f7ea6ed5b..1b55812a3 100644 --- a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift +++ b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift @@ -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 { diff --git a/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift b/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift index 17a5db0a7..e14dec587 100644 --- a/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift +++ b/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift @@ -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) diff --git a/Sources/SwiftDocC/Model/Rendering/RenderContext.swift b/Sources/SwiftDocC/Model/Rendering/RenderContext.swift index e4a5ab403..367845ad3 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderContext.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderContext.swift @@ -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() @@ -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 var dependencies = RenderReferenceDependencies() let renderReference = renderer.renderReference(for: reference, dependencies: &dependencies) let canonicalPath = documentationContext.shortestFinitePath(to: reference).flatMap { $0.isEmpty ? nil : $0 } diff --git a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift index 4b1ed22a0..cddcb3420 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift @@ -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): @@ -806,7 +806,7 @@ public struct RenderNodeTranslator: SemanticVisitor { for: documentationNode, withTraits: allowedTraits, context: context, - bundle: bundle, + bundle: context.inputs, renderContext: renderContext, renderer: contentRenderer ) { @@ -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. @@ -1241,7 +1241,7 @@ public struct RenderNodeTranslator: SemanticVisitor { node.metadata.extendedModuleVariants = VariantCollection(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) @@ -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 { @@ -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] = [:] @@ -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 @@ -2002,7 +2001,6 @@ public struct RenderNodeTranslator: SemanticVisitor { init( context: DocumentationContext, - bundle: DocumentationBundle, identifier: ResolvedTopicReference, renderContext: RenderContext? = nil, emitSymbolSourceFileURIs: Bool = false, @@ -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) diff --git a/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift b/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift index 381720b5b..96e96a4f7 100644 --- a/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift +++ b/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift @@ -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() @@ -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"] @@ -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"] diff --git a/Tests/SwiftDocCTests/Converter/RenderContextTests.swift b/Tests/SwiftDocCTests/Converter/RenderContextTests.swift index 7ac0d4240..3d9805df4 100644 --- a/Tests/SwiftDocCTests/Converter/RenderContextTests.swift +++ b/Tests/SwiftDocCTests/Converter/RenderContextTests.swift @@ -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.") diff --git a/Tests/SwiftDocCTests/Converter/RenderNodeCodableTests.swift b/Tests/SwiftDocCTests/Converter/RenderNodeCodableTests.swift index 2295ec79f..94c129011 100644 --- a/Tests/SwiftDocCTests/Converter/RenderNodeCodableTests.swift +++ b/Tests/SwiftDocCTests/Converter/RenderNodeCodableTests.swift @@ -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 = """ @@ -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( @@ -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) diff --git a/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift b/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift index d2c790caa..8c201a2bc 100644 --- a/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift +++ b/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift @@ -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) @@ -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) @@ -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) diff --git a/Tests/SwiftDocCTests/Indexing/IndexingTests.swift b/Tests/SwiftDocCTests/Indexing/IndexingTests.swift index 758f370cb..2b83a1e1d 100644 --- a/Tests/SwiftDocCTests/Indexing/IndexingTests.swift +++ b/Tests/SwiftDocCTests/Indexing/IndexingTests.swift @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift index 71ea0f8da..c0042f0b8 100644 --- a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift +++ b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift @@ -458,7 +458,7 @@ Root func testNavigatorIndexGeneration() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) var results = Set() @@ -648,7 +648,7 @@ Root let (bundle, context) = try await loadBundle(catalog: catalog) - 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() @@ -695,7 +695,7 @@ Root func testNavigatorWithDifferentSwiftAndObjectiveCHierarchies() async throws { let (_, bundle, context) = try await testBundleAndContext(named: "GeometricalShapes") - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) let fromMemoryBuilder = NavigatorIndex.Builder(outputURL: try createTemporaryDirectory(), bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) @@ -956,7 +956,7 @@ Root func testNavigatorIndexUsingPageTitleGeneration() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) var results = Set() @@ -1082,7 +1082,7 @@ Root func testNavigatorIndexGenerationWithCuratedFragment() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) var results = Set() @@ -1145,7 +1145,7 @@ Root func testNavigatorIndexAvailabilityGeneration() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - 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() @@ -1249,7 +1249,7 @@ Root func testCustomIconsInNavigator() async throws { let (bundle, context) = try await testBundleAndContext(named: "BookLikeContent") // This content has a @PageImage with the "icon" purpose - 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() @@ -1275,7 +1275,7 @@ Root func testNavigatorIndexDifferentHasherGeneration() async throws { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - 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() @@ -2051,7 +2051,7 @@ Root configuration.externalMetadata.currentPlatforms = platformMetadata let (_, bundle, context) = try await testBundleAndContext(named: "AvailabilityBetaBundle", configuration: configuration) - 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) @@ -2094,7 +2094,7 @@ Root func generatedNavigatorIndex(for testBundleName: String, bundleIdentifier: String) async throws -> NavigatorIndex { let (bundle, context) = try await testBundleAndContext(named: testBundleName) - 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() diff --git a/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift b/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift index acc19fa5a..001dfe764 100644 --- a/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift +++ b/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift @@ -742,7 +742,7 @@ final class RenderIndexTests: XCTestCase { } func generatedRenderIndex(for bundle: DocumentationBundle, withIdentifier bundleIdentifier: String, withContext context: DocumentationContext) throws -> RenderIndex { - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) let indexDirectory = try createTemporaryDirectory() let builder = NavigatorIndex.Builder( diff --git a/Tests/SwiftDocCTests/Infrastructure/AutoCapitalizationTests.swift b/Tests/SwiftDocCTests/Infrastructure/AutoCapitalizationTests.swift index 8eb5ce13c..f45a2d711 100644 --- a/Tests/SwiftDocCTests/Infrastructure/AutoCapitalizationTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/AutoCapitalizationTests.swift @@ -60,18 +60,18 @@ class AutoCapitalizationTests: XCTestCase { let catalog = Folder(name: "unit-test.docc", content: [ JSONFile(name: "ModuleName.symbols.json", content: symbolGraph) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) XCTAssertEqual(context.problems.count, 0) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleName/functionName(...)", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleName/functionName(...)", sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) let parameterSections = symbol.parametersSectionVariants XCTAssertEqual(parameterSections[.swift]?.parameters.map(\.name), ["one", "two", "three", "four", "five"]) let parameterSectionTranslator = ParametersSectionTranslator() - var renderNodeTranslator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var renderNodeTranslator = RenderNodeTranslator(context: context, identifier: reference) var renderNode = renderNodeTranslator.visit(symbol) as! RenderNode let translatedParameters = parameterSectionTranslator.translateSection(for: symbol, renderNode: &renderNode, renderNodeTranslator: &renderNodeTranslator) let paramsRenderSection = translatedParameters?.defaultValue?.section as! ParametersRenderSection @@ -105,18 +105,18 @@ class AutoCapitalizationTests: XCTestCase { let catalog = Folder(name: "unit-test.docc", content: [ JSONFile(name: "ModuleName.symbols.json", content: symbolGraph) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) XCTAssertEqual(context.problems.count, 0) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleName/functionName(...)", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleName/functionName(...)", sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) let parameterSections = symbol.parametersSectionVariants XCTAssertEqual(parameterSections[.swift]?.parameters.map(\.name), ["one", "two", "three", "four", "five"]) let parameterSectionTranslator = ParametersSectionTranslator() - var renderNodeTranslator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var renderNodeTranslator = RenderNodeTranslator(context: context, identifier: reference) var renderNode = renderNodeTranslator.visit(symbol) as! RenderNode let translatedParameters = parameterSectionTranslator.translateSection(for: symbol, renderNode: &renderNode, renderNodeTranslator: &renderNodeTranslator) let paramsRenderSection = translatedParameters?.defaultValue?.section as! ParametersRenderSection @@ -146,16 +146,16 @@ class AutoCapitalizationTests: XCTestCase { let catalog = Folder(name: "unit-test.docc", content: [ JSONFile(name: "ModuleName.symbols.json", content: symbolGraph) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) XCTAssertEqual(context.problems.count, 0) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleName/functionName(...)", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleName/functionName(...)", sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) let returnsSectionTranslator = ReturnsSectionTranslator() - var renderNodeTranslator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var renderNodeTranslator = RenderNodeTranslator(context: context, identifier: reference) var renderNode = renderNodeTranslator.visit(symbol) as! RenderNode let translatedReturns = returnsSectionTranslator.translateSection(for: symbol, renderNode: &renderNode, renderNodeTranslator: &renderNodeTranslator) let returnsRenderSection = translatedReturns?.defaultValue?.section as! ContentRenderSection diff --git a/Tests/SwiftDocCTests/Infrastructure/AutomaticCurationTests.swift b/Tests/SwiftDocCTests/Infrastructure/AutomaticCurationTests.swift index c66d09454..d214b7733 100644 --- a/Tests/SwiftDocCTests/Infrastructure/AutomaticCurationTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/AutomaticCurationTests.swift @@ -38,9 +38,9 @@ class AutomaticCurationTests: XCTestCase { )) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) - try assertRenderedPage(atPath: "/documentation/ModuleName/SomeClass", containsAutomaticTopicSectionFor: kind, context: context, bundle: bundle) + try assertRenderedPage(atPath: "/documentation/ModuleName/SomeClass", containsAutomaticTopicSectionFor: kind, context: context) } } @@ -83,10 +83,10 @@ class AutomaticCurationTests: XCTestCase { )), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) - try assertRenderedPage(atPath: "/documentation/ModuleName", containsAutomaticTopicSectionFor: .extendedModule, context: context, bundle: bundle) - try assertRenderedPage(atPath: "/documentation/ModuleName/ExtendedModule", containsAutomaticTopicSectionFor: kind, context: context, bundle: bundle) + try assertRenderedPage(atPath: "/documentation/ModuleName", containsAutomaticTopicSectionFor: .extendedModule, context: context) + try assertRenderedPage(atPath: "/documentation/ModuleName/ExtendedModule", containsAutomaticTopicSectionFor: kind, context: context) } } @@ -94,12 +94,11 @@ class AutomaticCurationTests: XCTestCase { atPath path: String, containsAutomaticTopicSectionFor kind: SymbolGraph.Symbol.KindIdentifier, context: DocumentationContext, - bundle: DocumentationBundle, file: StaticString = #filePath, line: UInt = #line ) throws { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: path, sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(node.semantic) as? RenderNode, file: file, line: line) for section in renderNode.topicSections { @@ -117,7 +116,7 @@ class AutomaticCurationTests: XCTestCase { } func testAutomaticTopicsSkippingCustomCuratedSymbols() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], configureBundle: { url in // Curate some of members of SideClass in an API collection try """ # Some API collection @@ -136,11 +135,11 @@ class AutomaticCurationTests: XCTestCase { """.write(to: url.appendingPathComponent("sideclass.md"), atomically: true, encoding: .utf8) }) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) // Compile the render node to flex the automatic curator let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode // Verify that uncurated element `SideKit/SideClass/Element` is @@ -172,7 +171,7 @@ class AutomaticCurationTests: XCTestCase { for curatedIndices in variationsOfChildrenToCurate { let manualCuration = curatedIndices.map { "- <\(allExpectedChildren[$0])>" }.joined(separator: "\n") - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in try """ # ``SideKit/SideClass`` @@ -186,10 +185,10 @@ class AutomaticCurationTests: XCTestCase { """.write(to: url.appendingPathComponent("documentation/sideclass.md"), atomically: true, encoding: .utf8) } - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) // Compile docs and verify the generated Topics section let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode // Verify that all the symbols are curated, either manually or automatically @@ -231,7 +230,7 @@ class AutomaticCurationTests: XCTestCase { } func testSeeAlsoSectionForAutomaticallyCuratedTopics() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in var graph = try JSONDecoder().decode(SymbolGraph.self, from: Data(contentsOf: url.appendingPathComponent("sidekit.symbols.json"))) // Copy `SideClass` a handful of times @@ -348,8 +347,8 @@ class AutomaticCurationTests: XCTestCase { // The first topic section do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // SideKit includes the "Manually curated" task group and additional automatically created groups. @@ -364,8 +363,8 @@ class AutomaticCurationTests: XCTestCase { // The second topic section do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClassFour", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClassFour", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // The other symbols in the same topic section appear in this See Also section @@ -377,8 +376,8 @@ class AutomaticCurationTests: XCTestCase { // The second topic section do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClassSix", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClassSix", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // The other symbols in the same topic section appear in this See Also section @@ -389,22 +388,22 @@ class AutomaticCurationTests: XCTestCase { // The automatically curated symbols shouldn't have a See Also section do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClassEight", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClassEight", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode XCTAssertNil(renderNode.seeAlsoSections.first, "This symbol was automatically curated and shouldn't have a See Also section") } do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClassNine", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClassNine", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode XCTAssertNil(renderNode.seeAlsoSections.first, "This symbol was automatically curated and shouldn't have a See Also section") } do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClassTen", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClassTen", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode XCTAssertNil(renderNode.seeAlsoSections.first, "This symbol was automatically curated and shouldn't have a See Also section") @@ -421,17 +420,14 @@ class AutomaticCurationTests: XCTestCase { forResource: "TopLevelCuration.symbols", withExtension: "json", subdirectory: "Test Resources")! // Create a test bundle copy with the symbol graph from above - let (bundleURL, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { url in try? FileManager.default.copyItem(at: topLevelCurationSGFURL, to: url.appendingPathComponent("TopLevelCuration.symbols.json")) } - defer { - try? FileManager.default.removeItem(at: bundleURL) - } do { // Get the framework render node - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TestBed", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TestBed", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify that `B` isn't automatically curated under the framework node @@ -443,8 +439,8 @@ class AutomaticCurationTests: XCTestCase { do { // Get the `A` render node - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TestBed/A", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TestBed/A", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify that `B` was in fact curated under `A` @@ -825,7 +821,7 @@ class AutomaticCurationTests: XCTestCase { // Compile the render node to flex the automatic curator let symbol = protocolDocumentationNode.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: protocolDocumentationNode.reference) + var translator = RenderNodeTranslator(context: context, identifier: protocolDocumentationNode.reference) let renderNode = translator.visit(symbol) as! RenderNode XCTAssertEqual(renderNode.topicSections.count, 2) @@ -1242,12 +1238,12 @@ class AutomaticCurationTests: XCTestCase { """), ]) let catalogURL = try exampleDocumentation.write(inside: createTemporaryDirectory()) - let (_, bundle, context) = try await loadBundle(from: catalogURL) + let (_, _, context) = try await loadBundle(from: catalogURL) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleName/SomeClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleName/SomeClass", sourceLanguage: .swift)) // Compile docs and verify the generated Topics section - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(node.semantic) as? RenderNode) // Verify that there are no duplicate sections in `SomeClass`'s "Topics" section diff --git a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift index e63b282bd..6777edfa1 100644 --- a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift @@ -1329,7 +1329,7 @@ class DocumentationContextTests: XCTestCase { ] + testData.symbolGraphFiles) let (bundle, context) = try await loadBundle(catalog: testCatalog) - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let identifier = ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/TestOverview", sourceLanguage: .swift) let node = try context.entity(with: identifier) @@ -1898,7 +1898,7 @@ let expected = """ """), ]) let bundleURL = try catalog.write(inside: createTemporaryDirectory()) - let (_, bundle, context) = try await loadBundle(from: bundleURL) + let (_, _, context) = try await loadBundle(from: bundleURL) let problems = context.problems XCTAssertEqual(problems.count, 0, "Unexpected problems: \(problems.map(\.diagnostic.summary).sorted())") @@ -1924,7 +1924,7 @@ let expected = """ ) } - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: moduleReference) + var translator = RenderNodeTranslator(context: context, identifier: moduleReference) let renderNode = translator.visit(moduleSymbol) as! RenderNode // Verify that the resolved links rendered as links @@ -2451,7 +2451,7 @@ let expected = """ let moduleReference = try XCTUnwrap(context.rootModules.first) let moduleNode = try context.entity(with: moduleReference) - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) let renderNode = try XCTUnwrap(converter.renderNode(for: moduleNode)) @@ -2502,7 +2502,7 @@ let expected = """ } func testDeclarationTokenKinds() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let myFunc = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) @@ -2516,7 +2516,7 @@ let expected = """ // Render declaration and compare token kinds with symbol graph let symbol = myFunc.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: myFunc.reference) + var translator = RenderNodeTranslator(context: context, identifier: myFunc.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode let declarationTokens = renderNode.primaryContentSections.mapFirst { section -> [String]? in @@ -2650,13 +2650,13 @@ let expected = """ } func testNavigatorTitle() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") func renderNodeForPath(path: String) throws -> (DocumentationNode, RenderNode) { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: path, sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode return (node, renderNode) diff --git a/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift index 9a62ddf51..96b97bc0e 100644 --- a/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift @@ -707,7 +707,7 @@ class ExternalPathHierarchyResolverTests: XCTestCase { ) // Retrieve the link information from the dependency, as if '--enable-experimental-external-link-support' was passed to DocC - let dependencyConverter = DocumentationContextConverter(bundle: dependencyBundle, context: dependencyContext, renderContext: .init(documentationContext: dependencyContext, bundle: dependencyBundle)) + let dependencyConverter = DocumentationContextConverter(bundle: dependencyBundle, context: dependencyContext, renderContext: .init(documentationContext: dependencyContext)) let linkSummaries: [LinkDestinationSummary] = try dependencyContext.knownPages.flatMap { reference in let entity = try dependencyContext.entity(with: reference) @@ -794,7 +794,7 @@ class ExternalPathHierarchyResolverTests: XCTestCase { XCTAssertEqual(mainContext.knownPages.count, 3 /* 2 symbols & 1 module*/) - let mainConverter = DocumentationContextConverter(bundle: mainBundle, context: mainContext, renderContext: .init(documentationContext: mainContext, bundle: mainBundle)) + let mainConverter = DocumentationContextConverter(bundle: mainBundle, context: mainContext, renderContext: .init(documentationContext: mainContext)) // Check the relationships of 'SomeClass' do { diff --git a/Tests/SwiftDocCTests/Infrastructure/NodeTagsTests.swift b/Tests/SwiftDocCTests/Infrastructure/NodeTagsTests.swift index 37157b55c..4a34e693c 100644 --- a/Tests/SwiftDocCTests/Infrastructure/NodeTagsTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/NodeTagsTests.swift @@ -24,27 +24,27 @@ class NodeTagsTests: XCTestCase { let tempURL = try createTemporaryDirectory().appendingPathComponent("unit-tests.docc") try bundleFolder.write(to: tempURL) - let (_, bundle, context) = try await loadBundle(from: tempURL) + let (_, _, context) = try await loadBundle(from: tempURL) // Verify that `Test` is marked as SPI. - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Minimal_docs/Test", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/Minimal_docs/Test", sourceLanguage: .swift) let node = try XCTUnwrap(context.entity(with: reference)) let symbol = try XCTUnwrap(node.semantic as? Symbol) XCTAssertTrue(symbol.isSPI) // Verify the render node contains the SPI tag. - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) XCTAssertEqual(renderNode.metadata.tags, [.spi]) // Verify that the link to the node contains the SPI tag. - let moduleReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Minimal_docs", sourceLanguage: .swift) + let moduleReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/Minimal_docs", sourceLanguage: .swift) let moduleNode = try XCTUnwrap(context.entity(with: moduleReference)) let moduleSymbol = try XCTUnwrap(moduleNode.semantic as? Symbol) // Verify the render node contains the SPI tag. - var moduleTranslator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var moduleTranslator = RenderNodeTranslator(context: context, identifier: node.reference) let moduleRenderNode = try XCTUnwrap(moduleTranslator.visit(moduleSymbol) as? RenderNode) let linkReference = try XCTUnwrap(moduleRenderNode.references["doc://com.tests.spi/documentation/Minimal_docs/Test"] as? TopicRenderReference) diff --git a/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift index e43620429..4a3749335 100644 --- a/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/ReferenceResolverTests.swift @@ -78,7 +78,7 @@ class ReferenceResolverTests: XCTestCase { // Tests all reference syntax formats to a child symbol func testReferencesToChildFromFramework() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit`` @@ -101,7 +101,7 @@ class ReferenceResolverTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify resolved links @@ -111,7 +111,7 @@ class ReferenceResolverTests: XCTestCase { // Test relative paths to non-child symbol func testReferencesToGrandChildFromFramework() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit`` @@ -127,7 +127,7 @@ class ReferenceResolverTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify resolved links @@ -137,7 +137,7 @@ class ReferenceResolverTests: XCTestCase { // Test references to a sibling symbol func testReferencesToSiblingFromFramework() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit/SideClass/myFunction()`` @@ -153,7 +153,7 @@ class ReferenceResolverTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass/myFunction()", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify resolved links @@ -163,7 +163,7 @@ class ReferenceResolverTests: XCTestCase { // Test references to symbols in root paths func testReferencesToTutorial() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit/SideClass/myFunction()`` @@ -179,7 +179,7 @@ class ReferenceResolverTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass/myFunction()", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify resolved links @@ -189,7 +189,7 @@ class ReferenceResolverTests: XCTestCase { // Test references to technology pages func testReferencesToTechnologyPages() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit/SideClass/myFunction()`` @@ -204,7 +204,7 @@ class ReferenceResolverTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass/myFunction()", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify resolved links @@ -214,7 +214,7 @@ class ReferenceResolverTests: XCTestCase { // Test external references func testExternalReferencesConsiderBundleIdentifier() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit/SideClass/myFunction()`` @@ -230,7 +230,7 @@ class ReferenceResolverTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass/myFunction()", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify resolved links @@ -346,7 +346,7 @@ class ReferenceResolverTests: XCTestCase { } func testRelativeReferencesToExtensionSymbols() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "BundleWithRelativePathAmbiguity") { root in + let (_, _, context) = try await testBundleAndContext(copying: "BundleWithRelativePathAmbiguity") { root in // We don't want the external target to be part of the archive as that is not // officially supported yet. try FileManager.default.removeItem(at: root.appendingPathComponent("Dependency.symbols.json")) @@ -378,7 +378,7 @@ class ReferenceResolverTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/BundleWithRelativePathAmbiguity/Dependency", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode let content = try XCTUnwrap(renderNode.primaryContentSections.first as? ContentRenderSection).content @@ -407,10 +407,10 @@ class ReferenceResolverTests: XCTestCase { } func testCuratedExtensionRemovesEmptyPage() async throws { - let (bundle, context) = try await testBundleAndContext(named: "ModuleWithSingleExtension") + let (_, context) = try await testBundleAndContext(named: "ModuleWithSingleExtension") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleWithSingleExtension", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleWithSingleExtension", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // The only children of the root topic should be the `MyNamespace` enum - i.e. the Swift @@ -421,11 +421,11 @@ class ReferenceResolverTests: XCTestCase { // Make sure that the symbol added in the extension is still present in the topic graph, // even though its synthetic "extended symbol" parents are not - XCTAssertNoThrow(try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleWithSingleExtension/Swift/Array/asdf", sourceLanguage: .swift))) + XCTAssertNoThrow(try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleWithSingleExtension/Swift/Array/asdf", sourceLanguage: .swift))) } func testCuratedExtensionWithDanglingReference() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "ModuleWithSingleExtension") { root in + let (_, _, context) = try await testBundleAndContext(copying: "ModuleWithSingleExtension") { root in let topLevelArticle = root.appendingPathComponent("ModuleWithSingleExtension.md") try FileManager.default.removeItem(at: topLevelArticle) @@ -445,16 +445,16 @@ class ReferenceResolverTests: XCTestCase { XCTAssertEqual(replacement.replacement, "`Swift/Array`") // Also make sure that the extension pages are still gone - let extendedModule = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleWithSingleExtension/Swift", sourceLanguage: .swift) + let extendedModule = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleWithSingleExtension/Swift", sourceLanguage: .swift) XCTAssertFalse(context.knownPages.contains(where: { $0 == extendedModule })) - let extendedStructure = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleWithSingleExtension/Swift/Array", sourceLanguage: .swift) + let extendedStructure = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleWithSingleExtension/Swift/Array", sourceLanguage: .swift) XCTAssertFalse(context.knownPages.contains(where: { $0 == extendedStructure })) // Load the RenderNode for the root article and make sure that the `Swift/Array` symbol link // is not rendered as a link - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleWithSingleExtension", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleWithSingleExtension", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode XCTAssertEqual(renderNode.abstract, [ @@ -522,10 +522,10 @@ class ReferenceResolverTests: XCTestCase { } func testCuratedExtensionWithAdditionalConformance() async throws { - let (bundle, context) = try await testBundleAndContext(named: "ModuleWithConformanceAndExtension") + let (_, context) = try await testBundleAndContext(named: "ModuleWithConformanceAndExtension") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleWithConformanceAndExtension/MyProtocol", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleWithConformanceAndExtension/MyProtocol", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode let conformanceSection = try XCTUnwrap(renderNode.relationshipSections.first(where: { $0.type == RelationshipsGroup.Kind.conformingTypes.rawValue })) @@ -538,10 +538,10 @@ class ReferenceResolverTests: XCTestCase { } func testExtensionWithEmptyDeclarationFragments() async throws { - let (bundle, context) = try await testBundleAndContext(named: "ModuleWithEmptyDeclarationFragments") + let (_, context) = try await testBundleAndContext(named: "ModuleWithEmptyDeclarationFragments") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleWithEmptyDeclarationFragments", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleWithEmptyDeclarationFragments", sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Despite having an extension to Float, there are no symbols added by that extension, so diff --git a/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift b/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift index 6110717c5..00b842496 100644 --- a/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift +++ b/Tests/SwiftDocCTests/Model/RenderHierarchyTranslatorTests.swift @@ -89,7 +89,7 @@ class RenderHierarchyTranslatorTests: XCTestCase { func testMultiplePaths() async throws { // Curate "TestTutorial" under MyKit as well as TechnologyX. - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in let myKitURL = root.appendingPathComponent("documentation/mykit.md") let text = try String(contentsOf: myKitURL).replacingOccurrences(of: "## Topics", with: """ ## Topics @@ -104,7 +104,7 @@ class RenderHierarchyTranslatorTests: XCTestCase { // Get a translated render node let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: identifier) + var translator = RenderNodeTranslator(context: context, identifier: identifier) let renderNode = translator.visit(node.semantic) as! RenderNode guard case .tutorials(let hierarchy) = renderNode.hierarchyVariants.defaultValue else { @@ -129,7 +129,7 @@ class RenderHierarchyTranslatorTests: XCTestCase { } func testLanguageSpecificHierarchies() async throws { - let (bundle, context) = try await testBundleAndContext(named: "GeometricalShapes") + let (_, context) = try await testBundleAndContext(named: "GeometricalShapes") let moduleReference = try XCTUnwrap(context.soleRootModuleReference) // An inner function to assert the rendered hierarchy values for a given reference @@ -141,7 +141,7 @@ class RenderHierarchyTranslatorTests: XCTestCase { line: UInt = #line ) throws { let documentationNode = try context.entity(with: reference) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visit(documentationNode.semantic) as? RenderNode, file: file, line: line) if let expectedSwiftPaths { diff --git a/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift b/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift index 35c8d22a5..cde169c47 100644 --- a/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift +++ b/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift @@ -285,7 +285,7 @@ class RenderNodeDiffingBundleTests: XCTestCase { func testNoDiffsWhenReconvertingSameBundle() async throws { let (bundle, context) = try await testBundleAndContext(named: testBundleName) - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) for identifier in context.knownPages { @@ -307,7 +307,7 @@ class RenderNodeDiffingBundleTests: XCTestCase { let nodeOriginal = try contextOriginal.entity(with: ResolvedTopicReference(bundleID: bundleID, path: topicReferencePath, sourceLanguage: .swift)) - var renderContext = RenderContext(documentationContext: contextOriginal, bundle: bundleOriginal) + var renderContext = RenderContext(documentationContext: contextOriginal) var converter = DocumentationContextConverter(bundle: bundleOriginal, context: contextOriginal, renderContext: renderContext) let renderNodeOriginal = try XCTUnwrap(converter.renderNode(for: nodeOriginal)) @@ -319,7 +319,7 @@ class RenderNodeDiffingBundleTests: XCTestCase { let nodeModified = try contextModified.entity(with: ResolvedTopicReference(bundleID: bundleID, path: topicReferencePath, sourceLanguage: .swift)) - renderContext = RenderContext(documentationContext: contextModified, bundle: bundleModified) + renderContext = RenderContext(documentationContext: contextModified) converter = DocumentationContextConverter(bundle: bundleModified, context: contextModified, renderContext: renderContext) let renderNodeModified = try XCTUnwrap(converter.renderNode(for: nodeModified)) diff --git a/Tests/SwiftDocCTests/Model/RenderNodeSerializationTests.swift b/Tests/SwiftDocCTests/Model/RenderNodeSerializationTests.swift index d539531a3..418d23146 100644 --- a/Tests/SwiftDocCTests/Model/RenderNodeSerializationTests.swift +++ b/Tests/SwiftDocCTests/Model/RenderNodeSerializationTests.swift @@ -92,8 +92,8 @@ class RenderNodeSerializationTests: XCTestCase { } func testBundleRoundTrip() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) guard let tutorialDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, tutorial not found as first child.") @@ -101,22 +101,22 @@ class RenderNodeSerializationTests: XCTestCase { } var problems = [Problem]() - guard let tutorial = Tutorial(from: tutorialDirective, source: nil, for: bundle, problems: &problems) else { + guard let tutorial = Tutorial(from: tutorialDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create tutorial from markup: \(problems)") return } XCTAssertEqual(problems.count, 1, "Found problems \(problems.map { DiagnosticConsoleWriter.formattedDescription(for: $0.diagnostic) }) analyzing tutorial markup") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(tutorial) as! RenderNode checkRoundTrip(renderNode) } func testTutorialArticleRoundTrip() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)) guard let articleDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, article not found as first child.") @@ -124,14 +124,14 @@ class RenderNodeSerializationTests: XCTestCase { } var problems = [Problem]() - guard let article = TutorialArticle(from: articleDirective, source: nil, for: bundle, problems: &problems) else { + guard let article = TutorialArticle(from: articleDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create article from markup: \(problems)") return } XCTAssertEqual(problems.count, 0, "Found problems \(problems.map { DiagnosticConsoleWriter.formattedDescription(for: $0.diagnostic) }) analyzing article markup") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(article) as! RenderNode checkRoundTrip(renderNode) @@ -140,8 +140,8 @@ class RenderNodeSerializationTests: XCTestCase { func testAssetReferenceDictionary() async throws { typealias JSONDictionary = [String: Any] - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) guard let tutorialDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, tutorial not found as first child.") @@ -149,14 +149,14 @@ class RenderNodeSerializationTests: XCTestCase { } var problems = [Problem]() - guard let tutorial = Tutorial(from: tutorialDirective, source: nil, for: bundle, problems: &problems) else { + guard let tutorial = Tutorial(from: tutorialDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create tutorial from markup: \(problems)") return } XCTAssertEqual(problems.count, 1, "Found problems \(problems.map { DiagnosticConsoleWriter.formattedDescription(for: $0.diagnostic) }) analyzing tutorial markup") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(tutorial) as! RenderNode let data = try encode(renderNode: renderNode) @@ -192,8 +192,8 @@ class RenderNodeSerializationTests: XCTestCase { } func testDiffAvailability() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)) guard let articleDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, article not found as first child.") @@ -201,12 +201,12 @@ class RenderNodeSerializationTests: XCTestCase { } var problems = [Problem]() - guard let article = TutorialArticle(from: articleDirective, source: nil, for: bundle, problems: &problems) else { + guard let article = TutorialArticle(from: articleDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create article from markup: \(problems)") return } - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) var renderNode = translator.visit(article) as! RenderNode diff --git a/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift b/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift index e4acc7156..3f158d550 100644 --- a/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift +++ b/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift @@ -449,7 +449,7 @@ class SemaToRenderNodeMixedLanguageTests: XCTestCase { } func testSymbolLinkWorkInMultipleLanguages() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "MixedLanguageFramework") { url in + let (_, _, context) = try await testBundleAndContext(copying: "MixedLanguageFramework") { url in try """ # ``MixedLanguageFramework/Bar`` @@ -466,12 +466,12 @@ class SemaToRenderNodeMixedLanguageTests: XCTestCase { """.write(to: url.appendingPathComponent("bar.md"), atomically: true, encoding: .utf8) } - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MixedLanguageFramework/Bar", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MixedLanguageFramework/Bar", sourceLanguage: .swift)) let symbol = try XCTUnwrap(node.semantic as? Symbol) XCTAssert(context.problems.isEmpty, "Encountered unexpected problems: \(context.problems)") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) XCTAssert(context.problems.isEmpty, "Encountered unexpected problems: \(context.problems)") diff --git a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift index a1be7f393..bbcd73619 100644 --- a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift +++ b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift @@ -32,7 +32,7 @@ class SemaToRenderNodeTests: XCTestCase { XCTAssertEqual(problems.count, 1, "Found problems \(DiagnosticConsoleWriter.formattedDescription(for: problems)) analyzing tutorial markup") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(tutorial) as! RenderNode @@ -417,7 +417,7 @@ class SemaToRenderNodeTests: XCTestCase { return } - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(tutorial) as! RenderNode let intro = renderNode.sections.compactMap { $0 as? IntroRenderSection }.first! XCTAssertEqual(RenderReferenceIdentifier(backgroundIdentifier), intro.backgroundImage) @@ -436,7 +436,7 @@ class SemaToRenderNodeTests: XCTestCase { let article = node.semantic as! TutorialArticle - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(article) as! RenderNode @@ -586,7 +586,7 @@ class SemaToRenderNodeTests: XCTestCase { // Verify we emit a diagnostic for the chapter with no tutorial references. XCTAssertEqual(problems.count, expectedProblemsCount, "Found problems \(DiagnosticConsoleWriter.formattedDescription(for: problems)) analyzing tutorial markup") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(tutorialTableOfContents) as! RenderNode @@ -822,7 +822,7 @@ class SemaToRenderNodeTests: XCTestCase { XCTAssertEqual(problems.count, 0, "Found problems \(DiagnosticConsoleWriter.formattedDescription(for: problems)) analyzing tutorial markup") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(tutorialTableOfContents) as! RenderNode @@ -958,7 +958,7 @@ class SemaToRenderNodeTests: XCTestCase { let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode guard renderNode.primaryContentSections.count == 4 else { @@ -1217,7 +1217,7 @@ class SemaToRenderNodeTests: XCTestCase { let testBundleURL = Bundle.module.url( forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")! - let (_, bundle, context) = try await loadBundle( + let (_, _, context) = try await loadBundle( from: testBundleURL, externalResolvers: ["com.test.external": TestReferenceResolver()], externalSymbolResolver: TestSymbolResolver() @@ -1237,7 +1237,7 @@ class SemaToRenderNodeTests: XCTestCase { XCTAssertNotNil(context.externalCache["s:10Foundation4DataV"]) XCTAssertNotNil(context.externalCache["s:5Foundation0A5NSCodableP"]) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: myProtocol.reference) + var translator = RenderNodeTranslator(context: context, identifier: myProtocol.reference) let renderNode = translator.visit(myProtocolSymbol) as! RenderNode guard renderNode.primaryContentSections.count == 4 else { @@ -1321,7 +1321,7 @@ class SemaToRenderNodeTests: XCTestCase { let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode guard let conf = renderNode.metadata.conformance else { @@ -1341,7 +1341,7 @@ class SemaToRenderNodeTests: XCTestCase { let parent = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let parentSymbol = parent.semantic as! Symbol - var parentTranslator = RenderNodeTranslator(context: context, bundle: bundle, identifier: parent.reference) + var parentTranslator = RenderNodeTranslator(context: context, identifier: parent.reference) let parentRenderNode = parentTranslator.visit(parentSymbol) as! RenderNode guard let functionReference = parentRenderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyClass/myFunction()"] as? TopicRenderReference else { @@ -1373,7 +1373,7 @@ class SemaToRenderNodeTests: XCTestCase { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode // Test conditional conformance for the conforming type @@ -1395,7 +1395,7 @@ class SemaToRenderNodeTests: XCTestCase { let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode // Test conditional conformance for the conforming type @@ -1419,7 +1419,7 @@ class SemaToRenderNodeTests: XCTestCase { // Compile docs and verify contents let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -1484,7 +1484,7 @@ class SemaToRenderNodeTests: XCTestCase { // Compile docs and verify contents let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -1557,7 +1557,7 @@ class SemaToRenderNodeTests: XCTestCase { // Compile docs and verify contents let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -1595,7 +1595,7 @@ class SemaToRenderNodeTests: XCTestCase { XCTAssertTrue(problems.isEmpty) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(tutorial) as! RenderNode @@ -1707,19 +1707,19 @@ Document let document = Document(parsing: markupSource, options: []) let node = DocumentationNode(reference: ResolvedTopicReference(bundleID: "org.swift.docc", path: "/blah", sourceLanguage: .swift), kind: .article, sourceLanguage: .swift, name: .conceptual(title: "Title"), markup: document, semantic: Semantic()) - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + var translator = RenderNodeTranslator(context: context, identifier: node.reference) XCTAssertNotNil(translator.visit(MarkupContainer(document.children))) } func testCompileSymbolMetadata() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift)) // Compile docs and verify contents let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -1821,10 +1821,10 @@ Document try content.write(to: targetURL.appendingPathComponent("article2.md"), atomically: true, encoding: .utf8) - let (_, bundle, context) = try await loadBundle(from: targetURL) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Test-Bundle/article2", sourceLanguage: .swift)) + let (_, _, context) = try await loadBundle(from: targetURL) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/Test-Bundle/article2", sourceLanguage: .swift)) let article = node.semantic as! Article - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) return translator.visit(article) as! RenderNode } @@ -1948,7 +1948,7 @@ Document do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (_, context, reference) = try await makeTestBundle(currentPlatforms: [ "Custom Name": PlatformVersion(VersionTriplet(100, 0, 0), beta: true) ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) @@ -2109,22 +2109,22 @@ Document } func testRendersDeprecatedViolator() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") // Make the referenced symbol deprecated do { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) let node = try context.entity(with: reference) (node.semantic as? Symbol)?.availability = SymbolGraph.Symbol.Availability(availability: [ SymbolGraph.Symbol.Availability.AvailabilityItem(domain: .init(rawValue: "iOS"), introducedVersion: nil, deprecatedVersion: .init(major: 13, minor: 0, patch: 0), obsoletedVersion: nil, message: nil, renamed: nil, isUnconditionallyDeprecated: false, isUnconditionallyUnavailable: false, willEventuallyBeDeprecated: false), ]) } - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode // The reference is deprecated on all platforms @@ -2132,11 +2132,11 @@ Document } func testDoesNotRenderDeprecatedViolator() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") // Make the referenced symbol deprecated do { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) let node = try context.entity(with: reference) (node.semantic as? Symbol)?.availability = SymbolGraph.Symbol.Availability(availability: [ SymbolGraph.Symbol.Availability.AvailabilityItem(domain: .init(rawValue: "iOS"), introducedVersion: .init(major: 13, minor: 0, patch: 0), deprecatedVersion: nil, obsoletedVersion: nil, message: nil, renamed: nil, isUnconditionallyDeprecated: false, isUnconditionallyUnavailable: false, willEventuallyBeDeprecated: false), @@ -2144,11 +2144,11 @@ Document ]) } - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode // The reference is not deprecated on all platforms @@ -2156,11 +2156,11 @@ Document } func testRendersDeprecatedViolatorForUnconditionallyDeprecatedReference() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") // Make the referenced symbol deprecated do { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) let node = try context.entity(with: reference) (node.semantic as? Symbol)?.availability = SymbolGraph.Symbol.Availability(availability: [ SymbolGraph.Symbol.Availability.AvailabilityItem(domain: .init(rawValue: "iOS"), introducedVersion: .init(major: 13, minor: 0, patch: 0), deprecatedVersion: nil, obsoletedVersion: nil, message: nil, renamed: nil, isUnconditionallyDeprecated: true, isUnconditionallyUnavailable: false, willEventuallyBeDeprecated: false), @@ -2168,11 +2168,11 @@ Document ]) } - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode // Verify that the reference is deprecated on all platforms @@ -2180,13 +2180,12 @@ Document } func testRenderMetadataFragments() async throws { - // Check for fragments in metadata in render node - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode guard let fragments = renderNode.metadata.fragments else { @@ -2202,24 +2201,24 @@ Document } func testRenderMetadataExtendedModule() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) XCTAssertEqual(renderNode.metadata.extendedModule, "MyKit") } func testDefaultImplementations() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") // Verify that the render reference to a required symbol includes the 'required' key and the number of default implementations provided. do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideProtocol", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideProtocol", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode let requiredFuncReference = try XCTUnwrap(renderNode.references["doc://org.swift.docc.example/documentation/SideKit/SideProtocol/func()"]) @@ -2230,9 +2229,9 @@ Document // Verify that a required symbol includes a required metadata and default implementations do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideProtocol/func()", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideProtocol/func()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode // Verify that the render reference to a required symbol includes the 'required' key and the number of default implementations provided. @@ -2246,13 +2245,13 @@ Document } func testDefaultImplementationsNotListedInTopics() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") // Verify that a required symbol does not include default implementations in Topics groups do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideProtocol/func()", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideProtocol/func()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode // Test that default implementations are listed ONLY under Default Implementations and not Topics @@ -2262,13 +2261,12 @@ Document } func testNoStringMetadata() async throws { - // Check for fragments in metadata in render node - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode let encoded = try JSONEncoder().encode(renderNode) @@ -2291,13 +2289,12 @@ Document } func testRenderDeclarations() async throws { - // Check for fragments in metadata in render node - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -2312,11 +2309,11 @@ Document func testDocumentationRenderReferenceRoles() async throws { // Check for fragments in metadata in render node - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -2332,11 +2329,11 @@ Document func testTutorialsRenderReferenceRoles() async throws { // Check for fragments in metadata in render node - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/TestOverview", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/TestOverview", sourceLanguage: .swift)) let symbol = node.semantic as! TutorialTableOfContents - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -2351,9 +2348,9 @@ Document func testRemovingTrailingNewLinesInDeclaration() async throws { // Check for fragments in metadata in render node - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/globalFunction(_:considering:)", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/globalFunction(_:considering:)", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol // Subheading with trailing "\n" @@ -2362,7 +2359,7 @@ Document // Navigator title with trailing "\n" XCTAssertEqual(symbol.navigator?.count, 11) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode // Verify trailing newline removed from subheading @@ -2374,11 +2371,11 @@ Document func testRenderManualSeeAlsoInArticles() async throws { // Check for fragments in metadata in render node - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Test-Bundle/article", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/Test-Bundle/article", sourceLanguage: .swift)) let article = node.semantic as! Article - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(article) as! RenderNode @@ -2397,10 +2394,10 @@ Document func testSafeSectionAnchorNames() async throws { // Check that heading's anchor was safe-ified - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode @@ -2417,13 +2414,13 @@ Document } func testDuplicateNavigatorTitleIsRemoved() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/globalFunction(_:considering:)", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/globalFunction(_:considering:)", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) translator.collectedTopicReferences.append(myFuncReference) let renderNode = translator.visit(symbol) as! RenderNode @@ -2433,13 +2430,13 @@ Document } func testNonDuplicateNavigatorTitleIsRendered() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode let renderReference = try XCTUnwrap(renderNode.references[myFuncReference.absoluteString] as? TopicRenderReference) @@ -2476,7 +2473,7 @@ Document ] func testBareTechnology() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in try """ @Tutorials(name: "<#text#>") { @Intro(title: "<#text#>") { @@ -2492,7 +2489,7 @@ Document """.write(to: url.appendingPathComponent("TestOverview.tutorial"), atomically: true, encoding: .utf8) } - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/TestOverview", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/TestOverview", sourceLanguage: .swift)) guard let tutorialTableOfContentsDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, tutorial table-of-contents not found as first child.") @@ -2500,38 +2497,38 @@ Document } var problems = [Problem]() - guard let tutorialTableOfContents = TutorialTableOfContents(from: tutorialTableOfContentsDirective, source: nil, for: bundle, problems: &problems) else { + guard let tutorialTableOfContents = TutorialTableOfContents(from: tutorialTableOfContentsDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create tutorial from markup: \(problems)") return } XCTAssert(problems.filter { $0.diagnostic.severity == .error }.isEmpty, "Found errors when analyzing Tutorials overview.") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) // Verify we don't crash. _ = translator.visit(tutorialTableOfContents) do { - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) guard let technologyDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, tutorial not found as first child.") return } - guard let tutorial = Tutorial(from: technologyDirective, source: nil, for: bundle, problems: &problems) else { + guard let tutorial = Tutorial(from: technologyDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create tutorial from markup: \(problems)") return } - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) XCTAssertNil(translator.visit(tutorial), "Render node for uncurated tutorial should not have been produced") } } func testBareTutorial() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in try """ @Tutorial(time: <#number#>, projectFiles: <#.zip#>) { @Intro(title: "<#text#>") { @@ -2584,7 +2581,7 @@ Document """.write(to: url.appendingPathComponent("TestTutorial.tutorial"), atomically: true, encoding: .utf8) } - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) guard let technologyDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, tutorial not found as first child.") @@ -2592,14 +2589,14 @@ Document } var problems = [Problem]() - guard let tutorial = Tutorial(from: technologyDirective, source: nil, for: bundle, problems: &problems) else { + guard let tutorial = Tutorial(from: technologyDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create tutorial from markup: \(problems)") return } XCTAssert(problems.filter { $0.diagnostic.severity == .error }.isEmpty, "Found errors when analyzing tutorial.") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) // Verify we don't crash. _ = translator.visit(tutorial) @@ -2609,27 +2606,24 @@ Document func testRenderAsides() async throws { let asidesSGFURL = Bundle.module.url( forResource: "Asides.symbols", withExtension: "json", subdirectory: "Test Resources")! - let (bundleURL, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { url in try? FileManager.default.copyItem(at: asidesSGFURL, to: url.appendingPathComponent("Asides.symbols.json")) } - defer { - try? FileManager.default.removeItem(at: bundleURL) - } // Both of these symbols have the same content; one just has its asides as list items and the other has blockquotes. let testReference: (ResolvedTopicReference) throws -> () = { myFuncReference in let node = try context.entity(with: myFuncReference) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(symbol) as! RenderNode let asides = try XCTUnwrap(renderNode.primaryContentSections.first(where: { $0.kind == .content }) as? ContentRenderSection) XCTAssertEqual(Array(asides.content.dropFirst()), self.asidesStressTest) } - let dashReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Asides/dashAsides()", sourceLanguage: .swift) - let quoteReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Asides/quoteAsides()", sourceLanguage: .swift) + let dashReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/Asides/dashAsides()", sourceLanguage: .swift) + let quoteReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/Asides/quoteAsides()", sourceLanguage: .swift) try testReference(dashReference) try testReference(quoteReference) @@ -2654,20 +2648,20 @@ Document let sgURL = Bundle.module.url( forResource: "LegacyBundle_DoNotUseInNewTests.docc/sidekit.symbols", withExtension: "json", subdirectory: "Test Bundles")! - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in // Replace the out-of-bundle origin with a symbol from the same bundle. try String(contentsOf: sgURL) .replacingOccurrences(of: #"identifier" : "s:OriginalUSR"#, with: #"identifier" : "s:5MyKit0A5MyProtocol0Afunc()"#) .write(to: url.appendingPathComponent("sidekit.symbols.json"), atomically: true, encoding: .utf8) }) - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = try XCTUnwrap(node.semantic as? Symbol) // Verify that by default we inherit docs. do { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) // Verify the expected inherited abstract text. @@ -2680,7 +2674,7 @@ Document let sgURL = Bundle.module.url( forResource: "LegacyBundle_DoNotUseInNewTests.docc/sidekit.symbols", withExtension: "json", subdirectory: "Test Bundles")! - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in // Replace the out-of-bundle origin with a symbol from the same bundle but // from the MyKit module. try String(contentsOf: sgURL) @@ -2688,13 +2682,13 @@ Document .write(to: url.appendingPathComponent("sidekit.symbols.json"), atomically: true, encoding: .utf8) }) - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = try XCTUnwrap(node.semantic as? Symbol) // Verify that by default we inherit docs. do { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) // Verify the expected default abstract text. @@ -2703,7 +2697,7 @@ Document } /// Tests that we generated an automatic abstract and remove source docs. func testDisabledDocInheritance() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") // Verify that the inherited docs which should be ignored are not reference resolved. // Verify inherited docs are reference resolved and their problems are recorded. @@ -2714,13 +2708,13 @@ Document return p.diagnostic.summary == "Resource 'my-inherited-image.png' couldn't be found" })) - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = try XCTUnwrap(node.semantic as? Symbol) // Verify that by default we don't inherit docs and we generate default abstract. do { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) // Verify the expected default abstract text. @@ -2734,7 +2728,7 @@ Document /// Tests doc extensions are matched to inherited symbols func testInheritedSymbolDocExtension() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in try? """ # ``SideKit/SideClass/Element/inherited()`` Doc extension abstract. @@ -2743,13 +2737,13 @@ Document """.write(to: url.appendingPathComponent("inherited.md"), atomically: true, encoding: .utf8) }) - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = try XCTUnwrap(node.semantic as? Symbol) // Verify the doc extension was matched to the inherited symbol. do { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) // Verify the expected default abstract text. @@ -2877,7 +2871,7 @@ Document for testData in testData { let sgURL = Bundle.module.url(forResource: "LegacyBundle_DoNotUseInNewTests.docc/sidekit.symbols", withExtension: "json", subdirectory: "Test Bundles")! - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in // Replace the out-of-bundle origin with a symbol from the same bundle but // from the MyKit module. var graph = try JSONDecoder().decode(SymbolGraph.self, from: Data(contentsOf: sgURL)) @@ -2888,13 +2882,13 @@ Document .write(to: url.appendingPathComponent("sidekit.symbols.json")) }) - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = try XCTUnwrap(node.semantic as? Symbol) // Verify the doc extension was matched to the inherited symbol. do { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) // Verify the expected default abstract text. @@ -2911,20 +2905,20 @@ Document var configuration = DocumentationContext.Configuration() configuration.externalMetadata.inheritDocs = true - let (_, bundle, context) = try await loadBundle(from: bundleURL, configuration: configuration) + let (_, _, context) = try await loadBundle(from: bundleURL, configuration: configuration) // Verify that we don't reference resolve inherited docs. XCTAssertFalse(context.diagnosticEngine.problems.contains(where: { problem in problem.diagnostic.summary.contains("my-inherited-image.png") })) - let myFuncReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) + let myFuncReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass/Element/inherited()", sourceLanguage: .swift) let node = try context.entity(with: myFuncReference) let symbol = try XCTUnwrap(node.semantic as? Symbol) // Verify that by default we don't inherit docs and we generate default abstract. do { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) // Verify the expected default abstract text. @@ -2951,13 +2945,13 @@ Document // Verifies that undocumented symbol gets a nil abstract. func testNonDocumentedSymbolNilAbstract() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/globalFunction(_:considering:)", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/globalFunction(_:considering:)", sourceLanguage: .swift) let node = try context.entity(with: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) // Verify that an undocumented symbol gets a nil abstract. @@ -3059,7 +3053,7 @@ Document /// Tests links to symbols that have deprecation summary in markdown appear deprecated. func testLinkToDeprecatedSymbolViaDirectiveIsDeprecated() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in try """ # ``MyKit/MyProtocol`` @DeprecationSummary { @@ -3068,10 +3062,10 @@ Document """.write(to: url.appendingPathComponent("documentation").appendingPathComponent("myprotocol.md"), atomically: true, encoding: .utf8) }) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit", sourceLanguage: .swift)) let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode) let reference = try XCTUnwrap(renderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyProtocol"] as? TopicRenderReference) @@ -3079,7 +3073,7 @@ Document } func testCustomSymbolDisplayNames() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], externalResolvers: [:], externalSymbolResolver: nil, configureBundle: { url in try """ # ``MyKit`` @@ -3109,9 +3103,9 @@ Document """.write(to: url.appendingPathComponent("documentation").appendingPathComponent("myprotocol.md"), atomically: true, encoding: .utf8) }) - let moduleReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit", sourceLanguage: .swift) - let protocolReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift) - let functionReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) + let moduleReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit", sourceLanguage: .swift) + let protocolReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift) + let functionReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) // Verify the MyKit module @@ -3124,7 +3118,7 @@ Document XCTAssertEqual(titleVariant.variant, "My custom conceptual name") } - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: moduleNode.reference) + var translator = RenderNodeTranslator(context: context, identifier: moduleNode.reference) let moduleRenderNode = try XCTUnwrap(translator.visit(moduleSymbol) as? RenderNode) XCTAssertEqual(moduleRenderNode.metadata.title, "My custom conceptual name") @@ -3170,7 +3164,7 @@ Document let functionNode = try context.entity(with: functionReference) let functionSymbol = try XCTUnwrap(functionNode.semantic as? Symbol) - translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: functionNode.reference) + translator = RenderNodeTranslator(context: context, identifier: functionNode.reference) let functionRenderNode = try XCTUnwrap(translator.visit(functionSymbol) as? RenderNode) XCTAssertTrue(functionRenderNode.metadata.modulesVariants.variants.isEmpty) // Test that the symbol name `MyKit` is not added as a related module. @@ -3209,7 +3203,7 @@ Document } func testVisitTutorialMediaWithoutExtension() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in try """ @Tutorials(name: "Technology X") { @Intro(title: "Technology X") { @@ -3231,17 +3225,17 @@ Document } """.write(to: url.appendingPathComponent("TestOverview.tutorial"), atomically: true, encoding: .utf8) } - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/TestOverview", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/TestOverview", sourceLanguage: .swift)) guard let technologyDirective = node.markup as? BlockDirective else { XCTFail("Unexpected document structure, tutorial not found as first child.") return } var problems = [Problem]() - guard let tutorialTableOfContents = TutorialTableOfContents(from: technologyDirective, source: nil, for: bundle, problems: &problems) else { + guard let tutorialTableOfContents = TutorialTableOfContents(from: technologyDirective, source: nil, for: context.inputs, problems: &problems) else { XCTFail("Couldn't create technology from markup: \(problems)") return } - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(tutorialTableOfContents) as? RenderNode) XCTAssertEqual(renderNode.references.count, 5) XCTAssertNotNil(renderNode.references["doc://org.swift.docc.example/tutorials/Test-Bundle/TestTutorial"] as? TopicRenderReference) @@ -3255,7 +3249,7 @@ Document } func testTopicsSectionWithAnonymousTopicGroup() async throws { - let (_, bundle, context) = try await testBundleAndContext( + let (_, _, context) = try await testBundleAndContext( copying: "LegacyBundle_DoNotUseInNewTests", configureBundle: { url in try """ @@ -3276,14 +3270,14 @@ Document ) let moduleReference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/Test-Bundle/article", sourceLanguage: .swift ) let moduleNode = try context.entity(with: moduleReference) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: moduleNode.reference) + var translator = RenderNodeTranslator(context: context, identifier: moduleNode.reference) let moduleRenderNode = try XCTUnwrap(translator.visit(moduleNode.semantic) as? RenderNode) XCTAssertEqual( @@ -3319,18 +3313,17 @@ Document """), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) - let articleReference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/unit-test/Article", sourceLanguage: .swift ) let articleNode = try context.entity(with: articleReference) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleNode.reference) + var translator = RenderNodeTranslator(context: context, identifier: articleNode.reference) let articleRenderNode = try XCTUnwrap(translator.visit(articleNode.semantic) as? RenderNode) XCTAssertEqual( @@ -3475,7 +3468,7 @@ Document let contextConverter = DocumentationContextConverter( bundle: bundle, context: context, - renderContext: RenderContext(documentationContext: context, bundle: bundle) + renderContext: RenderContext(documentationContext: context) ) try assertExpectedTopicSections(XCTUnwrap(contextConverter.renderNode(for: documentationNode))) } diff --git a/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift b/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift index 0983c98de..3cad453d2 100644 --- a/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift +++ b/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift @@ -393,10 +393,7 @@ class OutOfProcessReferenceResolverV2Tests: XCTestCase { let converter = DocumentationContextConverter( bundle: context.inputs, context: context, - renderContext: RenderContext( - documentationContext: context, - bundle: context.inputs - ) + renderContext: RenderContext(documentationContext: context) ) let renderNode = try XCTUnwrap(converter.renderNode(for: context.entity(with: reference))) diff --git a/Tests/SwiftDocCTests/Rendering/AutomaticSeeAlsoTests.swift b/Tests/SwiftDocCTests/Rendering/AutomaticSeeAlsoTests.swift index 5ed6806cc..4c264ec3e 100644 --- a/Tests/SwiftDocCTests/Rendering/AutomaticSeeAlsoTests.swift +++ b/Tests/SwiftDocCTests/Rendering/AutomaticSeeAlsoTests.swift @@ -18,7 +18,7 @@ class AutomaticSeeAlsoTests: XCTestCase { /// Test that a symbol with no authored See Also and with no curated siblings /// does not have a See Also section. func testNoSeeAlso() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Extension that curates `SideClass` try """ # ``SideKit`` @@ -31,7 +31,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify there is no See Also @@ -41,7 +41,7 @@ class AutomaticSeeAlsoTests: XCTestCase { /// Test that a symbol with authored See Also and with no curated siblings /// does include an authored See Also section func testAuthoredSeeAlso() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Extension that curates `SideClass` try """ # ``SideKit`` @@ -62,7 +62,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify there is an authored See Also from markdown @@ -77,7 +77,7 @@ class AutomaticSeeAlsoTests: XCTestCase { /// Test that a symbol with authored See Also and with curated siblings /// does include both in See Also with authored section first func testAuthoredAndAutomaticSeeAlso() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Extension that curates `SideClass` try """ # ``SideKit`` @@ -105,7 +105,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify there is an authored See Also & automatically created See Also @@ -122,7 +122,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Verify that articles get same automatic See Also sections as symbols do { let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/Test-Bundle/sidearticle", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Article) as! RenderNode // Verify there is an automacially created See Also @@ -138,7 +138,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Duplicate of the `testAuthoredAndAutomaticSeeAlso()` test above // but with automatic see also creation disabled func testAuthoredSeeAlsoWithDisabledAutomaticSeeAlso() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit`` @@ -172,7 +172,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify there is an authored See Also but no automatically created See Also @@ -185,7 +185,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Verify that article without options directive still gets automatic See Also sections do { let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/Test-Bundle/sidearticle", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Article) as! RenderNode // Verify there is an automacially created See Also @@ -201,7 +201,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Duplicate of the `testAuthoredAndAutomaticSeeAlso()` test above // but with automatic see also creation globally disabled func testAuthoredSeeAlsoWithGloballyDisabledAutomaticSeeAlso() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { root in /// Article that curates `SideClass` try """ # ``SideKit`` @@ -236,7 +236,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify there is an authored See Also but no automatically created See Also @@ -249,7 +249,7 @@ class AutomaticSeeAlsoTests: XCTestCase { // Verify that article without options directive still gets automatic See Also sections do { let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/Test-Bundle/sidearticle", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Article) as! RenderNode // Verify there is an automacially created See Also @@ -283,11 +283,11 @@ class AutomaticSeeAlsoTests: XCTestCase { let tempURL = try createTemporaryDirectory() let bundleURL = try exampleDocumentation.write(inside: tempURL) - let (_, bundle, context) = try await loadBundle(from: bundleURL) + let (_, _, context) = try await loadBundle(from: bundleURL) // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "MyKit", path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify there is a See Also with the resolved tutorial reference diff --git a/Tests/SwiftDocCTests/Rendering/AvailabilityRenderOrderTests.swift b/Tests/SwiftDocCTests/Rendering/AvailabilityRenderOrderTests.swift index da55f59b4..f0a76bd05 100644 --- a/Tests/SwiftDocCTests/Rendering/AvailabilityRenderOrderTests.swift +++ b/Tests/SwiftDocCTests/Rendering/AvailabilityRenderOrderTests.swift @@ -18,7 +18,7 @@ class AvailabilityRenderOrderTests: XCTestCase { forResource: "Availability.symbols", withExtension: "json", subdirectory: "Test Resources")! func testSortingAtRenderTime() async throws { - let (bundleURL, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { url in let availabilitySymbolGraphURL = url.appendingPathComponent("Availability.symbols.json") try? FileManager.default.copyItem(at: self.availabilitySGFURL, to: availabilitySymbolGraphURL) @@ -61,13 +61,10 @@ class AvailabilityRenderOrderTests: XCTestCase { let data = try jsonEncoder.encode(availabilitySymbolGraph) try data.write(to: availabilitySymbolGraphURL) } - defer { - try? FileManager.default.removeItem(at: bundleURL) - } - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Availability/MyStruct", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/Availability/MyStruct", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode // Verify that all the symbol's availabilities were sorted into the order diff --git a/Tests/SwiftDocCTests/Rendering/ConstraintsRenderSectionTests.swift b/Tests/SwiftDocCTests/Rendering/ConstraintsRenderSectionTests.swift index cf83b6b49..7b67c5499 100644 --- a/Tests/SwiftDocCTests/Rendering/ConstraintsRenderSectionTests.swift +++ b/Tests/SwiftDocCTests/Rendering/ConstraintsRenderSectionTests.swift @@ -19,7 +19,7 @@ fileprivate let jsonEncoder = JSONEncoder() class ConstraintsRenderSectionTests: XCTestCase { func testSingleConstraint() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -40,16 +40,16 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode XCTAssertEqual(renderNode.metadata.conformance?.constraints.map(flattenInlineElements).joined(), "Label is Text.") } func testSingleRedundantConstraint() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -70,15 +70,15 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode XCTAssertNil(renderNode.metadata.conformance) } func testSingleRedundantConstraintForLeaves() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -99,15 +99,15 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode XCTAssertNil(renderNode.metadata.conformance) } func testPreservesNonRedundantConstraints() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -129,15 +129,15 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode XCTAssertEqual(renderNode.metadata.conformance?.constraints.map(flattenInlineElements).joined(), "Element is MyClass.") } func testGroups2Constraints() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -159,15 +159,15 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode XCTAssertEqual(renderNode.metadata.conformance?.constraints.map(flattenInlineElements).joined(), "Element conforms to MyProtocol and Equatable.") } func testGroups3Constraints() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -190,15 +190,15 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode XCTAssertEqual(renderNode.metadata.conformance?.constraints.map(flattenInlineElements).joined(), "Element conforms to MyProtocol, Equatable, and Hashable.") } func testRenderReferences() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -220,9 +220,9 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode guard let renderReference = renderNode.references.first(where: { (key, value) -> Bool in @@ -236,7 +236,7 @@ class ConstraintsRenderSectionTests: XCTestCase { } func testRenderReferencesWithNestedTypeInSelf() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { bundleURL in // Add constraints to `MyClass` let graphURL = bundleURL.appendingPathComponent("mykit-iOS.symbols.json") var graph = try jsonDecoder.decode(SymbolGraph.self, from: try Data(contentsOf: graphURL)) @@ -258,9 +258,9 @@ class ConstraintsRenderSectionTests: XCTestCase { } // Compile docs and verify contents - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)) let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visitSymbol(symbol) as! RenderNode guard let renderReference = renderNode.references.first(where: { (key, value) -> Bool in diff --git a/Tests/SwiftDocCTests/Rendering/DeclarationsRenderSectionTests.swift b/Tests/SwiftDocCTests/Rendering/DeclarationsRenderSectionTests.swift index 42c72aef0..7073b07c6 100644 --- a/Tests/SwiftDocCTests/Rendering/DeclarationsRenderSectionTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DeclarationsRenderSectionTests.swift @@ -134,9 +134,9 @@ class DeclarationsRenderSectionTests: XCTestCase { } func testAlternateDeclarations() async throws { - let (bundle, context) = try await testBundleAndContext(named: "AlternateDeclarations") + let (_, context) = try await testBundleAndContext(named: "AlternateDeclarations") let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/AlternateDeclarations/MyClass/present(completion:)", sourceLanguage: .swift ) @@ -152,7 +152,7 @@ class DeclarationsRenderSectionTests: XCTestCase { })) // Verify that the rendered symbol displays both signatures - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first) @@ -218,7 +218,7 @@ class DeclarationsRenderSectionTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first) XCTAssertEqual(declarationsSection.declarations.count, 2) @@ -265,7 +265,7 @@ class DeclarationsRenderSectionTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first) XCTAssertEqual(declarationsSection.declarations.count, 1) @@ -316,7 +316,7 @@ class DeclarationsRenderSectionTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first) XCTAssertEqual(declarationsSection.declarations.count, 1) @@ -371,7 +371,7 @@ class DeclarationsRenderSectionTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first) XCTAssertEqual(declarationsSection.declarations.count, 1) @@ -458,12 +458,12 @@ class DeclarationsRenderSectionTests: XCTestCase { JSONFile(name: "FancierOverloads.symbols.json", content: symbolGraph), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) func assertDeclarations(for USR: String, file: StaticString = #filePath, line: UInt = #line) throws { let reference = try XCTUnwrap(context.documentationCache.reference(symbolID: USR), file: file, line: line) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol, file: file, line: line) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode, file: file, line: line) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first, file: file, line: line) XCTAssertEqual(declarationsSection.declarations.count, 1, file: file, line: line) @@ -504,7 +504,7 @@ class DeclarationsRenderSectionTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first) XCTAssertEqual(declarationsSection.declarations.count, 1) @@ -539,7 +539,7 @@ class DeclarationsRenderSectionTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let declarationsSection = try XCTUnwrap(renderNode.primaryContentSections.compactMap({ $0 as? DeclarationsRenderSection }).first) XCTAssertEqual(declarationsSection.declarations.count, 1) diff --git a/Tests/SwiftDocCTests/Rendering/DefaultAvailabilityTests.swift b/Tests/SwiftDocCTests/Rendering/DefaultAvailabilityTests.swift index 597ecbd05..200fd3073 100644 --- a/Tests/SwiftDocCTests/Rendering/DefaultAvailabilityTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DefaultAvailabilityTests.swift @@ -73,7 +73,7 @@ class DefaultAvailabilityTests: XCTestCase { do { let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", fragment: nil, sourceLanguage: .swift) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual(renderNode.metadata.platforms?.map({ "\($0.name ?? "") \($0.introduced ?? "")" }).sorted(), expectedDefaultAvailability) @@ -83,7 +83,7 @@ class DefaultAvailabilityTests: XCTestCase { do { let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit/MyClass/init()-3743d", fragment: nil, sourceLanguage: .swift) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual(renderNode.metadata.platforms?.map({ "\($0.name ?? "") \($0.introduced ?? "")" }).sorted(), ["Mac Catalyst ", "iOS ", "iPadOS ", "macOS 10.15.1"]) @@ -93,7 +93,7 @@ class DefaultAvailabilityTests: XCTestCase { do { let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit/MyClass", fragment: nil, sourceLanguage: .swift) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertNotEqual(renderNode.metadata.platforms?.map({ "\($0.name ?? "") \($0.introduced ?? "")" }), expectedDefaultAvailability) @@ -131,14 +131,14 @@ class DefaultAvailabilityTests: XCTestCase { JSONFile(name: "MyKit.symbols.json", content: makeSymbolGraph(moduleName: "MyKit")), ]) - let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration) + let (_, context) = try await loadBundle(catalog: catalog, configuration: configuration) let reference = try XCTUnwrap(context.soleRootModuleReference, file: file, line: line) // Test whether we: // 1) Fallback on iOS when Mac Catalyst availability is missing // 2) Render [Beta] or not for Mac Catalyst's inherited iOS availability let node = try context.entity(with: reference) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual(renderNode.metadata.platforms?.map({ "\($0.name ?? "") \($0.introduced ?? "")\($0.isBeta == true ? "(beta)" : "")" }).sorted(), expected, file: (file), line: line) @@ -177,7 +177,7 @@ class DefaultAvailabilityTests: XCTestCase { // Set a beta status for the docs (which would normally be set via command line argument) configuration.externalMetadata.currentPlatforms = ["macOS": PlatformVersion(VersionTriplet(10, 16, 0), beta: true)] - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", configuration: configuration) { (url) in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", configuration: configuration) { (url) in // Copy an Info.plist with default availability of macOS 10.15.1 try? FileManager.default.removeItem(at: url.appendingPathComponent("Info.plist")) try? FileManager.default.copyItem(at: self.infoPlistAvailabilityURL, to: url.appendingPathComponent("Info.plist")) @@ -187,7 +187,7 @@ class DefaultAvailabilityTests: XCTestCase { do { let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", fragment: nil, sourceLanguage: .swift) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual(renderNode.metadata.platforms?.map({ "\($0.name ?? "") \($0.introduced ?? "")\($0.isBeta == true ? "(beta)" : "")" }).sorted(), [ @@ -202,7 +202,7 @@ class DefaultAvailabilityTests: XCTestCase { var configuration = DocumentationContext.Configuration() // Set a beta status for the docs (which would normally be set via command line argument) configuration.externalMetadata.currentPlatforms = ["iOS": PlatformVersion(VersionTriplet(14, 0, 0), beta: true)] - let (_, bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests", configuration: configuration) + let (_, _, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests", configuration: configuration) do { let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit/MyClass/myFunction()", fragment: nil, sourceLanguage: .swift) @@ -218,7 +218,7 @@ class DefaultAvailabilityTests: XCTestCase { SymbolGraph.Symbol.Availability.AvailabilityItem(domain: .init(rawValue: "macOS"), introducedVersion: nil, deprecatedVersion: nil, obsoletedVersion: nil, message: nil, renamed: nil, isUnconditionallyDeprecated: false, isUnconditionallyUnavailable: true, willEventuallyBeDeprecated: false), ]) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode // Verify that the 'watchOS' & 'tvOS' platforms are filtered out because the symbol is unavailable @@ -344,7 +344,7 @@ class DefaultAvailabilityTests: XCTestCase { // Compile docs and verify contents let symbol = node.semantic as! Symbol - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) guard let renderNode = translator.visit(symbol) as? RenderNode else { XCTFail("Could not compile the node") @@ -641,7 +641,7 @@ class DefaultAvailabilityTests: XCTestCase { // Don't use default availability version. - var (bundle, context) = try await setupContext( + var (_, context) = try await setupContext( defaultAvailability: """ name @@ -667,14 +667,14 @@ class DefaultAvailabilityTests: XCTestCase { // Verify we remove the version from the module availability information. var identifier = ResolvedTopicReference(bundleID: "test", path: "/documentation/MyModule", fragment: nil, sourceLanguage: .swift) var node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: identifier) + var translator = RenderNodeTranslator(context: context, identifier: identifier) var renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual(renderNode.metadata.platforms?.count, 1) XCTAssertEqual(renderNode.metadata.platforms?.first?.name, "iOS") XCTAssertEqual(renderNode.metadata.platforms?.first?.introduced, nil) // Add an extra default availability to test behaviour when mixin in source with default behaviour. - (bundle, context) = try await setupContext(defaultAvailability: """ + (_, context) = try await setupContext(defaultAvailability: """ name iOS @@ -710,7 +710,7 @@ class DefaultAvailabilityTests: XCTestCase { // Verify the module availability shows as expected. identifier = ResolvedTopicReference(bundleID: "test", path: "/documentation/MyModule", fragment: nil, sourceLanguage: .swift) node = try context.entity(with: identifier) - translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: identifier) + translator = RenderNodeTranslator(context: context, identifier: identifier) renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual(renderNode.metadata.platforms?.count, 4) var moduleAvailability = try XCTUnwrap(renderNode.metadata.platforms?.first(where: {$0.name == "iOS"})) diff --git a/Tests/SwiftDocCTests/Rendering/DeprecationSummaryTests.swift b/Tests/SwiftDocCTests/Rendering/DeprecationSummaryTests.swift index 9b6e4864f..68184ffba 100644 --- a/Tests/SwiftDocCTests/Rendering/DeprecationSummaryTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DeprecationSummaryTests.swift @@ -31,12 +31,12 @@ class DeprecationSummaryTests: XCTestCase { /// This test verifies that a symbol's deprecation summary comes from its sidecar doc /// and it's preferred over the original deprecation note in the code docs. func testAuthoredDeprecatedSummary() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/init()", sourceLanguage: .swift)) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass/init()", sourceLanguage: .swift)) // Compile docs and verify contents let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode, "Could not compile the node") XCTAssertEqual(renderNode.deprecationSummary?.firstParagraph, [.text("This initializer has been deprecated.")]) @@ -44,7 +44,7 @@ class DeprecationSummaryTests: XCTestCase { /// Test for a warning when symbol is not deprecated func testIncorrectlyAuthoredDeprecatedSummary() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], configureBundle: { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: [], configureBundle: { url in // Add a sidecar file with wrong deprecated summary try """ # ``SideKit/SideClass`` @@ -63,11 +63,11 @@ class DeprecationSummaryTests: XCTestCase { }) // Verify the deprecation is still rendered. - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) // Compile docs and verify contents let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode, "Could not compile the node") XCTAssertEqual(renderNode.deprecationSummary?.firstParagraph, [.text("This class has been deprecated.")]) @@ -91,7 +91,7 @@ class DeprecationSummaryTests: XCTestCase { // Compile docs and verify contents let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) guard let renderNode = translator.visit(symbol) as? RenderNode else { XCTFail("Could not compile the node") @@ -112,10 +112,10 @@ class DeprecationSummaryTests: XCTestCase { } func testSymbolDeprecatedSummary() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") + let (_, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") let node = try context.entity( with: ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/CoolFramework/CoolClass/doUncoolThings(with:)", sourceLanguage: .swift ) @@ -123,7 +123,7 @@ class DeprecationSummaryTests: XCTestCase { // Compile docs and verify contents let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode, "Could not compile the node") @@ -134,18 +134,18 @@ class DeprecationSummaryTests: XCTestCase { } func testDeprecationOverride() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") - let node = try context.entity( - with: ResolvedTopicReference( - bundleID: bundle.id, - path: "/documentation/CoolFramework/CoolClass/init()", - sourceLanguage: .swift - ) - ) - + let (_, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") + let node = try context.entity( + with: ResolvedTopicReference( + bundleID: context.inputs.id, + path: "/documentation/CoolFramework/CoolClass/init()", + sourceLanguage: .swift + ) + ) + // Compile docs and verify contents let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode, "Could not compile the node") @@ -163,10 +163,10 @@ class DeprecationSummaryTests: XCTestCase { } func testDeprecationSummaryInDiscussionSection() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") + let (_, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") let node = try context.entity( with: ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/CoolFramework/CoolClass/coolFunc()", sourceLanguage: .swift ) @@ -174,7 +174,7 @@ class DeprecationSummaryTests: XCTestCase { // Compile docs and verify contents let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode, "Could not compile the node") @@ -192,10 +192,10 @@ class DeprecationSummaryTests: XCTestCase { } func testDeprecationSummaryWithMultiLineCommentSymbol() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") + let (_, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") let node = try context.entity( with: ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/CoolFramework/CoolClass/init(config:cache:)", sourceLanguage: .swift ) @@ -203,7 +203,7 @@ class DeprecationSummaryTests: XCTestCase { // Compile docs and verify contents let symbol = try XCTUnwrap(node.semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(symbol) as? RenderNode, "Could not compile the node") diff --git a/Tests/SwiftDocCTests/Rendering/ExternalLinkTitleTests.swift b/Tests/SwiftDocCTests/Rendering/ExternalLinkTitleTests.swift index 704d56081..d533344d9 100644 --- a/Tests/SwiftDocCTests/Rendering/ExternalLinkTitleTests.swift +++ b/Tests/SwiftDocCTests/Rendering/ExternalLinkTitleTests.swift @@ -24,8 +24,8 @@ class ExternalLinkTitleTests: XCTestCase { semantic: Semantic()) - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let result = translator.visit(MarkupContainer(document.children)) as! [RenderBlockContent] return (translator, result) diff --git a/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift b/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift index 7565ed4c4..24d7b5762 100644 --- a/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift +++ b/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift @@ -38,7 +38,7 @@ class HeadingAnchorTests: XCTestCase { let reference = try XCTUnwrap(context.soleRootModuleReference) let node = try context.entity(with: reference) - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) let renderNode = try XCTUnwrap(converter.renderNode(for: node)) diff --git a/Tests/SwiftDocCTests/Rendering/MentionsRenderSectionTests.swift b/Tests/SwiftDocCTests/Rendering/MentionsRenderSectionTests.swift index 3f981b3ca..720ae88a4 100644 --- a/Tests/SwiftDocCTests/Rendering/MentionsRenderSectionTests.swift +++ b/Tests/SwiftDocCTests/Rendering/MentionsRenderSectionTests.swift @@ -17,19 +17,19 @@ class MentionsRenderSectionTests: XCTestCase { /// pointing to the correct article. func testMentionedInSectionFull() async throws { enableFeatureFlag(\.isMentionedInEnabled) - let (bundle, context) = try await createMentionedInTestBundle() + let (_, context) = try await createMentionedInTestBundle() let identifier = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/MentionedIn/MyClass", sourceLanguage: .swift ) let mentioningArticle = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/MentionedIn/ArticleMentioningSymbol", sourceLanguage: .swift ) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode let mentionsSection = try XCTUnwrap(renderNode.primaryContentSections.mapFirst { $0 as? MentionsRenderSection }) XCTAssertEqual(1, mentionsSection.mentions.count) @@ -40,14 +40,14 @@ class MentionsRenderSectionTests: XCTestCase { /// If there are no qualifying mentions of a symbol, the Mentioned In section should not appear. func testMentionedInSectionEmpty() async throws { enableFeatureFlag(\.isMentionedInEnabled) - let (bundle, context) = try await createMentionedInTestBundle() + let (_, context) = try await createMentionedInTestBundle() let identifier = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/MentionedIn/MyClass/myFunction()", sourceLanguage: .swift ) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode let mentionsSection = renderNode.primaryContentSections.mapFirst { $0 as? MentionsRenderSection } XCTAssertNil(mentionsSection) diff --git a/Tests/SwiftDocCTests/Rendering/PageKindTests.swift b/Tests/SwiftDocCTests/Rendering/PageKindTests.swift index 2f8c794c8..ac9add76f 100644 --- a/Tests/SwiftDocCTests/Rendering/PageKindTests.swift +++ b/Tests/SwiftDocCTests/Rendering/PageKindTests.swift @@ -23,7 +23,7 @@ class PageKindTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) return try XCTUnwrap(translator.visitArticle(article) as? RenderNode) } diff --git a/Tests/SwiftDocCTests/Rendering/PlatformAvailabilityTests.swift b/Tests/SwiftDocCTests/Rendering/PlatformAvailabilityTests.swift index 59e48df45..f013c1e4f 100644 --- a/Tests/SwiftDocCTests/Rendering/PlatformAvailabilityTests.swift +++ b/Tests/SwiftDocCTests/Rendering/PlatformAvailabilityTests.swift @@ -41,7 +41,7 @@ class PlatformAvailabilityTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 1) @@ -60,7 +60,7 @@ class PlatformAvailabilityTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 1) @@ -78,7 +78,7 @@ class PlatformAvailabilityTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 3) @@ -106,7 +106,7 @@ class PlatformAvailabilityTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 2) @@ -132,7 +132,7 @@ class PlatformAvailabilityTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 5) @@ -164,14 +164,14 @@ class PlatformAvailabilityTests: XCTestCase { let platformMetadata = [ "iOS": PlatformVersion(VersionTriplet(16, 0, 0), beta: true), ] - let (bundle, context) = try await testBundleWithConfiguredPlatforms(named: "AvailabilityBundle", platformMetadata: platformMetadata) + let (_, context) = try await testBundleWithConfiguredPlatforms(named: "AvailabilityBundle", platformMetadata: platformMetadata) let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/AvailableArticle", sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 1) @@ -187,14 +187,14 @@ class PlatformAvailabilityTests: XCTestCase { "macOS": PlatformVersion(VersionTriplet(12, 0, 0), beta: true), "watchOS": PlatformVersion(VersionTriplet(7, 0, 0), beta: true), ] - let (bundle, context) = try await testBundleWithConfiguredPlatforms(named: "AvailabilityBundle", platformMetadata: platformMetadata) + let (_, context) = try await testBundleWithConfiguredPlatforms(named: "AvailabilityBundle", platformMetadata: platformMetadata) let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/AvailabilityBundle/ComplexAvailable", sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 3) @@ -219,14 +219,14 @@ class PlatformAvailabilityTests: XCTestCase { let platformMetadata = [ "iOS": PlatformVersion(VersionTriplet(16, 0, 0), beta: true), ] - let (bundle, context) = try await testBundleWithConfiguredPlatforms(named: "AvailabilityBundle", platformMetadata: platformMetadata) + let (_, context) = try await testBundleWithConfiguredPlatforms(named: "AvailabilityBundle", platformMetadata: platformMetadata) let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let availability = try XCTUnwrap(renderNode.metadata.platformsVariants.defaultValue) XCTAssertEqual(availability.count, 1) diff --git a/Tests/SwiftDocCTests/Rendering/RESTSymbolsTests.swift b/Tests/SwiftDocCTests/Rendering/RESTSymbolsTests.swift index 8bb0b2c91..9de46ea5c 100644 --- a/Tests/SwiftDocCTests/Rendering/RESTSymbolsTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RESTSymbolsTests.swift @@ -330,10 +330,10 @@ class RESTSymbolsTests: XCTestCase { )), ] + extraFiles ) - let (bundle, context) = try await loadBundle(catalog: catalog) - let moduleReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleName", sourceLanguage: .swift) + let (_, context) = try await loadBundle(catalog: catalog) + let moduleReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleName", sourceLanguage: .swift) let moduleSymbol = try XCTUnwrap((try context.entity(with: moduleReference)).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: moduleReference) + var translator = RenderNodeTranslator(context: context, identifier: moduleReference) let renderNode = translator.visit(moduleSymbol) as! RenderNode return try XCTUnwrap((renderNode.references["doc://unit-test/documentation/ModuleName/plist-key-symbolname"] as? TopicRenderReference)) } @@ -425,6 +425,4 @@ class RESTSymbolsTests: XCTestCase { XCTAssertEqual(propertyListKeyNames.rawKey, "plist-key-symbolname") XCTAssertEqual(propertyListKeyNames.displayName, nil) } - - } diff --git a/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift b/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift index d07e2e629..58136785d 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift @@ -75,7 +75,7 @@ class RenderMetadataTests: XCTestCase { for bundleName in ["LegacyBundle_DoNotUseInNewTests"] { let (bundle, context) = try await testBundleAndContext(named: bundleName) - let renderContext = RenderContext(documentationContext: context, bundle: bundle) + let renderContext = RenderContext(documentationContext: context) let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) for identifier in context.knownPages { let entity = try context.entity(with: identifier) @@ -119,7 +119,7 @@ class RenderMetadataTests: XCTestCase { func testRendersBystanderExtensionsFromSymbolGraph() async throws { throw XCTSkip("Fails in CI. rdar://159615046") - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [:]) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [:]) { url in let baseSymbolGraphURL = Bundle.module.url( forResource: "BaseKit.symbols", withExtension: "json", subdirectory: "Test Resources")! try FileManager.default.copyItem(at: baseSymbolGraphURL, to: url.appendingPathComponent("BaseKit.symbols.json")) @@ -129,7 +129,7 @@ class RenderMetadataTests: XCTestCase { } // Verify the symbol from bystanders graph is present in the documentation context. - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/BaseKit/OtherStruct/someFunc()", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/BaseKit/OtherStruct/someFunc()", sourceLanguage: .swift) let entity = try XCTUnwrap(try? context.entity(with: reference)) let symbol = try XCTUnwrap(entity.semantic as? Symbol) @@ -137,14 +137,14 @@ class RenderMetadataTests: XCTestCase { XCTAssertEqual(symbol.crossImportOverlayModule?.bystanderModules, ["BaseKit"]) // Verify the rendered metadata contains the bystanders - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(bundle: context.inputs, context: context) let renderNode = converter.convert(entity) XCTAssertEqual(renderNode.metadata.modules?.first?.name, "OverlayTest") XCTAssertEqual(renderNode.metadata.modules?.first?.relatedModules, ["BaseKit"]) } func testRendersExtensionSymbolsWithBystanderModules() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "BundleWithRelativePathAmbiguity") { root in + let (_, _, context) = try await testBundleAndContext(copying: "BundleWithRelativePathAmbiguity") { root in // We don't want the external target to be part of the archive as that is not // officially supported yet. try FileManager.default.removeItem(at: root.appendingPathComponent("Dependency.symbols.json")) @@ -152,7 +152,7 @@ class RenderMetadataTests: XCTestCase { // Get a translated render node let node = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/BundleWithRelativePathAmbiguity/Dependency/AmbiguousType", sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode XCTAssertEqual(renderNode.metadata.modules?.first?.name, "BundleWithRelativePathAmbiguity") XCTAssertEqual(renderNode.metadata.modules?.first?.relatedModules, ["Dependency"]) diff --git a/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift b/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift index 31504330f..2e2ec2bd6 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift @@ -1167,10 +1167,10 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase { assertAfterApplyingVariant: (RenderNode) throws -> () = { _ in }, assertDataAfterApplyingVariant: (Data) throws -> () = { _ in } ) async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: bundleName) + let (_, _, context) = try await testBundleAndContext(copying: bundleName) let identifier = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift ) @@ -1187,7 +1187,6 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase { try assertMultiLanguageSemantic( symbol, context: context, - bundle: bundle, identifier: identifier, configureRenderNodeTranslator: configureRenderNodeTranslator, assertOriginalRenderNode: assertOriginalRenderNode, @@ -1204,10 +1203,10 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase { assertAfterApplyingVariant: (RenderNode) throws -> () = { _ in }, assertDataAfterApplyingVariant: (Data) throws -> () = { _ in } ) async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") let identifier = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/Test-Bundle/article", sourceLanguage: .swift ) @@ -1224,7 +1223,6 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase { try assertMultiLanguageSemantic( article, context: context, - bundle: bundle, identifier: identifier, assertOriginalRenderNode: assertOriginalRenderNode, assertAfterApplyingVariant: assertAfterApplyingVariant, @@ -1235,14 +1233,13 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase { private func assertMultiLanguageSemantic( _ semantic: Semantic, context: DocumentationContext, - bundle: DocumentationBundle, identifier: ResolvedTopicReference, configureRenderNodeTranslator: (inout RenderNodeTranslator) -> () = { _ in }, assertOriginalRenderNode: (RenderNode) throws -> (), assertAfterApplyingVariant: (RenderNode) throws -> (), assertDataAfterApplyingVariant: (Data) throws -> () = { _ in } ) throws { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: identifier) + var translator = RenderNodeTranslator(context: context, identifier: identifier) configureRenderNodeTranslator(&translator) diff --git a/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorTests.swift b/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorTests.swift index c2fe00d4f..aba174200 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorTests.swift @@ -21,7 +21,7 @@ class RenderNodeTranslatorTests: XCTestCase { let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: forSymbolPath, sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode guard let section = renderNode.primaryContentSections.last(where: { section -> Bool in @@ -294,7 +294,7 @@ class RenderNodeTranslatorTests: XCTestCase { let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Test-Bundle/article", sourceLanguage: .swift) let node = try context.entity(with: reference) let article = try XCTUnwrap(node.semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderedNode = translator.visit(article) as! RenderNode // Verify that the render reference to a section includes the container symbol's abstract @@ -346,7 +346,7 @@ class RenderNodeTranslatorTests: XCTestCase { let topicGraphNode = TopicGraph.Node(reference: reference, kind: .article, source: .file(url: URL(fileURLWithPath: "/path/to/article.md")), title: "My Article") 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.topicSections.count, 2) @@ -376,7 +376,7 @@ class RenderNodeTranslatorTests: XCTestCase { }) let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let node = try XCTUnwrap(try? context.entity(with: reference)) // Test manual task groups and automatic symbol groups ordering @@ -503,7 +503,7 @@ class RenderNodeTranslatorTests: XCTestCase { }) let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Test-Bundle/article", sourceLanguage: .swift) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let node = try XCTUnwrap(try? context.entity(with: reference)) // Test the manual curation task groups @@ -606,7 +606,7 @@ class RenderNodeTranslatorTests: XCTestCase { // Verify "Default Implementations" group on the implementing type do { let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element", sourceLanguage: .swift) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let node = try XCTUnwrap(try? context.entity(with: reference)) let symbol = try XCTUnwrap(node.semantic as? Symbol) @@ -625,7 +625,7 @@ class RenderNodeTranslatorTests: XCTestCase { // Verify automatically generated api collection do { let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass/Element/Protocol-Implementations", sourceLanguage: .swift) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let node = try XCTUnwrap(try? context.entity(with: reference)) let article = try XCTUnwrap(node.semantic as? Article) @@ -654,7 +654,7 @@ class RenderNodeTranslatorTests: XCTestCase { } let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/FancyProtocol/SomeClass", sourceLanguage: .swift) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let node = try context.entity(with: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) @@ -857,7 +857,7 @@ class RenderNodeTranslatorTests: XCTestCase { let (_, bundle, context) = try await loadBundle(from: bundleURL) let reference = ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguage: .swift) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let node = try context.entity(with: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) return try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) @@ -871,7 +871,7 @@ class RenderNodeTranslatorTests: XCTestCase { // Verify that the ordering of default implementations is deterministic for _ in 0..<100 { - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: structReference) + var translator = RenderNodeTranslator(context: context, identifier: structReference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let section = renderNode.topicSections.first(where: { $0.title == "Default Implementations" }) XCTAssertEqual(section?.identifiers, [ @@ -900,7 +900,7 @@ class RenderNodeTranslatorTests: XCTestCase { }) let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let node = try XCTUnwrap(try? context.entity(with: reference)) let symbol = try XCTUnwrap(node.semantic as? Symbol) @@ -930,7 +930,7 @@ class RenderNodeTranslatorTests: XCTestCase { let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit", sourceLanguage: .swift) let node = try context.entity(with: reference) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) @@ -950,7 +950,7 @@ class RenderNodeTranslatorTests: XCTestCase { let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit", sourceLanguage: .swift) let node = try context.entity(with: reference) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let symbol = try XCTUnwrap(node.semantic as? Symbol) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) @@ -963,7 +963,7 @@ class RenderNodeTranslatorTests: XCTestCase { let (bundle, context) = try await testBundleAndContext(named: "Snippets") let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Snippets/Snippets", sourceLanguage: .swift) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let discussion = try XCTUnwrap(renderNode.primaryContentSections.first(where: { $0.kind == .content }) as? ContentRenderSection) @@ -993,7 +993,7 @@ class RenderNodeTranslatorTests: XCTestCase { let (bundle, context) = try await testBundleAndContext(named: "Snippets") let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Snippets/Snippets", sourceLanguage: .swift) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let discussion = try XCTUnwrap(renderNode.primaryContentSections.first(where: { $0.kind == .content }) as? ContentRenderSection) @@ -1017,7 +1017,7 @@ class RenderNodeTranslatorTests: XCTestCase { let (bundle, context) = try await testBundleAndContext(named: "Snippets") let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Snippets/Snippets", sourceLanguage: .swift) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let discussion = try XCTUnwrap(renderNode.primaryContentSections.first(where: { $0.kind == .content }) as? ContentRenderSection) @@ -1048,7 +1048,7 @@ class RenderNodeTranslatorTests: XCTestCase { let (bundle, context) = try await testBundleAndContext(named: "Snippets") let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/Snippets/SliceIndentation", sourceLanguage: .swift) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let discussion = try XCTUnwrap(renderNode.primaryContentSections.first(where: { $0.kind == .content }) as? ContentRenderSection) @@ -1077,7 +1077,7 @@ class RenderNodeTranslatorTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let discussion = try XCTUnwrap( @@ -1106,7 +1106,7 @@ class RenderNodeTranslatorTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let discussion = try XCTUnwrap( @@ -1134,7 +1134,7 @@ class RenderNodeTranslatorTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let discussion = try XCTUnwrap( @@ -1171,7 +1171,7 @@ class RenderNodeTranslatorTests: XCTestCase { sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitArticle(article) as? RenderNode) let encodedArticle = try JSONEncoder().encode(renderNode) @@ -1247,7 +1247,7 @@ class RenderNodeTranslatorTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let encodedSymbol = try JSONEncoder().encode(renderNode) @@ -1263,7 +1263,7 @@ class RenderNodeTranslatorTests: XCTestCase { sourceLanguage: .swift ) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) let encodedSymbol = try JSONEncoder().encode(renderNode) @@ -1341,7 +1341,7 @@ class RenderNodeTranslatorTests: XCTestCase { ) throws -> RenderNode { let reference = ResolvedTopicReference(bundleID: bundle.id, path: referencePath, sourceLanguage: .swift) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) return try XCTUnwrap(translator.visitArticle(symbol) as? RenderNode) } @@ -1433,7 +1433,7 @@ class RenderNodeTranslatorTests: XCTestCase { ) throws -> RenderNode { let reference = ResolvedTopicReference(bundleID: bundle.id, path: referencePath, sourceLanguage: .swift) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) return try XCTUnwrap(translator.visitArticle(symbol) as? RenderNode) } @@ -1461,7 +1461,7 @@ class RenderNodeTranslatorTests: XCTestCase { func testEncodesOverloadsInRenderNode() async throws { enableFeatureFlag(\.isExperimentalOverloadedSymbolPresentationEnabled) - let (bundle, context) = try await testBundleAndContext(named: "OverloadedSymbols") + let (_, context) = try await testBundleAndContext(named: "OverloadedSymbols") let overloadPreciseIdentifiers = ["s:8ShapeKit14OverloadedEnumO19firstTestMemberNameySdSiF", "s:8ShapeKit14OverloadedEnumO19firstTestMemberNameySdSfF", @@ -1474,7 +1474,7 @@ class RenderNodeTranslatorTests: XCTestCase { for (index, reference) in overloadReferences.indexed() { let documentationNode = try context.entity(with: reference) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let symbol = try XCTUnwrap(documentationNode.semantic as? Symbol) let renderNode = try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) @@ -1497,7 +1497,7 @@ class RenderNodeTranslatorTests: XCTestCase { } func testAlternateRepresentationsRenderedAsVariants() async throws { - let (bundle, context) = try await loadBundle(catalog: Folder( + let (_, context) = try await loadBundle(catalog: Folder( name: "unit-test.docc", content: [ TextFile(name: "Symbol.md", utf8Content: """ @@ -1547,9 +1547,9 @@ class RenderNodeTranslatorTests: XCTestCase { func renderNodeArticleFromReferencePath( referencePath: String ) throws -> RenderNode { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: referencePath, sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: referencePath, sourceLanguage: .swift) let symbol = try XCTUnwrap(context.entity(with: reference).semantic as? Symbol) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) return try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) } diff --git a/Tests/SwiftDocCTests/Rendering/RoleTests.swift b/Tests/SwiftDocCTests/Rendering/RoleTests.swift index f05fe42e1..c944b9cb3 100644 --- a/Tests/SwiftDocCTests/Rendering/RoleTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RoleTests.swift @@ -25,14 +25,14 @@ class RoleTests: XCTestCase { ] func testNodeRoles() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") // Compile docs and verify contents for (path, expectedRole) in expectedRoles { let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: path, fragment: nil, sourceLanguage: .swift) do { let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual(expectedRole, renderNode.metadata.role, "Unexpected role \(renderNode.metadata.role!.singleQuoted) for identifier \(identifier.path)") } catch { @@ -43,11 +43,11 @@ class RoleTests: XCTestCase { } func testDocumentationRenderReferenceRoles() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", fragment: nil, sourceLanguage: .swift) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit"] as? TopicRenderReference)?.role, "collection") @@ -56,11 +56,11 @@ class RoleTests: XCTestCase { } func testTutorialsRenderReferenceRoles() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") let identifier = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorial", fragment: nil, sourceLanguage: .swift) let node = try context.entity(with: identifier) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = translator.visit(node.semantic) as! RenderNode XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/tutorials/TestOverview"] as? TopicRenderReference)?.role, "overview") diff --git a/Tests/SwiftDocCTests/Rendering/SampleDownloadTests.swift b/Tests/SwiftDocCTests/Rendering/SampleDownloadTests.swift index 39b7ab7d6..62089827e 100644 --- a/Tests/SwiftDocCTests/Rendering/SampleDownloadTests.swift +++ b/Tests/SwiftDocCTests/Rendering/SampleDownloadTests.swift @@ -126,14 +126,14 @@ class SampleDownloadTests: XCTestCase { } private func renderNodeFromSampleBundle(at referencePath: String) async throws -> RenderNode { - let (bundle, context) = try await testBundleAndContext(named: "SampleBundle") + let (_, context) = try await testBundleAndContext(named: "SampleBundle") let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: referencePath, sourceLanguage: .swift ) let article = try XCTUnwrap(context.entity(with: reference).semantic as? Article) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) return try XCTUnwrap(translator.visitArticle(article) as? RenderNode) } diff --git a/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift b/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift index 239d35223..c3ea5e5ab 100644 --- a/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift +++ b/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift @@ -37,10 +37,10 @@ class SymbolAvailabilityTests: XCTestCase { )), ] ) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) let reference = try XCTUnwrap(context.soleRootModuleReference).appendingPath(symbolName) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: reference.path, sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: reference.path, sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) return try XCTUnwrap((translator.visit(node.semantic as! Symbol) as! RenderNode).metadata.platformsVariants.defaultValue) } diff --git a/Tests/SwiftDocCTests/Semantics/DoxygenTests.swift b/Tests/SwiftDocCTests/Semantics/DoxygenTests.swift index bd62af73f..100ad050b 100644 --- a/Tests/SwiftDocCTests/Semantics/DoxygenTests.swift +++ b/Tests/SwiftDocCTests/Semantics/DoxygenTests.swift @@ -88,8 +88,8 @@ class DoxygenTests: XCTestCase { )), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/ModuleName/SomeClass", sourceLanguage: .swift) + let (_, context) = try await loadBundle(catalog: catalog) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/ModuleName/SomeClass", sourceLanguage: .swift) // Verify the expected content in the in-memory model let node = try context.entity(with: reference) @@ -103,7 +103,7 @@ class DoxygenTests: XCTestCase { ]) // Verify the expected content in the render model - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) let renderNode = try XCTUnwrap(translator.visit(node.semantic) as? RenderNode) XCTAssertEqual(renderNode.abstract, [.text("This is an abstract.")]) diff --git a/Tests/SwiftDocCTests/Semantics/VideoMediaTests.swift b/Tests/SwiftDocCTests/Semantics/VideoMediaTests.swift index 010fb3125..3fb78b144 100644 --- a/Tests/SwiftDocCTests/Semantics/VideoMediaTests.swift +++ b/Tests/SwiftDocCTests/Semantics/VideoMediaTests.swift @@ -326,19 +326,19 @@ class VideoMediaTests: XCTestCase { """ let document = Document(parsing: source, options: .parseBlockDirectives) let directive = document.child(at: 0)! as! BlockDirective - let (bundle, context) = try await loadBundle( + let (_, context) = try await loadBundle( catalog: Folder(name: "unit-test.docc", content: [ DataFile(name: "introvideo.mov", data: Data()) ]) ) var problems = [Problem]() - let video = VideoMedia(from: directive, source: nil, for: bundle, problems: &problems) + let video = VideoMedia(from: directive, source: nil, for: context.inputs, problems: &problems) let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "", sourceLanguage: .swift ) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference) + var translator = RenderNodeTranslator(context: context, identifier: reference) let videoMediaReference = translator.visitVideoMedia(video!) as! RenderReferenceIdentifier let videoMedia = translator.videoReferences[videoMediaReference.identifier] // Check that the video references in the node translator contains the alt text. diff --git a/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift b/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift index 0ae2ec07a..3d3f508fe 100644 --- a/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift +++ b/Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift @@ -131,9 +131,9 @@ extension XCTestCase { } func renderNode(atPath path: String, fromTestBundleNamed testBundleName: String) async throws -> RenderNode { - let (bundle, context) = try await testBundleAndContext(named: testBundleName) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguage: .swift)) - var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference) + let (_, context) = try await testBundleAndContext(named: testBundleName) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: path, sourceLanguage: .swift)) + var translator = RenderNodeTranslator(context: context, identifier: node.reference) return try XCTUnwrap(translator.visit(node.semantic) as? RenderNode) } From 9d0839303c27a6820e917f673e41e495ab826e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 12:02:48 +0200 Subject: [PATCH 09/19] Remove redundant "bundle" parameter from DocumentationNodeConverter --- .../DocumentationNodeConverter.swift | 15 ++-- .../DocumentationContextConverterTests.swift | 6 +- .../TopicRenderReferenceEncoderTests.swift | 10 +-- .../Indexing/NavigatorIndexTests.swift | 8 +- .../Infrastructure/AnchorSectionTests.swift | 30 +++---- .../DocumentationContextTests.swift | 13 ++-- .../DocumentationCuratorTests.swift | 18 ++--- .../ExternalPathHierarchyResolverTests.swift | 6 +- .../ExternalReferenceResolverTests.swift | 60 +++++++------- .../Infrastructure/SnippetResolverTests.swift | 2 +- .../LinkDestinationSummaryTests.swift | 30 +++---- ...opertyListPossibleValuesSectionTests.swift | 12 +-- .../SemaToRenderNodeMultiLanguageTests.swift | 4 +- .../Model/SemaToRenderNodeTests.swift | 78 +++++++++---------- .../DefaultCodeListingSyntaxTests.swift | 2 +- ...ropertyListDetailsRenderSectionTests.swift | 4 +- .../Rendering/RenderMetadataTests.swift | 8 +- ...derNodeTranslatorSymbolVariantsTests.swift | 4 +- .../Rendering/TermListTests.swift | 6 +- .../Utility/ListItemExtractorTests.swift | 13 ++-- .../ConvertActionIndexerTests.swift | 10 +-- 21 files changed, 167 insertions(+), 172 deletions(-) diff --git a/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift b/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift index be69ef9e1..51c19137b 100644 --- a/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift +++ b/Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift @@ -15,20 +15,19 @@ public struct DocumentationNodeConverter { /// The context the converter uses to resolve references it finds in the documentation node's content. let context: DocumentationContext - /// The bundle that contains the content from which the documentation node originated. - let bundle: DocumentationBundle - - /// Creates a new node converter for the given bundle and context. + /// Creates a new node converter for the given context. /// - /// The converter uses bundle and context to resolve references to other documentation and describe the documentation hierarchy. + /// The converter uses context to resolve references to other documentation and describe the documentation hierarchy. /// /// - Parameters: - /// - bundle: The bundle that contains the content from which the documentation node originated. /// - context: The context that the converter uses to to resolve references it finds in the documentation node's content. - public init(bundle: DocumentationBundle, context: DocumentationContext) { - self.bundle = bundle + public init(context: DocumentationContext) { self.context = context } + @available(*, deprecated, renamed: "init(context:)", message: "Use 'init(context:)' instead. This deprecated API will be removed after 6.4 is released.") + public init(bundle _: DocumentationBundle, context: DocumentationContext) { + self.init(context: context) + } /// Converts a documentation node to a render node. /// diff --git a/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift b/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift index 96e96a4f7..10ebec954 100644 --- a/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift +++ b/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift @@ -14,14 +14,14 @@ import XCTest class DocumentationContextConverterTests: XCTestCase { func testRenderNodesAreIdentical() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") // We'll use this to convert nodes ad-hoc - let perNodeConverter = DocumentationNodeConverter(bundle: bundle, context: context) + let perNodeConverter = DocumentationNodeConverter(context: context) // We'll use these to convert nodes in bulk let renderContext = RenderContext(documentationContext: context) - let bulkNodeConverter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let bulkNodeConverter = DocumentationContextConverter(bundle: context.inputs, context: context, renderContext: renderContext) let encoder = JSONEncoder() for identifier in context.knownPages { diff --git a/Tests/SwiftDocCTests/Converter/TopicRenderReferenceEncoderTests.swift b/Tests/SwiftDocCTests/Converter/TopicRenderReferenceEncoderTests.swift index c3014f198..0686fe324 100644 --- a/Tests/SwiftDocCTests/Converter/TopicRenderReferenceEncoderTests.swift +++ b/Tests/SwiftDocCTests/Converter/TopicRenderReferenceEncoderTests.swift @@ -156,10 +156,10 @@ class TopicRenderReferenceEncoderTests: XCTestCase { } /// Verifies that when JSON encoder should sort keys, the custom render reference cache - /// respects that setting and prints the referencs in alphabetical order. + /// respects that setting and prints the reference in alphabetical order. func testSortedReferences() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let converter = DocumentationNodeConverter(context: context) // Create a JSON encoder let encoder = RenderJSONEncoder.makeEncoder() @@ -218,8 +218,8 @@ class TopicRenderReferenceEncoderTests: XCTestCase { // Verifies that there is no extra comma at the end of the references list. func testRemovesLastReferencesListDelimiter() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let converter = DocumentationNodeConverter(context: context) // Create a JSON encoder let encoder = RenderJSONEncoder.makeEncoder() diff --git a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift index c0042f0b8..5d5cb4a4b 100644 --- a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift +++ b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift @@ -1004,8 +1004,8 @@ Root } func testNavigatorIndexGenerationNoPaths() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let converter = DocumentationNodeConverter(context: context) var results = Set() // Create an index 10 times to ensure we have not non-deterministic behavior across builds @@ -1723,8 +1723,8 @@ Root } func testNavigatorIndexAsReadOnlyFile() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let converter = DocumentationNodeConverter(context: context) let targetURL = try createTemporaryDirectory() let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: "org.swift.docc.test", sortRootChildrenByName: true) diff --git a/Tests/SwiftDocCTests/Infrastructure/AnchorSectionTests.swift b/Tests/SwiftDocCTests/Infrastructure/AnchorSectionTests.swift index 968cca594..ff67afb93 100644 --- a/Tests/SwiftDocCTests/Infrastructure/AnchorSectionTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/AnchorSectionTests.swift @@ -17,19 +17,19 @@ import Markdown class AnchorSectionTests: XCTestCase { func testResolvingArticleSubsections() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") + let (_, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") // Verify the sub-sections of the article have been collected in the context [ - ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TechnologyX/Article", fragment: "Article-Sub-Section", sourceLanguage: .swift), - ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TechnologyX/Article", fragment: "Article-Sub-Sub-Section", sourceLanguage: .swift), + ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TechnologyX/Article", fragment: "Article-Sub-Section", sourceLanguage: .swift), + ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TechnologyX/Article", fragment: "Article-Sub-Sub-Section", sourceLanguage: .swift), ] .forEach { sectionReference in XCTAssertTrue(context.nodeAnchorSections.keys.contains(sectionReference)) } // Load the module page - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/CoolFramework", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/CoolFramework", sourceLanguage: .swift) let entity = try context.entity(with: reference) // Extract the links from the discussion @@ -66,7 +66,7 @@ class AnchorSectionTests: XCTestCase { } // Verify collecting section render references - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) let sectionReference = try XCTUnwrap(renderNode.references["doc://org.swift.docc.example/documentation/TechnologyX/Article#Article-Sub-Section"] as? TopicRenderReference) @@ -75,19 +75,19 @@ class AnchorSectionTests: XCTestCase { } func testResolvingSymbolSubsections() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") + let (_, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") // Verify the sub-sections of the article have been collected in the context [ - ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/CoolFramework/CoolClass", fragment: "Symbol-Sub-Section", sourceLanguage: .swift), - ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/CoolFramework/CoolClass", fragment: "Symbol-Sub-Sub-Section", sourceLanguage: .swift), + ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/CoolFramework/CoolClass", fragment: "Symbol-Sub-Section", sourceLanguage: .swift), + ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/CoolFramework/CoolClass", fragment: "Symbol-Sub-Sub-Section", sourceLanguage: .swift), ] .forEach { sectionReference in XCTAssertTrue(context.nodeAnchorSections.keys.contains(sectionReference)) } // Load the module page - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/CoolFramework", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/CoolFramework", sourceLanguage: .swift) let entity = try context.entity(with: reference) // Extract the links from the discussion @@ -124,7 +124,7 @@ class AnchorSectionTests: XCTestCase { } // Verify collecting section render references - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) let sectionReference = try XCTUnwrap(renderNode.references["doc://org.swift.docc.example/documentation/CoolFramework/CoolClass#Symbol-Sub-Section"] as? TopicRenderReference) @@ -133,19 +133,19 @@ class AnchorSectionTests: XCTestCase { } func testResolvingRootPageSubsections() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") + let (_, context) = try await testBundleAndContext(named: "BundleWithLonelyDeprecationDirective") // Verify the sub-sections of the article have been collected in the context [ - ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/CoolFramework", fragment: "Module-Sub-Section", sourceLanguage: .swift), - ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/CoolFramework", fragment: "Module-Sub-Sub-Section", sourceLanguage: .swift), + ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/CoolFramework", fragment: "Module-Sub-Section", sourceLanguage: .swift), + ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/CoolFramework", fragment: "Module-Sub-Sub-Section", sourceLanguage: .swift), ] .forEach { sectionReference in XCTAssertTrue(context.nodeAnchorSections.keys.contains(sectionReference)) } // Load the article page - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TechnologyX/Article", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TechnologyX/Article", sourceLanguage: .swift) let entity = try context.entity(with: reference) // Extract the links from the discussion @@ -182,7 +182,7 @@ class AnchorSectionTests: XCTestCase { } // Verify collecting section render references - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) let sectionReference = try XCTUnwrap(renderNode.references["doc://org.swift.docc.example/documentation/CoolFramework#Module-Sub-Section"] as? TopicRenderReference) diff --git a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift index 6777edfa1..9d3328fc3 100644 --- a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift @@ -3286,8 +3286,7 @@ let expected = """ ]) // Verify that the links are resolved in the render model. - let bundle = try XCTUnwrap(context.inputs) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) XCTAssertEqual(renderNode.topicSections.map(\.anchor), [ @@ -5480,7 +5479,7 @@ let expected = """ let externalModuleName = "ExternalModuleName" func makeExternalDependencyFiles() async throws -> (SerializableLinkResolutionInformation, [LinkDestinationSummary]) { - let (bundle, context) = try await loadBundle( + let (_, context) = try await loadBundle( catalog: Folder(name: "Dependency.docc", content: [ JSONFile(name: "\(externalModuleName).symbols.json", content: makeSymbolGraph(moduleName: externalModuleName)), TextFile(name: "Extension.md", utf8Content: """ @@ -5492,14 +5491,14 @@ let expected = """ ) // Retrieve the link information from the dependency, as if '--enable-experimental-external-link-support' was passed to DocC - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let linkSummaries: [LinkDestinationSummary] = try context.knownPages.flatMap { reference in let entity = try context.entity(with: reference) let renderNode = try XCTUnwrap(converter.convert(entity)) return entity.externallyLinkableElementSummaries(context: context, renderNode: renderNode, includeTaskGroups: false) } - let linkResolutionInformation = try context.linkResolver.localResolver.prepareForSerialization(bundleID: bundle.id) + let linkResolutionInformation = try context.linkResolver.localResolver.prepareForSerialization(bundleID: context.inputs.id) return (linkResolutionInformation, linkSummaries) } @@ -5521,7 +5520,7 @@ let expected = """ URL(fileURLWithPath: "/path/to/SomeDependency.doccarchive") ] - let (bundle, context) = try await loadBundle( + let (_, context) = try await loadBundle( catalog: catalog, otherFileSystemDirectories: [ Folder(name: "path", content: [ @@ -5540,7 +5539,7 @@ let expected = """ let reference = try XCTUnwrap(context.soleRootModuleReference) let node = try context.entity(with: reference) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(node) let externalReference = "doc://Dependency/documentation/ExternalModuleName" diff --git a/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift b/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift index 84321b58f..125b3ff2c 100644 --- a/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift @@ -228,7 +228,7 @@ class DocumentationCuratorTests: XCTestCase { - ``NotFound`` """), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) XCTAssertEqual( context.problems.map(\.diagnostic.summary), [ @@ -266,7 +266,7 @@ class DocumentationCuratorTests: XCTestCase { ) // Verify that the rendered top-level page doesn't have an automatic "Classes" topic section anymore. - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let moduleReference = try XCTUnwrap(context.soleRootModuleReference) let rootRenderNode = converter.convert(try context.entity(with: moduleReference)) @@ -319,7 +319,7 @@ class DocumentationCuratorTests: XCTestCase { } func testCuratorDoesNotRelateNodesWhenArticleLinksContainExtraPathComponents() async throws { - let (bundle, context) = try await loadBundle(catalog: + let (_, context) = try await loadBundle(catalog: Folder(name: "CatalogName.docc", content: [ TextFile(name: "Root.md", utf8Content: """ # Root @@ -395,7 +395,7 @@ class DocumentationCuratorTests: XCTestCase { ]) let rootPage = try context.entity(with: rootReference) - let renderer = DocumentationNodeConverter(bundle: bundle, context: context) + let renderer = DocumentationNodeConverter(context: context) let renderNode = renderer.convert(rootPage) XCTAssertEqual(renderNode.topicSections.map(\.title), [ @@ -661,16 +661,16 @@ class DocumentationCuratorTests: XCTestCase { /// +-- MyArticle ( <--- This should be crawled even if we've mixed manual and automatic curation) /// ``` func testMixedManualAndAutomaticCuration() async throws { - let (bundle, context) = try await testBundleAndContext(named: "MixedManualAutomaticCuration") + let (_, context) = try await testBundleAndContext(named: "MixedManualAutomaticCuration") - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TestBed/TopClass/NestedEnum/SecondLevelNesting", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TestBed/TopClass/NestedEnum/SecondLevelNesting", sourceLanguage: .swift) let entity = try context.entity(with: reference) let symbol = try XCTUnwrap(entity.semantic as? Symbol) // Verify the link was resolved and it's found in the node's topics task group. XCTAssertEqual("doc://com.test.TestBed/documentation/TestBed/MyArticle", symbol.topics?.taskGroups.first?.links.first?.destination) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) // Verify the article identifier is included in the task group for the render node. @@ -678,7 +678,7 @@ class DocumentationCuratorTests: XCTestCase { // Verify that the ONLY curation for `TopClass/name` is the manual curation under `MyArticle` // and the automatic curation under `TopClass` is not present. - let nameReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TestBed/TopClass/name", sourceLanguage: .swift) + let nameReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TestBed/TopClass/name", sourceLanguage: .swift) XCTAssertEqual(context.finitePaths(to: nameReference).map({ $0.map(\.path) }), [ ["/documentation/TestBed", "/documentation/TestBed/TopClass", "/documentation/TestBed/TopClass-API-Collection"], ["/documentation/TestBed", "/documentation/TestBed/TopClass", "/documentation/TestBed/TopClass/NestedEnum", "/documentation/TestBed/TopClass/NestedEnum/SecondLevelNesting", "/documentation/TestBed/MyArticle"], @@ -686,7 +686,7 @@ class DocumentationCuratorTests: XCTestCase { // Verify that the BOTH manual curations for `TopClass/age` are preserved // even if one of the manual curations overlaps with the inheritance edge from the symbol graph. - let ageReference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/TestBed/TopClass/age", sourceLanguage: .swift) + let ageReference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/TestBed/TopClass/age", sourceLanguage: .swift) XCTAssertEqual(context.finitePaths(to: ageReference).map({ $0.map(\.path) }), [ ["/documentation/TestBed", "/documentation/TestBed/TopClass"], ["/documentation/TestBed", "/documentation/TestBed/TopClass", "/documentation/TestBed/TopClass-API-Collection"], diff --git a/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift index 96b97bc0e..600235cbc 100644 --- a/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift @@ -991,16 +991,16 @@ class ExternalPathHierarchyResolverTests: XCTestCase { private func makeLinkResolversForTestBundle(named testBundleName: String, configuration: DocumentationContext.Configuration = .init()) async throws -> LinkResolvers { let bundleURL = try XCTUnwrap(Bundle.module.url(forResource: testBundleName, withExtension: "docc", subdirectory: "Test Bundles")) - let (_, bundle, context) = try await loadBundle(from: bundleURL, configuration: configuration) + let (_, _, context) = try await loadBundle(from: bundleURL, configuration: configuration) let localResolver = try XCTUnwrap(context.linkResolver.localResolver) - let resolverInfo = try localResolver.prepareForSerialization(bundleID: bundle.id) + let resolverInfo = try localResolver.prepareForSerialization(bundleID: context.inputs.id) let resolverData = try JSONEncoder().encode(resolverInfo) let roundtripResolverInfo = try JSONDecoder().decode(SerializableLinkResolutionInformation.self, from: resolverData) var entitySummaries = [LinkDestinationSummary]() - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) for reference in context.knownPages { let node = try context.entity(with: reference) let renderNode = converter.convert(node) diff --git a/Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift index 84cb5e7a1..803868d2a 100644 --- a/Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift @@ -90,7 +90,7 @@ class ExternalReferenceResolverTests: XCTestCase { // Set the language of the externally resolved entity to 'data'. externalResolver.resolvedEntityLanguage = .data - let (_, bundle, context) = try await testBundleAndContext( + let (_, _, context) = try await testBundleAndContext( copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver] ) { url in @@ -112,9 +112,9 @@ class ExternalReferenceResolverTests: XCTestCase { try sideClassExtension.write(to: sideClassExtensionURL, atomically: true, encoding: .utf8) } - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let sideClassReference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift ) @@ -179,10 +179,10 @@ class ExternalReferenceResolverTests: XCTestCase { externalResolver.resolvedEntityTitle = "ClassName" externalResolver.resolvedEntityKind = resolvedEntityKind - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)) guard let fileURL = context.documentURL(for: node.reference) else { XCTFail("Unable to find the file for \(node.reference.path)") @@ -221,7 +221,7 @@ class ExternalReferenceResolverTests: XCTestCase { .init(kind: .identifier, spelling: "ClassName", preciseIdentifier: nil), ]) - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in try """ # ``SideKit/SideClass`` @@ -235,8 +235,8 @@ class ExternalReferenceResolverTests: XCTestCase { """.write(to: url.appendingPathComponent("documentation/sideclass.md"), atomically: true, encoding: .utf8) } - let converter = DocumentationNodeConverter(bundle: bundle, context: context) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) let renderNode = converter.convert(node) @@ -278,10 +278,10 @@ class ExternalReferenceResolverTests: XCTestCase { var configuration = DocumentationContext.Configuration() configuration.externalDocumentationConfiguration.sources = [externalResolver.bundleID: externalResolver] - let (bundle, context) = try await loadBundle(catalog: tempFolder, configuration: configuration) + let (_, context) = try await loadBundle(catalog: tempFolder, configuration: configuration) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/article", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/article", sourceLanguage: .swift)) let renderNode = converter.convert(node) @@ -313,7 +313,7 @@ class ExternalReferenceResolverTests: XCTestCase { externalResolver.resolvedEntityTitle = "Name of Sample" externalResolver.resolvedEntityKind = .sampleCode - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in try """ # ``SideKit/SideClass`` @@ -327,8 +327,8 @@ class ExternalReferenceResolverTests: XCTestCase { """.write(to: url.appendingPathComponent("documentation/sideclass.md"), atomically: true, encoding: .utf8) } - let converter = DocumentationNodeConverter(bundle: bundle, context: context) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SideKit/SideClass", sourceLanguage: .swift)) let renderNode = converter.convert(node) @@ -401,7 +401,7 @@ class ExternalReferenceResolverTests: XCTestCase { ), ] - let (_, bundle, context) = try await testBundleAndContext(copying: "SampleBundle", excludingPaths: ["MySample.md", "MyLocalSample.md"], externalResolvers: [externalResolver.bundleID: externalResolver]) { url in + let (_, _, context) = try await testBundleAndContext(copying: "SampleBundle", excludingPaths: ["MySample.md", "MyLocalSample.md"], externalResolvers: [externalResolver.bundleID: externalResolver]) { url in try """ # SomeSample @@ -426,8 +426,8 @@ class ExternalReferenceResolverTests: XCTestCase { """.write(to: url.appendingPathComponent("SomeSample.md"), atomically: true, encoding: .utf8) } - let converter = DocumentationNodeConverter(bundle: bundle, context: context) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SomeSample", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/SomeSample", sourceLanguage: .swift)) let renderNode = converter.convert(node) @@ -641,7 +641,7 @@ class ExternalReferenceResolverTests: XCTestCase { // Copy the test bundle and add external links to the MyKit See Also. // We're using a See Also group, because external links aren't rendered in Topics groups. - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: ["com.external.testbundle" : resolver]) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: ["com.external.testbundle" : resolver]) { url in try """ # ``MyKit`` MyKit module root symbol @@ -693,8 +693,8 @@ class ExternalReferenceResolverTests: XCTestCase { "The external reference resolver error message is included in that problem's error summary.") // Get MyKit symbol - let entity = try context.entity(with: .init(bundleID: bundle.id, path: "/documentation/MyKit", sourceLanguage: .swift)) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let entity = try context.entity(with: .init(bundleID: context.inputs.id, path: "/documentation/MyKit", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) let taskGroupLinks = try XCTUnwrap(renderNode.seeAlsoSections.first?.identifiers) @@ -794,7 +794,7 @@ class ExternalReferenceResolverTests: XCTestCase { ) ) - let (_, bundle, context) = try await testBundleAndContext( + let (_, _, context) = try await testBundleAndContext( copying: "MixedLanguageFramework", externalResolvers: [externalResolver.bundleID: externalResolver] ) { url in @@ -814,9 +814,9 @@ class ExternalReferenceResolverTests: XCTestCase { """ try mixedLanguageFrameworkExtension.write(to: url.appendingPathComponent("/MixedLanguageFramework.md"), atomically: true, encoding: .utf8) } - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let mixedLanguageFrameworkReference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: "/documentation/MixedLanguageFramework", sourceLanguage: .swift ) @@ -945,7 +945,7 @@ class ExternalReferenceResolverTests: XCTestCase { var configuration = DocumentationContext.Configuration() configuration.externalDocumentationConfiguration.sources = [resolver.bundleID: resolver] - let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration) + let (_, context) = try await loadBundle(catalog: catalog, configuration: configuration) XCTAssert(context.problems.isEmpty, "Unexpected problems: \(context.problems.map(\.diagnostic.summary))") @@ -961,10 +961,10 @@ class ExternalReferenceResolverTests: XCTestCase { ]) // Check the rendered SeeAlso sections for the two curated articles. - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) do { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/unit-test/First", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/unit-test/First", sourceLanguage: .swift) let node = try context.entity(with: reference) let rendered = converter.convert(node) @@ -978,7 +978,7 @@ class ExternalReferenceResolverTests: XCTestCase { } do { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/unit-test/Second", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/unit-test/Second", sourceLanguage: .swift) let node = try context.entity(with: reference) let rendered = converter.convert(node) @@ -1013,7 +1013,7 @@ class ExternalReferenceResolverTests: XCTestCase { var configuration = DocumentationContext.Configuration() configuration.externalDocumentationConfiguration.sources = [resolver.bundleID: resolver] - let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration) + let (_, context) = try await loadBundle(catalog: catalog, configuration: configuration) XCTAssert(context.problems.isEmpty, "Unexpected problems: \(context.problems.map(\.diagnostic.summary))") @@ -1021,7 +1021,7 @@ class ExternalReferenceResolverTests: XCTestCase { // Check the curation on the root page let reference = try XCTUnwrap(context.soleRootModuleReference) let node = try context.entity(with: reference) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let rendered = converter.convert(node) XCTAssertEqual(rendered.seeAlsoSections.count, 1, "The page should only have the authored See Also section.") diff --git a/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift index ddff13df6..84e39551d 100644 --- a/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/SnippetResolverTests.swift @@ -235,7 +235,7 @@ class SnippetResolverTests: XCTestCase { let reference = try XCTUnwrap(context.soleRootModuleReference, file: file, line: line) let moduleNode = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: context.inputs, context: context).convert(moduleNode) + let renderNode = DocumentationNodeConverter(context: context).convert(moduleNode) let renderBlocks = try XCTUnwrap(renderNode.primaryContentSections.first as? ContentRenderSection, file: file, line: line).content diff --git a/Tests/SwiftDocCTests/LinkTargets/LinkDestinationSummaryTests.swift b/Tests/SwiftDocCTests/LinkTargets/LinkDestinationSummaryTests.swift index 560695810..5ac4655d9 100644 --- a/Tests/SwiftDocCTests/LinkTargets/LinkDestinationSummaryTests.swift +++ b/Tests/SwiftDocCTests/LinkTargets/LinkDestinationSummaryTests.swift @@ -90,11 +90,11 @@ class LinkDestinationSummaryTests: XCTestCase { InfoPlist(displayName: "TestBundle", identifier: "com.test.example") ]) - let (bundle, context) = try await loadBundle(catalog: catalogHierarchy) + let (_, context) = try await loadBundle(catalog: catalogHierarchy) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/TestBundle/Tutorial", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/TestBundle/Tutorial", sourceLanguage: .swift)) let renderNode = converter.convert(node) let summaries = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode) @@ -151,8 +151,8 @@ class LinkDestinationSummaryTests: XCTestCase { } func testSymbolSummaries() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let converter = DocumentationNodeConverter(context: context) do { let symbolReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit/MyClass", sourceLanguage: .swift) let node = try context.entity(with: symbolReference) @@ -334,7 +334,7 @@ class LinkDestinationSummaryTests: XCTestCase { } func testTopicImageReferences() async throws { - let (url, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in + let (url, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in let extensionFile = """ # ``MyKit/MyClass/myFunction()`` @@ -349,7 +349,7 @@ class LinkDestinationSummaryTests: XCTestCase { let fileURL = url.appendingPathComponent("documentation").appendingPathComponent("myFunction.md") try extensionFile.write(to: fileURL, atomically: true, encoding: .utf8) } - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) do { let symbolReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift) @@ -438,24 +438,24 @@ class LinkDestinationSummaryTests: XCTestCase { summary.references = summary.references?.compactMap { (original: RenderReference) -> (any RenderReference)? in guard var imageRef = original as? ImageReference else { return nil } imageRef.asset.variants = imageRef.asset.variants.mapValues { variant in - return imageRef.destinationURL(for: variant.lastPathComponent, prefixComponent: bundle.id.rawValue) + return imageRef.destinationURL(for: variant.lastPathComponent, prefixComponent: context.inputs.id.rawValue) } imageRef.asset.metadata = .init(uniqueKeysWithValues: imageRef.asset.metadata.map { key, value in - return (imageRef.destinationURL(for: key.lastPathComponent, prefixComponent: bundle.id.rawValue), value) + return (imageRef.destinationURL(for: key.lastPathComponent, prefixComponent: context.inputs.id.rawValue), value) }) return imageRef as (any RenderReference) } - let encoded = try RenderJSONEncoder.makeEncoder(assetPrefixComponent: bundle.id.rawValue).encode(summary) + let encoded = try RenderJSONEncoder.makeEncoder(assetPrefixComponent: context.inputs.id.rawValue).encode(summary) let decoded = try JSONDecoder().decode(LinkDestinationSummary.self, from: encoded) XCTAssertEqual(decoded, summary) } } func testVariantSummaries() async throws { - let (bundle, context) = try await testBundleAndContext(named: "MixedLanguageFramework") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, context) = try await testBundleAndContext(named: "MixedLanguageFramework") + let converter = DocumentationNodeConverter(context: context) // Check a symbol that's represented as a class in both Swift and Objective-C do { @@ -801,11 +801,11 @@ class LinkDestinationSummaryTests: XCTestCase { JSONFile(name: "MyModule.symbols.json", content: symbolGraph), InfoPlist(displayName: "MyModule", identifier: "com.example.mymodule") ]) - let (bundle, context) = try await loadBundle(catalog: catalogHierarchy) + let (_, context) = try await loadBundle(catalog: catalogHierarchy) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyModule/MyClass/myFunc()", sourceLanguage: .swift)) + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyModule/MyClass/myFunc()", sourceLanguage: .swift)) let renderNode = converter.convert(node) let summaries = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode) diff --git a/Tests/SwiftDocCTests/Model/PropertyListPossibleValuesSectionTests.swift b/Tests/SwiftDocCTests/Model/PropertyListPossibleValuesSectionTests.swift index 4547e14f4..2a5ddab8b 100644 --- a/Tests/SwiftDocCTests/Model/PropertyListPossibleValuesSectionTests.swift +++ b/Tests/SwiftDocCTests/Model/PropertyListPossibleValuesSectionTests.swift @@ -82,18 +82,18 @@ class PropertyListPossibleValuesSectionTests: XCTestCase { } func testAbsenceOfPossibleValues() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "DictionaryData") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/DictionaryData/Artist", sourceLanguage: .swift)) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, _, context) = try await testBundleAndContext(copying: "DictionaryData") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/DictionaryData/Artist", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) // Check that the `Possible Values` section is not rendered if the symbol don't define any possible value. XCTAssertNil(converter.convert(node).primaryContentSections.first(where: { $0.kind == .possibleValues}) as? PossibleValuesRenderSection) } func testUndocumentedPossibleValues() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "DictionaryData") - let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/DictionaryData/Month", sourceLanguage: .swift)) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let (_, _, context) = try await testBundleAndContext(copying: "DictionaryData") + let node = try context.entity(with: ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/DictionaryData/Month", sourceLanguage: .swift)) + let converter = DocumentationNodeConverter(context: context) let possibleValuesSection = try XCTUnwrap(converter.convert(node).primaryContentSections.first(where: { $0.kind == .possibleValues}) as? PossibleValuesRenderSection) let possibleValues: [PossibleValuesRenderSection.NamedValue] = possibleValuesSection.values diff --git a/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift b/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift index 3f158d550..ed560e458 100644 --- a/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift +++ b/Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift @@ -962,7 +962,7 @@ class SemaToRenderNodeMixedLanguageTests: XCTestCase { } func testAutomaticSeeAlsoSectionElementLimit() async throws { - let (bundle, context) = try await loadBundle(catalog: + let (_, context) = try await loadBundle(catalog: Folder(name: "unit-test.docc", content: [ JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(moduleName: "ModuleName", symbols: (1...50).map { makeSymbol(id: "symbol-id-\($0)", kind: .class, pathComponents: ["SymbolName\($0)"]) @@ -984,7 +984,7 @@ class SemaToRenderNodeMixedLanguageTests: XCTestCase { XCTAssert(context.problems.isEmpty, "Unexpected problems: \(context.problems.map(\.diagnostic.summary))") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let moduleReference = try XCTUnwrap(context.soleRootModuleReference) let moduleNode = try converter.convert(context.entity(with: moduleReference)) diff --git a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift index bbcd73619..fb0aae328 100644 --- a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift +++ b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift @@ -1918,7 +1918,7 @@ Document } func testRendersBetaViolators() async throws { - func makeTestBundle(currentPlatforms: [String : PlatformVersion]?, file: StaticString = #filePath, line: UInt = #line, referencePath: String) async throws -> (DocumentationBundle, DocumentationContext, ResolvedTopicReference) { + func makeTestBundle(currentPlatforms: [String : PlatformVersion]?, file: StaticString = #filePath, line: UInt = #line, referencePath: String) async throws -> (DocumentationContext, ResolvedTopicReference) { var configuration = DocumentationContext.Configuration() // Add missing platforms if their fallback platform is present. var currentPlatforms = currentPlatforms ?? [:] @@ -1927,18 +1927,18 @@ Document } configuration.externalMetadata.currentPlatforms = currentPlatforms - let (_, bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests", configuration: configuration) + let (_, _, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests", configuration: configuration) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: referencePath, sourceLanguage: .swift) - return (bundle, context, reference) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: referencePath, sourceLanguage: .swift) + return (context, reference) } // Not a beta platform do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: nil, referencePath: "/documentation/MyKit/globalFunction(_:considering:)") + let (context, reference) = try await makeTestBundle(currentPlatforms: nil, referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: bundle, context: context).convert(node) + let renderNode = DocumentationNodeConverter(context: context).convert(node) // Verify platform beta was plumbed all the way to the render JSON XCTAssertEqual(renderNode.metadata.platforms?.first?.isBeta, false) @@ -1948,7 +1948,7 @@ Document do { - let (_, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "Custom Name": PlatformVersion(VersionTriplet(100, 0, 0), beta: true) ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) @@ -1961,12 +1961,12 @@ Document // Different platform is beta do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "tvOS": PlatformVersion(VersionTriplet(100, 0, 0), beta: true) ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: bundle, context: context).convert(node) + let renderNode = DocumentationNodeConverter(context: context).convert(node) // Verify platform beta was plumbed all the way to the render JSON XCTAssertEqual(renderNode.metadata.platforms?.first?.isBeta, false) @@ -1975,12 +1975,12 @@ Document // Beta platform but *not* matching the introduced version do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "macOS": PlatformVersion(VersionTriplet(100, 0, 0), beta: true) ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: bundle, context: context).convert(node) + let renderNode = DocumentationNodeConverter(context: context).convert(node) // Verify platform beta was plumbed all the way to the render JSON XCTAssertEqual(renderNode.metadata.platforms?.first?.isBeta, false) @@ -1989,12 +1989,12 @@ Document // Beta platform matching the introduced version do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true) ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: bundle, context: context).convert(node) + let renderNode = DocumentationNodeConverter(context: context).convert(node) // Verify platform beta was plumbed all the way to the render JSON XCTAssertEqual(renderNode.metadata.platforms?.first(where: { $0.name == "macOS"})?.isBeta, true) @@ -2003,12 +2003,12 @@ Document // Beta platform earlier than the introduced version do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "macOS": PlatformVersion(VersionTriplet(10, 14, 0), beta: true) ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: bundle, context: context).convert(node) + let renderNode = DocumentationNodeConverter(context: context).convert(node) // Verify platform beta was plumbed all the way to the render JSON XCTAssertEqual(renderNode.metadata.platforms?.first(where: { $0.name == "macOS" })?.isBeta, true) @@ -2017,14 +2017,14 @@ Document // Set only some platforms to beta & the exact version globalFunction is being introduced at do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true), "watchOS": PlatformVersion(VersionTriplet(9, 0, 0), beta: true), "tvOS": PlatformVersion(VersionTriplet(1, 0, 0), beta: true), ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = DocumentationNodeConverter(bundle: bundle, context: context).convert(node) + let renderNode = DocumentationNodeConverter(context: context).convert(node) // Verify task group link is not in beta betas "iOS" is not being marked as beta XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, false) @@ -2032,7 +2032,7 @@ Document // Set all platforms to beta & the exact version globalFunction is being introduced at to test beta SDK documentation do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true), "watchOS": PlatformVersion(VersionTriplet(6, 0, 0), beta: true), "tvOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true), @@ -2040,7 +2040,7 @@ Document ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node)) + let renderNode = try XCTUnwrap(DocumentationNodeConverter(context: context).convert(node)) // Verify task group link is beta XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, true) @@ -2048,7 +2048,7 @@ Document // Set all platforms to beta where the symbol is available, // some platforms not beta but the symbol is not available there. - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true), "watchOS": PlatformVersion(VersionTriplet(6, 0, 0), beta: true), "tvOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true), @@ -2058,7 +2058,7 @@ Document ], referencePath: "/documentation/MyKit/globalFunction(_:considering:)") let node = try context.entity(with: reference) - let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node)) + let renderNode = try XCTUnwrap(DocumentationNodeConverter(context: context).convert(node)) // Verify task group link is beta XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, true) @@ -2071,16 +2071,16 @@ Document renderReferenceSymbol.availability?.availability.append(SymbolGraph.Symbol.Availability.AvailabilityItem(domain: SymbolGraph.Symbol.Availability.Domain(rawValue: "ImaginaryOS"), introducedVersion: nil, deprecatedVersion: nil, obsoletedVersion: nil, message: nil, renamed: nil, isUnconditionallyDeprecated: false, isUnconditionallyUnavailable: true, willEventuallyBeDeprecated: false)) // Verify the rendered reference - let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node)) + let renderNode = try XCTUnwrap(DocumentationNodeConverter(context: context).convert(node)) // Verify task group link is beta XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, true) } // Set all platforms to beta & the exact version MyClass is being introduced. - // Expect the symbol to no be in beta sinceit does not have an introduced version for iOS + // Expect the symbol to no be in beta since it does not have an introduced version for iOS do { - let (bundle, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true), "watchOS": PlatformVersion(VersionTriplet(6, 0, 0), beta: true), "tvOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true), @@ -2088,7 +2088,7 @@ Document ], referencePath: "/documentation/MyKit") let node = try context.entity(with: reference) - let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node)) + let renderNode = try XCTUnwrap(DocumentationNodeConverter(context: context).convert(node)) // Verify task group link is not in beta because `iOS` does not have an introduced version XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyClass"] as? TopicRenderReference)?.isBeta, false) @@ -2096,7 +2096,7 @@ Document // Set all platforms as unconditionally unavailable and test that the symbol is not marked as beta. do { - let (_, context, reference) = try await makeTestBundle(currentPlatforms: [ + let (context, reference) = try await makeTestBundle(currentPlatforms: [ "iOS": PlatformVersion(VersionTriplet(100, 0, 0), beta: true) ], referencePath: "/documentation/MyKit/MyClass") let node = try context.entity(with: reference) @@ -3339,7 +3339,7 @@ Document } func testLanguageSpecificTopicSections() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "MixedLanguageFrameworkWithLanguageRefinements") { url in + let (_, _, context) = try await testBundleAndContext(copying: "MixedLanguageFrameworkWithLanguageRefinements") { url in try """ # ``MixedFramework/MyObjectiveCClassObjectiveCName`` @@ -3376,7 +3376,7 @@ Document let documentationNode = try context.entity(with: reference) XCTAssertEqual(documentationNode.availableVariantTraits.count, 2, "This page has Swift and Objective-C variants") - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(documentationNode) let topicSectionsVariants = renderNode.topicSectionsVariants @@ -3430,7 +3430,7 @@ Document - ``SomeClass4`` """), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) XCTAssert(context.problems.isEmpty, "\(context.problems.map(\.diagnostic.summary))") let moduleReference = try XCTUnwrap(context.soleRootModuleReference) @@ -3462,11 +3462,11 @@ Document ], file: file, line: line) } - let nodeConverter = DocumentationNodeConverter(bundle: bundle, context: context) + let nodeConverter = DocumentationNodeConverter(context: context) assertExpectedTopicSections(nodeConverter.convert(documentationNode)) let contextConverter = DocumentationContextConverter( - bundle: bundle, + bundle: context.inputs, context: context, renderContext: RenderContext(documentationContext: context) ) @@ -3504,14 +3504,14 @@ Document let tempURL = try createTemporaryDirectory() let bundleURL = try exampleDocumentation.write(inside: tempURL) - let (_, bundle, context) = try await loadBundle(from: bundleURL, diagnosticEngine: .init() /* no diagnostic consumers */) + let (_, _, context) = try await loadBundle(from: bundleURL, diagnosticEngine: .init() /* no diagnostic consumers */) let reference = try XCTUnwrap(context.soleRootModuleReference) let documentationNode = try context.entity(with: reference) XCTAssertEqual(documentationNode.availableVariantTraits.count, 1) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(documentationNode) let topicSection = renderNode.topicSectionsVariants.defaultValue @@ -3524,13 +3524,13 @@ Document } func testAutomaticCurationForRefinedSymbols() async throws { - let (_, bundle, context) = try await testBundleAndContext(named: "GeometricalShapes") + let (_, _, context) = try await testBundleAndContext(named: "GeometricalShapes") do { let root = try XCTUnwrap(context.soleRootModuleReference) let node = try context.entity(with: root) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(node) let swiftTopicSections = renderNode.topicSectionsVariants.defaultValue @@ -3560,10 +3560,10 @@ Document } do { - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/GeometricalShapes/Circle", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/GeometricalShapes/Circle", sourceLanguage: .swift) let node = try context.entity(with: reference) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(node) let swiftTopicSections = renderNode.topicSectionsVariants.defaultValue @@ -3642,7 +3642,7 @@ Document )) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) XCTAssertEqual(context.knownPages.map(\.path).sorted(), [ "/documentation/ModuleName", @@ -3655,7 +3655,7 @@ Document let unnamedStructReference = try XCTUnwrap(context.soleRootModuleReference).appendingPath("SomeContainer/struct_(unnamed)") let node = try context.entity(with: unnamedStructReference) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(node) XCTAssertEqual(renderNode.metadata.title, "struct (unnamed)") diff --git a/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift b/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift index fd60141b2..002f93d25 100644 --- a/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DefaultCodeListingSyntaxTests.swift @@ -56,7 +56,7 @@ class DefaultCodeBlockSyntaxTests: XCTestCase { let (_, context) = try await loadBundle(catalog: catalog) let reference = try XCTUnwrap(context.soleRootModuleReference) - let converter = DocumentationNodeConverter(bundle: context.inputs, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(try context.entity(with: reference)) let renderSection = try XCTUnwrap(renderNode.primaryContentSections.first as? ContentRenderSection) diff --git a/Tests/SwiftDocCTests/Rendering/PropertyListDetailsRenderSectionTests.swift b/Tests/SwiftDocCTests/Rendering/PropertyListDetailsRenderSectionTests.swift index bfe5eddd0..a4790d4d2 100644 --- a/Tests/SwiftDocCTests/Rendering/PropertyListDetailsRenderSectionTests.swift +++ b/Tests/SwiftDocCTests/Rendering/PropertyListDetailsRenderSectionTests.swift @@ -55,9 +55,9 @@ class PropertyListDetailsRenderSectionTests: XCTestCase { let catalog = Folder(name: "unit-test.docc", content: [ TextFile(name: "MyModule.symbols.json", utf8Content: symbolGraphString) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) let node = try XCTUnwrap(context.documentationCache["plist:propertylistkey"]) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(node) return try XCTUnwrap(renderNode.primaryContentSections.mapFirst(where: { $0 as? PropertyListDetailsRenderSection })) } diff --git a/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift b/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift index 58136785d..b57ce61c1 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift @@ -93,14 +93,14 @@ class RenderMetadataTests: XCTestCase { /// Test that a bystanders symbol graph is loaded, symbols are merged into the main module /// and the bystanders are included in the render node metadata. func testRendersBystandersFromSymbolGraph() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [:]) { url in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [:]) { url in let bystanderSymbolGraphURL = Bundle.module.url( forResource: "MyKit@Foundation@_MyKit_Foundation.symbols", withExtension: "json", subdirectory: "Test Resources")! try FileManager.default.copyItem(at: bystanderSymbolGraphURL, to: url.appendingPathComponent("MyKit@Foundation@_MyKit_Foundation.symbols.json")) } // Verify the symbol from bystanders graph is present in the documentation context. - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/MyKit/MyClass/myFunction1()", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/MyKit/MyClass/myFunction1()", sourceLanguage: .swift) let entity = try XCTUnwrap(try? context.entity(with: reference)) let symbol = try XCTUnwrap(entity.semantic as? Symbol) @@ -108,7 +108,7 @@ class RenderMetadataTests: XCTestCase { XCTAssertEqual(symbol.crossImportOverlayModule?.bystanderModules, ["Foundation"]) // Verify the rendered metadata contains the bystanders - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) XCTAssertEqual(renderNode.metadata.modules?.first?.name, "MyKit") XCTAssertEqual(renderNode.metadata.modules?.first?.relatedModules, ["Foundation"]) @@ -137,7 +137,7 @@ class RenderMetadataTests: XCTestCase { XCTAssertEqual(symbol.crossImportOverlayModule?.bystanderModules, ["BaseKit"]) // Verify the rendered metadata contains the bystanders - let converter = DocumentationNodeConverter(bundle: context.inputs, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) XCTAssertEqual(renderNode.metadata.modules?.first?.name, "OverlayTest") XCTAssertEqual(renderNode.metadata.modules?.first?.relatedModules, ["BaseKit"]) diff --git a/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift b/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift index 2e2ec2bd6..6d5469869 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift @@ -510,7 +510,7 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase { ])) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) let moduleReference = try XCTUnwrap(context.soleRootModuleReference) let dictionaryReference = moduleReference.appendingPath("SomeDictionary") @@ -521,7 +521,7 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase { symbol.dictionaryKeysSection = dictionaryKeysSection context.documentationCache[dictionaryReference] = node - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(node) return try XCTUnwrap(renderNode.primaryContentSections.mapFirst(where: { $0 as? PropertiesRenderSection })) diff --git a/Tests/SwiftDocCTests/Rendering/TermListTests.swift b/Tests/SwiftDocCTests/Rendering/TermListTests.swift index 426df3d6a..d5e496456 100644 --- a/Tests/SwiftDocCTests/Rendering/TermListTests.swift +++ b/Tests/SwiftDocCTests/Rendering/TermListTests.swift @@ -86,12 +86,12 @@ class TermListTests: XCTestCase { var configuration = DocumentationContext.Configuration() configuration.externalDocumentationConfiguration.sources = ["com.external.testbundle": resolver] - let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration) + let (_, context) = try await loadBundle(catalog: catalog, configuration: configuration) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/unit-test/Article", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: context.inputs.id, path: "/documentation/unit-test/Article", sourceLanguage: .swift) let entity = try context.entity(with: reference) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(entity) let overviewSection = try XCTUnwrap(renderNode.primaryContentSections.first as? ContentRenderSection) diff --git a/Tests/SwiftDocCTests/Utility/ListItemExtractorTests.swift b/Tests/SwiftDocCTests/Utility/ListItemExtractorTests.swift index 59fe23e12..6159b6060 100644 --- a/Tests/SwiftDocCTests/Utility/ListItemExtractorTests.swift +++ b/Tests/SwiftDocCTests/Utility/ListItemExtractorTests.swift @@ -272,8 +272,7 @@ class ListItemExtractorTests: XCTestCase { line: UInt = #line ) async throws { // Build documentation for a module page with one tagged item with a lot of different - - let (bundle, context) = try await loadBundle( + let (_, context) = try await loadBundle( catalog: Folder(name: "Something.docc", content: [ JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(moduleName: "ModuleName")), TextFile(name: "Extension.md", utf8Content: """ @@ -303,7 +302,7 @@ class ListItemExtractorTests: XCTestCase { ]) ) - try _assertExtractsRichContentFor(tagName: tagName, findModelContent: findModelContent, renderVerification: renderVerification, isAside: isAside, bundle: bundle, context: context, expectedLogText: """ + try _assertExtractsRichContentFor(tagName: tagName, findModelContent: findModelContent, renderVerification: renderVerification, isAside: isAside, context: context, expectedLogText: """ \u{001B}[1;33mwarning: 'FirstNotFoundSymbol' doesn't exist at '/ModuleName'\u{001B}[0;0m --> /Something.docc/Extension.md:5:\(49+tagName.count)-5:\(68+tagName.count) 3 | Some description of this module. @@ -338,8 +337,7 @@ class ListItemExtractorTests: XCTestCase { line: UInt = #line ) async throws { // Build documentation for a module page with one tagged item with a lot of different - - let (bundle, context) = try await loadBundle( + let (_, context) = try await loadBundle( catalog: Folder(name: "Something.docc", content: [ JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(moduleName: "ModuleName")), TextFile(name: "Extension.md", utf8Content: """ @@ -370,7 +368,7 @@ class ListItemExtractorTests: XCTestCase { ]) ) - try _assertExtractsRichContentFor(tagName: tagName, findModelContent: findModelContent, renderVerification: renderVerification, isAside: false, bundle: bundle, context: context, expectedLogText: """ + try _assertExtractsRichContentFor(tagName: tagName, findModelContent: findModelContent, renderVerification: renderVerification, isAside: false, context: context, expectedLogText: """ \u{001B}[1;33mwarning: 'FirstNotFoundSymbol' doesn't exist at '/ModuleName'\u{001B}[0;0m --> /Something.docc/Extension.md:6:60-6:79 4 | @@ -401,7 +399,6 @@ class ListItemExtractorTests: XCTestCase { findModelContent: (Symbol) -> [any Markup]?, renderVerification: RenderVerification, isAside: Bool, - bundle: DocumentationBundle, context: DocumentationContext, expectedLogText: String, file: StaticString = #filePath, @@ -457,7 +454,7 @@ class ListItemExtractorTests: XCTestCase { return } - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let converter = DocumentationNodeConverter(context: context) let renderNode = converter.convert(node) let renderContent = try XCTUnwrap(findRenderContent(renderNode), "Didn't find any rendered content", file: file, line: line) diff --git a/Tests/SwiftDocCUtilitiesTests/ConvertActionIndexerTests.swift b/Tests/SwiftDocCUtilitiesTests/ConvertActionIndexerTests.swift index 39fa7a46d..4d3db2bdb 100644 --- a/Tests/SwiftDocCUtilitiesTests/ConvertActionIndexerTests.swift +++ b/Tests/SwiftDocCUtilitiesTests/ConvertActionIndexerTests.swift @@ -17,11 +17,11 @@ class ConvertActionIndexerTests: XCTestCase { // Tests the standalone indexer func testConvertActionIndexer() async throws { - let (bundle, dataProvider) = try DocumentationContext.InputsProvider() + let (inputs, dataProvider) = try DocumentationContext.InputsProvider() .inputsAndDataProvider(startingPoint: testCatalogURL(named: "LegacyBundle_DoNotUseInNewTests"), options: .init()) - let context = try await DocumentationContext(bundle: bundle, dataProvider: dataProvider) - let converter = DocumentationNodeConverter(bundle: bundle, context: context) + let context = try await DocumentationContext(bundle: inputs, dataProvider: dataProvider) + let converter = DocumentationNodeConverter(context: context) // Add /documentation/MyKit to the index, verify the tree dump do { @@ -29,7 +29,7 @@ class ConvertActionIndexerTests: XCTestCase { let renderNode = try converter.convert(context.entity(with: reference)) let tempIndexURL = try createTemporaryDirectory(named: "index") - let indexer = try ConvertAction.Indexer(outputURL: tempIndexURL, bundleID: bundle.id) + let indexer = try ConvertAction.Indexer(outputURL: tempIndexURL, bundleID: inputs.id) indexer.index(renderNode) XCTAssertTrue(indexer.finalize(emitJSON: false, emitLMDB: false).isEmpty) let treeDump = try XCTUnwrap(indexer.dumpTree()) @@ -54,7 +54,7 @@ class ConvertActionIndexerTests: XCTestCase { let renderNode2 = try converter.convert(context.entity(with: reference2)) let tempIndexURL = try createTemporaryDirectory(named: "index") - let indexer = try ConvertAction.Indexer(outputURL: tempIndexURL, bundleID: bundle.id) + let indexer = try ConvertAction.Indexer(outputURL: tempIndexURL, bundleID: inputs.id) indexer.index(renderNode1) indexer.index(renderNode2) XCTAssertTrue(indexer.finalize(emitJSON: false, emitLMDB: false).isEmpty) From 4922a7605fb54eff58c5b7614c883e8173c066ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 12:11:28 +0200 Subject: [PATCH 10/19] Remove redundant "bundle" parameter from DocumentationContextConverter --- .../DocumentationContextConverter.swift | 27 +++++++--- .../Convert/ConvertService.swift | 1 - .../ConvertActionConverter.swift | 1 - .../DocumentationContextConverterTests.swift | 10 ++-- .../Indexing/ExternalRenderNodeTests.swift | 24 ++++----- .../Indexing/NavigatorIndexTests.swift | 50 +++++++++---------- .../Indexing/RenderIndexTests.swift | 14 +++--- .../DocumentationContextTests.swift | 10 ++-- .../ExternalPathHierarchyResolverTests.swift | 14 +++--- .../Model/RenderNodeDiffingBundleTests.swift | 12 ++--- .../Model/SemaToRenderNodeTests.swift | 1 - ...OutOfProcessReferenceResolverV2Tests.swift | 1 - .../Rendering/HeadingAnchorTests.swift | 4 +- .../Rendering/RenderMetadataTests.swift | 4 +- 14 files changed, 89 insertions(+), 84 deletions(-) diff --git a/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift b/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift index a18f97980..ff9c43823 100644 --- a/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift +++ b/Sources/SwiftDocC/Converter/DocumentationContextConverter.swift @@ -20,9 +20,6 @@ public class DocumentationContextConverter { /// The context the converter uses to resolve references it finds in the documentation node's content. let context: DocumentationContext - /// The bundle that contains the content from which the documentation node originated. - let bundle: DocumentationBundle - /// A context that contains common pre-rendered pieces of content. let renderContext: RenderContext @@ -43,12 +40,11 @@ public class DocumentationContextConverter { /// The remote source control repository where the documented module's source is hosted. let sourceRepository: SourceRepository? - /// Creates a new node converter for the given bundle and context. + /// Creates a new node converter for the given context. /// /// The converter uses bundle and context to resolve references to other documentation and describe the documentation hierarchy. /// /// - Parameters: - /// - bundle: The bundle that contains the content from which the documentation node originated. /// - context: The context that the converter uses to to resolve references it finds in the documentation node's content. /// - renderContext: A context that contains common pre-rendered pieces of content. /// - emitSymbolSourceFileURIs: Whether the documentation converter should include @@ -61,7 +57,6 @@ public class DocumentationContextConverter { /// - sourceRepository: The source repository where the documentation's sources are hosted. /// - symbolIdentifiersWithExpandedDocumentation: A list of symbol IDs that have version of their documentation page with more content that a renderer can link to. public init( - bundle: DocumentationBundle, context: DocumentationContext, renderContext: RenderContext, emitSymbolSourceFileURIs: Bool = false, @@ -69,7 +64,6 @@ public class DocumentationContextConverter { sourceRepository: SourceRepository? = nil, symbolIdentifiersWithExpandedDocumentation: [String]? = nil ) { - self.bundle = bundle self.context = context self.renderContext = renderContext self.shouldEmitSymbolSourceFileURIs = emitSymbolSourceFileURIs @@ -77,6 +71,25 @@ public class DocumentationContextConverter { self.sourceRepository = sourceRepository self.symbolIdentifiersWithExpandedDocumentation = symbolIdentifiersWithExpandedDocumentation } + @available(*, deprecated, renamed: "init(context:renderContext:emitSymbolSourceFileURIs:emitSymbolAccessLevels:sourceRepository:symbolIdentifiersWithExpandedDocumentation:)", message: "Use 'init(context:renderContext:emitSymbolSourceFileURIs:emitSymbolAccessLevels:sourceRepository:symbolIdentifiersWithExpandedDocumentation:)' instead. This deprecated API will be removed after 6.4 is released.") + public convenience init( + bundle _: DocumentationBundle, + context: DocumentationContext, + renderContext: RenderContext, + emitSymbolSourceFileURIs: Bool = false, + emitSymbolAccessLevels: Bool = false, + sourceRepository: SourceRepository? = nil, + symbolIdentifiersWithExpandedDocumentation: [String]? = nil + ) { + self.init( + context: context, + renderContext: renderContext, + emitSymbolSourceFileURIs: emitSymbolSourceFileURIs, + emitSymbolAccessLevels: emitSymbolAccessLevels, + sourceRepository: sourceRepository, + symbolIdentifiersWithExpandedDocumentation: symbolIdentifiersWithExpandedDocumentation + ) + } /// Converts a documentation node to a render node. /// diff --git a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift index 1b55812a3..8eef7e671 100644 --- a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift +++ b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift @@ -168,7 +168,6 @@ public struct ConvertService: DocumentationService { return documentationNode.meetsExpandedDocumentationRequirements(expandedDocsRequirement) ? identifier : nil } let converter = DocumentationContextConverter( - bundle: bundle, context: context, renderContext: renderContext, emitSymbolSourceFileURIs: request.emitSymbolSourceFileURIs, diff --git a/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift b/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift index e14dec587..6be58a18e 100644 --- a/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift +++ b/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift @@ -69,7 +69,6 @@ package enum ConvertActionConverter { try outputConsumer.consume(assetsInBundle: bundle) let converter = DocumentationContextConverter( - bundle: bundle, context: context, renderContext: renderContext, sourceRepository: sourceRepository diff --git a/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift b/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift index 10ebec954..d9b63dfee 100644 --- a/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift +++ b/Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift @@ -21,7 +21,7 @@ class DocumentationContextConverterTests: XCTestCase { // We'll use these to convert nodes in bulk let renderContext = RenderContext(documentationContext: context) - let bulkNodeConverter = DocumentationContextConverter(bundle: context.inputs, context: context, renderContext: renderContext) + let bulkNodeConverter = DocumentationContextConverter(context: context, renderContext: renderContext) let encoder = JSONEncoder() for identifier in context.knownPages { @@ -41,7 +41,7 @@ class DocumentationContextConverterTests: XCTestCase { } func testSymbolLocationsAreOnlyIncludedWhenRequested() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let renderContext = RenderContext(documentationContext: context) let fillIntroducedSymbolNode = try XCTUnwrap( @@ -50,7 +50,6 @@ class DocumentationContextConverterTests: XCTestCase { do { let documentationContextConverter = DocumentationContextConverter( - bundle: bundle, context: context, renderContext: renderContext, emitSymbolSourceFileURIs: true) @@ -61,7 +60,6 @@ class DocumentationContextConverterTests: XCTestCase { do { let documentationContextConverter = DocumentationContextConverter( - bundle: bundle, context: context, renderContext: renderContext) @@ -71,7 +69,7 @@ class DocumentationContextConverterTests: XCTestCase { } func testSymbolAccessLevelsAreOnlyIncludedWhenRequested() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let renderContext = RenderContext(documentationContext: context) let fillIntroducedSymbolNode = try XCTUnwrap( @@ -80,7 +78,6 @@ class DocumentationContextConverterTests: XCTestCase { do { let documentationContextConverter = DocumentationContextConverter( - bundle: bundle, context: context, renderContext: renderContext, emitSymbolAccessLevels: true @@ -92,7 +89,6 @@ class DocumentationContextConverterTests: XCTestCase { do { let documentationContextConverter = DocumentationContextConverter( - bundle: bundle, context: context, renderContext: renderContext) diff --git a/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift b/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift index 8c201a2bc..d57306b8c 100644 --- a/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift +++ b/Tests/SwiftDocCTests/Indexing/ExternalRenderNodeTests.swift @@ -244,16 +244,16 @@ class ExternalRenderNodeTests: XCTestCase { var configuration = DocumentationContext.Configuration() let externalResolver = generateExternalResolver() configuration.externalDocumentationConfiguration.sources[externalResolver.bundleID] = externalResolver - let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration) + let (_, 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) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() - let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) + let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) builder.setup() for externalLink in context.externalCache { - let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: bundle.id) + let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: context.inputs.id) try builder.index(renderNode: externalRenderNode) } for identifier in context.knownPages { @@ -334,16 +334,16 @@ class ExternalRenderNodeTests: XCTestCase { var configuration = DocumentationContext.Configuration() let externalResolver = generateExternalResolver() configuration.externalDocumentationConfiguration.sources[externalResolver.bundleID] = externalResolver - let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration) + let (_, 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) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() - let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) + let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) builder.setup() for externalLink in context.externalCache { - let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: bundle.id) + let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: context.inputs.id) try builder.index(renderNode: externalRenderNode) } for identifier in context.knownPages { @@ -412,16 +412,16 @@ class ExternalRenderNodeTests: XCTestCase { var configuration = DocumentationContext.Configuration() let externalResolver = generateExternalResolver() configuration.externalDocumentationConfiguration.sources[externalResolver.bundleID] = externalResolver - let (bundle, context) = try await loadBundle(catalog: catalog, configuration: configuration) + let (_, 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) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() - let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) + let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) builder.setup() for externalLink in context.externalCache { - let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: bundle.id) + let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: context.inputs.id) try builder.index(renderNode: externalRenderNode) } for identifier in context.knownPages { diff --git a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift index 5d5cb4a4b..bcab40af1 100644 --- a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift +++ b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift @@ -457,9 +457,9 @@ Root } func testNavigatorIndexGeneration() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) var results = Set() // Create an index 10 times to ensure we have not non-deterministic behavior across builds @@ -646,10 +646,10 @@ Root """), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: testBundleIdentifier) @@ -694,12 +694,12 @@ Root } func testNavigatorWithDifferentSwiftAndObjectiveCHierarchies() async throws { - let (_, bundle, context) = try await testBundleAndContext(named: "GeometricalShapes") + let (_, _, context) = try await testBundleAndContext(named: "GeometricalShapes") let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) - let fromMemoryBuilder = NavigatorIndex.Builder(outputURL: try createTemporaryDirectory(), bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) - let fromDecodedBuilder = NavigatorIndex.Builder(outputURL: try createTemporaryDirectory(), bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) + let fromMemoryBuilder = NavigatorIndex.Builder(outputURL: try createTemporaryDirectory(), bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) + let fromDecodedBuilder = NavigatorIndex.Builder(outputURL: try createTemporaryDirectory(), bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true, groupByLanguage: true) fromMemoryBuilder.setup() fromDecodedBuilder.setup() @@ -955,9 +955,9 @@ Root } func testNavigatorIndexUsingPageTitleGeneration() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) var results = Set() // Create an index 10 times to ensure we have not non-deterministic behavior across builds @@ -1081,9 +1081,9 @@ Root func testNavigatorIndexGenerationWithCuratedFragment() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) var results = Set() // Create an index 10 times to ensure we have no non-deterministic behavior across builds @@ -1144,9 +1144,9 @@ Root } func testNavigatorIndexAvailabilityGeneration() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: testBundleIdentifier, sortRootChildrenByName: true) @@ -1248,12 +1248,12 @@ Root } func testCustomIconsInNavigator() async throws { - let (bundle, context) = try await testBundleAndContext(named: "BookLikeContent") // This content has a @PageImage with the "icon" purpose + let (_, context) = try await testBundleAndContext(named: "BookLikeContent") // This content has a @PageImage with the "icon" purpose let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() - let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true) + let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true) builder.setup() for identifier in context.knownPages { @@ -1269,14 +1269,14 @@ Root let imageReference = try XCTUnwrap(renderIndex.references["plus.svg"]) XCTAssertEqual(imageReference.asset.variants.values.map(\.path).sorted(), [ - "/images/\(bundle.id)/plus.svg", + "/images/\(context.inputs.id)/plus.svg", ]) } func testNavigatorIndexDifferentHasherGeneration() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: testBundleIdentifier, sortRootChildrenByName: true) @@ -2050,11 +2050,11 @@ Root var configuration = DocumentationContext.Configuration() configuration.externalMetadata.currentPlatforms = platformMetadata - let (_, bundle, context) = try await testBundleAndContext(named: "AvailabilityBetaBundle", configuration: configuration) + let (_, _, context) = try await testBundleAndContext(named: "AvailabilityBetaBundle", configuration: configuration) let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() - let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.id.rawValue, sortRootChildrenByName: true) + let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true) builder.setup() for identifier in context.knownPages { let entity = try context.entity(with: identifier) @@ -2093,9 +2093,9 @@ Root } func generatedNavigatorIndex(for testBundleName: String, bundleIdentifier: String) async throws -> NavigatorIndex { - let (bundle, context) = try await testBundleAndContext(named: testBundleName) + let (_, context) = try await testBundleAndContext(named: testBundleName) let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let targetURL = try createTemporaryDirectory() let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundleIdentifier, sortRootChildrenByName: true, groupByLanguage: true) diff --git a/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift b/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift index 001dfe764..d2682c360 100644 --- a/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift +++ b/Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift @@ -648,10 +648,10 @@ final class RenderIndexTests: XCTestCase { ) try bundle.write(to: bundleDirectory) - let (_, loadedBundle, context) = try await loadBundle(from: bundleDirectory) + let (_, _, context) = try await loadBundle(from: bundleDirectory) XCTAssertEqual( - try generatedRenderIndex(for: loadedBundle, withIdentifier: "com.test.example", withContext: context), + try generatedRenderIndex(forIdentifier: "com.test.example", inContext: context), try RenderIndex.fromString(#""" { "interfaceLanguages": { @@ -737,17 +737,17 @@ final class RenderIndexTests: XCTestCase { } func generatedRenderIndex(for testBundleName: String, with bundleIdentifier: String) async throws -> RenderIndex { - let (bundle, context) = try await testBundleAndContext(named: testBundleName) - return try generatedRenderIndex(for: bundle, withIdentifier: bundleIdentifier, withContext: context) + let (_, context) = try await testBundleAndContext(named: testBundleName) + return try generatedRenderIndex(forIdentifier: bundleIdentifier, inContext: context) } - func generatedRenderIndex(for bundle: DocumentationBundle, withIdentifier bundleIdentifier: String, withContext context: DocumentationContext) throws -> RenderIndex { + func generatedRenderIndex(forIdentifier bundleIdentifier: String, inContext context: DocumentationContext) throws -> RenderIndex { let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let indexDirectory = try createTemporaryDirectory() let builder = NavigatorIndex.Builder( outputURL: indexDirectory, - bundleIdentifier: bundleIdentifier, + bundleIdentifier: context.inputs.id.rawValue, sortRootChildrenByName: true ) diff --git a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift index 9d3328fc3..da3461c07 100644 --- a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift @@ -1328,13 +1328,13 @@ class DocumentationContextTests: XCTestCase { """), ] + testData.symbolGraphFiles) - let (bundle, context) = try await loadBundle(catalog: testCatalog) + let (_, context) = try await loadBundle(catalog: testCatalog) let renderContext = RenderContext(documentationContext: context) - let identifier = ResolvedTopicReference(bundleID: bundle.id, path: "/tutorials/TestOverview", sourceLanguage: .swift) + let identifier = ResolvedTopicReference(bundleID: context.inputs.id, path: "/tutorials/TestOverview", sourceLanguage: .swift) let node = try context.entity(with: identifier) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let renderNode = try XCTUnwrap(converter.renderNode(for: node)) XCTAssertEqual( @@ -2425,7 +2425,7 @@ let expected = """ } func testPrefersNonSymbolsInDocLink() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "SymbolsWithSameNameAsModule") { url in + let (_, _, context) = try await testBundleAndContext(copying: "SymbolsWithSameNameAsModule") { url in // This bundle has a top-level struct named "Wrapper". Adding an article named "Wrapper.md" introduces a possibility for a link collision try """ # An article @@ -2452,7 +2452,7 @@ let expected = """ let moduleNode = try context.entity(with: moduleReference) let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let renderNode = try XCTUnwrap(converter.renderNode(for: moduleNode)) let curatedTopic = try XCTUnwrap(renderNode.topicSections.first?.identifiers.first) diff --git a/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift b/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift index 600235cbc..0d0bab01b 100644 --- a/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/ExternalPathHierarchyResolverTests.swift @@ -699,7 +699,7 @@ class ExternalPathHierarchyResolverTests: XCTestCase { ) } - let (dependencyBundle, dependencyContext) = try await loadBundle( + let (_ , dependencyContext) = try await loadBundle( catalog: Folder(name: "Dependency.docc", content: [ InfoPlist(identifier: "com.example.dependency"), // This isn't necessary but makes it easier to distinguish the identifier from the module name in the external references. JSONFile(name: "Dependency.symbols.json", content: makeSymbolGraph(moduleName: "Dependency", symbols: symbols)) @@ -707,7 +707,7 @@ class ExternalPathHierarchyResolverTests: XCTestCase { ) // Retrieve the link information from the dependency, as if '--enable-experimental-external-link-support' was passed to DocC - let dependencyConverter = DocumentationContextConverter(bundle: dependencyBundle, context: dependencyContext, renderContext: .init(documentationContext: dependencyContext)) + let dependencyConverter = DocumentationContextConverter(context: dependencyContext, renderContext: .init(documentationContext: dependencyContext)) let linkSummaries: [LinkDestinationSummary] = try dependencyContext.knownPages.flatMap { reference in let entity = try dependencyContext.entity(with: reference) @@ -715,7 +715,7 @@ class ExternalPathHierarchyResolverTests: XCTestCase { return entity.externallyLinkableElementSummaries(context: dependencyContext, renderNode: renderNode, includeTaskGroups: false) } - let linkResolutionInformation = try dependencyContext.linkResolver.localResolver.prepareForSerialization(bundleID: dependencyBundle.id) + let linkResolutionInformation = try dependencyContext.linkResolver.localResolver.prepareForSerialization(bundleID: dependencyContext.inputs.id) XCTAssertEqual(linkResolutionInformation.pathHierarchy.nodes.count - linkResolutionInformation.nonSymbolPaths.count, 5 /* 4 symbols & 1 module */) XCTAssertEqual(linkSummaries.count, 5 /* 4 symbols & 1 module */) @@ -724,7 +724,7 @@ class ExternalPathHierarchyResolverTests: XCTestCase { configuration.externalDocumentationConfiguration.dependencyArchives = [URL(fileURLWithPath: "/Dependency.doccarchive")] // After building the dependency, - let (mainBundle, mainContext) = try await loadBundle( + let (_, mainContext) = try await loadBundle( catalog: Folder(name: "Main.docc", content: [ JSONFile(name: "Main.symbols.json", content: makeSymbolGraph( moduleName: "Main", @@ -794,11 +794,11 @@ class ExternalPathHierarchyResolverTests: XCTestCase { XCTAssertEqual(mainContext.knownPages.count, 3 /* 2 symbols & 1 module*/) - let mainConverter = DocumentationContextConverter(bundle: mainBundle, context: mainContext, renderContext: .init(documentationContext: mainContext)) + let mainConverter = DocumentationContextConverter(context: mainContext, renderContext: .init(documentationContext: mainContext)) // Check the relationships of 'SomeClass' do { - let reference = ResolvedTopicReference(bundleID: mainBundle.id, path: "/documentation/Main/SomeClass", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: mainContext.inputs.id, path: "/documentation/Main/SomeClass", sourceLanguage: .swift) let entity = try mainContext.entity(with: reference) let renderNode = try XCTUnwrap(mainConverter.renderNode(for: entity)) @@ -822,7 +822,7 @@ class ExternalPathHierarchyResolverTests: XCTestCase { // Check the declaration of 'someFunction' do { - let reference = ResolvedTopicReference(bundleID: mainBundle.id, path: "/documentation/Main/SomeClass/someFunction(parameter:)", sourceLanguage: .swift) + let reference = ResolvedTopicReference(bundleID: mainContext.inputs.id, path: "/documentation/Main/SomeClass/someFunction(parameter:)", sourceLanguage: .swift) let entity = try mainContext.entity(with: reference) let renderNode = try XCTUnwrap(mainConverter.renderNode(for: entity)) diff --git a/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift b/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift index cde169c47..e910d461b 100644 --- a/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift +++ b/Tests/SwiftDocCTests/Model/RenderNodeDiffingBundleTests.swift @@ -284,9 +284,9 @@ class RenderNodeDiffingBundleTests: XCTestCase { } func testNoDiffsWhenReconvertingSameBundle() async throws { - let (bundle, context) = try await testBundleAndContext(named: testBundleName) + let (_, context) = try await testBundleAndContext(named: testBundleName) let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) for identifier in context.knownPages { let entity = try context.entity(with: identifier) @@ -303,24 +303,24 @@ class RenderNodeDiffingBundleTests: XCTestCase { topicReferencePath: String, modification: @escaping (URL) throws -> () ) async throws -> JSONPatchDifferences { - let (bundleOriginal, contextOriginal) = try await testBundleAndContext(named: bundleName) + let (_, contextOriginal) = try await testBundleAndContext(named: bundleName) let nodeOriginal = try contextOriginal.entity(with: ResolvedTopicReference(bundleID: bundleID, path: topicReferencePath, sourceLanguage: .swift)) var renderContext = RenderContext(documentationContext: contextOriginal) - var converter = DocumentationContextConverter(bundle: bundleOriginal, context: contextOriginal, renderContext: renderContext) + var converter = DocumentationContextConverter(context: contextOriginal, renderContext: renderContext) let renderNodeOriginal = try XCTUnwrap(converter.renderNode(for: nodeOriginal)) // Make copy of the bundle on disk, modify the document, and write it - let (_, bundleModified, contextModified) = try await testBundleAndContext(copying: bundleName) { url in + let (_, _, contextModified) = try await testBundleAndContext(copying: bundleName) { url in try modification(url) } let nodeModified = try contextModified.entity(with: ResolvedTopicReference(bundleID: bundleID, path: topicReferencePath, sourceLanguage: .swift)) renderContext = RenderContext(documentationContext: contextModified) - converter = DocumentationContextConverter(bundle: bundleModified, context: contextModified, renderContext: renderContext) + converter = DocumentationContextConverter(context: contextModified, renderContext: renderContext) let renderNodeModified = try XCTUnwrap(converter.renderNode(for: nodeModified)) diff --git a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift index fb0aae328..155075931 100644 --- a/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift +++ b/Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift @@ -3466,7 +3466,6 @@ Document assertExpectedTopicSections(nodeConverter.convert(documentationNode)) let contextConverter = DocumentationContextConverter( - bundle: context.inputs, context: context, renderContext: RenderContext(documentationContext: context) ) diff --git a/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift b/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift index 3cad453d2..251a75759 100644 --- a/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift +++ b/Tests/SwiftDocCTests/OutOfProcessReferenceResolverV2Tests.swift @@ -391,7 +391,6 @@ class OutOfProcessReferenceResolverV2Tests: XCTestCase { let reference = try XCTUnwrap(context.soleRootModuleReference, "This example catalog only has a root page") let converter = DocumentationContextConverter( - bundle: context.inputs, context: context, renderContext: RenderContext(documentationContext: context) ) diff --git a/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift b/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift index 24d7b5762..778e19057 100644 --- a/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift +++ b/Tests/SwiftDocCTests/Rendering/HeadingAnchorTests.swift @@ -34,12 +34,12 @@ class HeadingAnchorTests: XCTestCase { """), ]) - let (bundle, context) = try await loadBundle(catalog: catalog) + let (_, context) = try await loadBundle(catalog: catalog) let reference = try XCTUnwrap(context.soleRootModuleReference) let node = try context.entity(with: reference) let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) let renderNode = try XCTUnwrap(converter.renderNode(for: node)) // Check heading anchors are encoded diff --git a/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift b/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift index b57ce61c1..9eea80584 100644 --- a/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift +++ b/Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift @@ -73,10 +73,10 @@ class RenderMetadataTests: XCTestCase { var typesOfPages = [Tutorial.self, TutorialTableOfContents.self, Article.self, TutorialArticle.self, Symbol.self] for bundleName in ["LegacyBundle_DoNotUseInNewTests"] { - let (bundle, context) = try await testBundleAndContext(named: bundleName) + let (_, context) = try await testBundleAndContext(named: bundleName) let renderContext = RenderContext(documentationContext: context) - let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext) + let converter = DocumentationContextConverter(context: context, renderContext: renderContext) for identifier in context.knownPages { let entity = try context.entity(with: identifier) let renderNode = try XCTUnwrap(converter.renderNode(for: entity)) From 8bfd711099f96a6c54dcd3037341f10751ac78d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 12:15:34 +0200 Subject: [PATCH 11/19] Remove redundant "bundle" parameter from GeneratedDocumentationTopics --- .../SwiftDocC/Infrastructure/DocumentationContext.swift | 6 +----- .../Symbol Graph/GeneratedDocumentationTopics.swift | 9 ++++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index a66321a92..86651dc55 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -1228,11 +1228,7 @@ public class DocumentationContext { symbolsWithMultipleDocumentationExtensionMatches.removeAll() // Create inherited API collections - try GeneratedDocumentationTopics.createInheritedSymbolsAPICollections( - relationships: uniqueRelationships, - context: self, - bundle: bundle - ) + try GeneratedDocumentationTopics.createInheritedSymbolsAPICollections(relationships: uniqueRelationships, context: self) // Parse and prepare the nodes' content concurrently. let updatedNodes = signposter.withIntervalSignpost("Parse symbol markup", id: signposter.makeSignpostID()) { diff --git a/Sources/SwiftDocC/Infrastructure/Symbol Graph/GeneratedDocumentationTopics.swift b/Sources/SwiftDocC/Infrastructure/Symbol Graph/GeneratedDocumentationTopics.swift index 4ceb41fa3..cf461d328 100644 --- a/Sources/SwiftDocC/Infrastructure/Symbol Graph/GeneratedDocumentationTopics.swift +++ b/Sources/SwiftDocC/Infrastructure/Symbol Graph/GeneratedDocumentationTopics.swift @@ -96,7 +96,7 @@ enum GeneratedDocumentationTopics { private static let defaultImplementationGroupTitle = "Default Implementations" - private static func createCollectionNode(parent: ResolvedTopicReference, title: String, identifiers: [ResolvedTopicReference], context: DocumentationContext, bundle: DocumentationBundle) throws { + private static func createCollectionNode(parent: ResolvedTopicReference, title: String, identifiers: [ResolvedTopicReference], context: DocumentationContext) throws { let automaticCurationSourceLanguage: SourceLanguage let automaticCurationSourceLanguages: Set automaticCurationSourceLanguage = identifiers.first?.sourceLanguage ?? .swift @@ -104,7 +104,7 @@ enum GeneratedDocumentationTopics { // Create the collection topic reference let collectionReference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: context.inputs.id, path: NodeURLGenerator.Path.documentationCuration( parentPath: parent.path, articleName: title @@ -227,8 +227,7 @@ enum GeneratedDocumentationTopics { /// - relationships: A set of relationships to inspect. /// - symbolsURLHierarchy: A symbol graph hierarchy as created during symbol registration. /// - context: A documentation context to update. - /// - bundle: The current documentation bundle. - static func createInheritedSymbolsAPICollections(relationships: Set, context: DocumentationContext, bundle: DocumentationBundle) throws { + static func createInheritedSymbolsAPICollections(relationships: Set, context: DocumentationContext) throws { var inheritanceIndex = InheritedSymbols() // Walk the symbol graph relationships and look for parent <-> child links that stem in a different module. @@ -258,7 +257,7 @@ enum GeneratedDocumentationTopics { for (typeReference, collections) in inheritanceIndex.implementingTypes where !collections.inheritedFromTypeName.isEmpty { for (_, collection) in collections.inheritedFromTypeName where !collection.identifiers.isEmpty { // Create a collection for the given provider type's inherited symbols - try createCollectionNode(parent: typeReference, title: collection.title, identifiers: collection.identifiers, context: context, bundle: bundle) + try createCollectionNode(parent: typeReference, title: collection.title, identifiers: collection.identifiers, context: context) } } } From c4bdf0b5eaa40f166c8c66044ae4571f02a0f9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 12:21:31 +0200 Subject: [PATCH 12/19] Remove redundant "bundle" parameter from ConvertActionConverter --- .../Infrastructure/ConvertActionConverter.swift | 12 +++++------- .../Action/Actions/Convert/ConvertAction.swift | 15 +++++++-------- .../DeprecatedDiagnosticsDigestWarningTests.swift | 8 ++------ .../TestRenderNodeOutputConsumer.swift | 4 +--- .../MergeActionTests.swift | 12 ++++++------ 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift b/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift index 6be58a18e..1673f7b33 100644 --- a/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift +++ b/Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift @@ -21,10 +21,9 @@ package enum ConvertActionConverter { static package let signposter = NoOpSignposterShim() #endif - /// Converts the documentation bundle in the given context and passes its output to a given consumer. + /// Converts the documentation in the given context and passes its output to a given consumer. /// /// - Parameters: - /// - bundle: The documentation bundle to convert. /// - context: The context that the bundle is a part of. /// - outputConsumer: The consumer that the conversion passes outputs of the conversion to. /// - sourceRepository: The source repository where the documentation's sources are hosted. @@ -32,7 +31,6 @@ package enum ConvertActionConverter { /// - documentationCoverageOptions: The level of experimental documentation coverage information that the conversion should pass to the consumer. /// - Returns: A list of problems that occurred during the conversion (excluding the problems that the context already encountered). package static func convert( - bundle: DocumentationBundle, context: DocumentationContext, outputConsumer: some ConvertOutputConsumer & ExternalNodeConsumer, sourceRepository: SourceRepository?, @@ -66,7 +64,7 @@ package enum ConvertActionConverter { try outputConsumer.consume(renderReferenceStore: renderContext.store) // Copy images, sample files, and other static assets. - try outputConsumer.consume(assetsInBundle: bundle) + try outputConsumer.consume(assetsInBundle: context.inputs) let converter = DocumentationContextConverter( context: context, @@ -108,7 +106,7 @@ package enum ConvertActionConverter { // Here we're associating the external node with the **current** bundle's bundle ID. // This is needed because nodes are only considered children if the parent and child's bundle ID match. // Otherwise, the node will be considered as a separate root node and displayed separately. - let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: bundle.id) + let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: context.inputs.id) try outputConsumer.consume(externalRenderNode: externalRenderNode) } @@ -191,7 +189,7 @@ package enum ConvertActionConverter { if FeatureFlags.current.isExperimentalLinkHierarchySerializationEnabled { signposter.withIntervalSignpost("Serialize link hierarchy", id: signposter.makeSignpostID()) { do { - let serializableLinkInformation = try context.linkResolver.localResolver.prepareForSerialization(bundleID: bundle.id) + let serializableLinkInformation = try context.linkResolver.localResolver.prepareForSerialization(bundleID: context.inputs.id) try outputConsumer.consume(linkResolutionInformation: serializableLinkInformation) if !emitDigest { @@ -224,7 +222,7 @@ package enum ConvertActionConverter { break } - try outputConsumer.consume(buildMetadata: BuildMetadata(bundleDisplayName: bundle.displayName, bundleID: bundle.id)) + try outputConsumer.consume(buildMetadata: BuildMetadata(bundleDisplayName: context.inputs.displayName, bundleID: context.inputs.id)) // Log the finalized topic graph checksum. benchmark(add: Benchmark.TopicGraphHash(context: context)) diff --git a/Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift b/Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift index 6f0af6647..b6c98eced 100644 --- a/Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift +++ b/Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift @@ -178,12 +178,12 @@ public struct ConvertAction: AsyncAction { self.configuration = configuration - self.bundle = bundle + self.inputs = bundle self.dataProvider = dataProvider } let configuration: DocumentationContext.Configuration - private let bundle: DocumentationBundle + private let inputs: DocumentationBundle private let dataProvider: any DataProvider /// A block of extra work that tests perform to affect the time it takes to convert documentation @@ -286,10 +286,10 @@ public struct ConvertAction: AsyncAction { workingDirectory: temporaryFolder, fileManager: fileManager) - let indexer = try Indexer(outputURL: temporaryFolder, bundleID: bundle.id) + let indexer = try Indexer(outputURL: temporaryFolder, bundleID: inputs.id) let registerInterval = signposter.beginInterval("Register", id: signposter.makeSignpostID()) - let context = try await DocumentationContext(bundle: bundle, dataProvider: dataProvider, diagnosticEngine: diagnosticEngine, configuration: configuration) + let context = try await DocumentationContext(bundle: inputs, dataProvider: dataProvider, diagnosticEngine: diagnosticEngine, configuration: configuration) signposter.endInterval("Register", registerInterval) let outputConsumer = ConvertFileWritingConsumer( @@ -300,7 +300,7 @@ public struct ConvertAction: AsyncAction { indexer: indexer, enableCustomTemplates: experimentalEnableCustomTemplates, transformForStaticHostingIndexHTML: transformForStaticHosting ? indexHTML : nil, - bundleID: bundle.id + bundleID: inputs.id ) if experimentalModifyCatalogWithGeneratedCuration, let catalogURL = rootURL { @@ -318,7 +318,6 @@ public struct ConvertAction: AsyncAction { do { conversionProblems = try signposter.withIntervalSignpost("Process") { try ConvertActionConverter.convert( - bundle: bundle, context: context, outputConsumer: outputConsumer, sourceRepository: sourceRepository, @@ -347,7 +346,7 @@ public struct ConvertAction: AsyncAction { let tableOfContentsFilename = CatalogTemplateKind.tutorialTopLevelFilename let source = rootURL?.appendingPathComponent(tableOfContentsFilename) var replacements = [Replacement]() - if let tableOfContentsTemplate = CatalogTemplateKind.tutorialTemplateFiles(bundle.displayName)[tableOfContentsFilename] { + if let tableOfContentsTemplate = CatalogTemplateKind.tutorialTemplateFiles(inputs.displayName)[tableOfContentsFilename] { replacements.append( Replacement( range: .init(line: 1, column: 1, source: source) ..< .init(line: 1, column: 1, source: source), @@ -438,7 +437,7 @@ public struct ConvertAction: AsyncAction { context: context, indexer: nil, transformForStaticHostingIndexHTML: nil, - bundleID: bundle.id + bundleID: inputs.id ) try outputConsumer.consume(benchmarks: Benchmark.main) diff --git a/Tests/SwiftDocCTests/DeprecatedDiagnosticsDigestWarningTests.swift b/Tests/SwiftDocCTests/DeprecatedDiagnosticsDigestWarningTests.swift index f8875ee29..8cfbad65d 100644 --- a/Tests/SwiftDocCTests/DeprecatedDiagnosticsDigestWarningTests.swift +++ b/Tests/SwiftDocCTests/DeprecatedDiagnosticsDigestWarningTests.swift @@ -23,12 +23,10 @@ class DeprecatedDiagnosticsDigestWarningTests: XCTestCase { An empty root page """) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) - + let (_, context) = try await loadBundle(catalog: catalog) let outputConsumer = TestOutputConsumer() _ = try ConvertActionConverter.convert( - bundle: bundle, context: context, outputConsumer: outputConsumer, sourceRepository: nil, @@ -49,12 +47,10 @@ class DeprecatedDiagnosticsDigestWarningTests: XCTestCase { This link will result in a warning: ``NotFound``. """) ]) - let (bundle, context) = try await loadBundle(catalog: catalog) - + let (_, context) = try await loadBundle(catalog: catalog) let outputConsumer = TestOutputConsumer() _ = try ConvertActionConverter.convert( - bundle: bundle, context: context, outputConsumer: outputConsumer, sourceRepository: nil, diff --git a/Tests/SwiftDocCTests/TestRenderNodeOutputConsumer.swift b/Tests/SwiftDocCTests/TestRenderNodeOutputConsumer.swift index 67c0f5e3a..c9eca9a9e 100644 --- a/Tests/SwiftDocCTests/TestRenderNodeOutputConsumer.swift +++ b/Tests/SwiftDocCTests/TestRenderNodeOutputConsumer.swift @@ -89,15 +89,13 @@ extension XCTestCase { sourceRepository: SourceRepository? = nil, configureBundle: ((URL) throws -> Void)? = nil ) async throws -> TestRenderNodeOutputConsumer { - let (_, bundle, context) = try await testBundleAndContext( + let (_, _, context) = try await testBundleAndContext( copying: bundleName, configureBundle: configureBundle ) - let outputConsumer = TestRenderNodeOutputConsumer() _ = try ConvertActionConverter.convert( - bundle: bundle, context: context, outputConsumer: outputConsumer, sourceRepository: sourceRepository, diff --git a/Tests/SwiftDocCUtilitiesTests/MergeActionTests.swift b/Tests/SwiftDocCUtilitiesTests/MergeActionTests.swift index 0853d154e..21cb1b150 100644 --- a/Tests/SwiftDocCUtilitiesTests/MergeActionTests.swift +++ b/Tests/SwiftDocCUtilitiesTests/MergeActionTests.swift @@ -876,13 +876,13 @@ class MergeActionTests: XCTestCase { try fileSystem.createDirectory(at: catalogDir, withIntermediateDirectories: true) try fileSystem.addFolder(catalog, basePath: catalogDir.deletingLastPathComponent()) - let (bundle, dataProvider) = try DocumentationContext.InputsProvider(fileManager: fileSystem) + let (inputs, dataProvider) = try DocumentationContext.InputsProvider(fileManager: fileSystem) .inputsAndDataProvider(startingPoint: catalogDir, options: .init()) - XCTAssertEqual(bundle.miscResourceURLs.map(\.lastPathComponent), [ + XCTAssertEqual(inputs.miscResourceURLs.map(\.lastPathComponent), [ "\(name.lowercased())-card.png", ]) - let context = try await DocumentationContext(bundle: bundle, dataProvider: dataProvider, configuration: .init()) + let context = try await DocumentationContext(bundle: inputs, dataProvider: dataProvider, configuration: .init()) XCTAssert( context.problems.filter { $0.diagnostic.identifier != "org.swift.docc.SummaryContainsLink" }.isEmpty, @@ -893,11 +893,11 @@ class MergeActionTests: XCTestCase { let outputPath = baseOutputDir.appendingPathComponent("\(name).doccarchive", isDirectory: true) let realTempURL = try createTemporaryDirectory() // The navigator builder only support real file systems - let indexer = try ConvertAction.Indexer(outputURL: realTempURL, bundleID: bundle.id) + let indexer = try ConvertAction.Indexer(outputURL: realTempURL, bundleID: inputs.id) - let outputConsumer = ConvertFileWritingConsumer(targetFolder: outputPath, bundleRootFolder: catalogDir, fileManager: fileSystem, context: context, indexer: indexer, transformForStaticHostingIndexHTML: nil, bundleID: bundle.id) + let outputConsumer = ConvertFileWritingConsumer(targetFolder: outputPath, bundleRootFolder: catalogDir, fileManager: fileSystem, context: context, indexer: indexer, transformForStaticHostingIndexHTML: nil, bundleID: inputs.id) - let convertProblems = try ConvertActionConverter.convert(bundle: bundle, context: context, outputConsumer: outputConsumer, sourceRepository: nil, emitDigest: false, documentationCoverageOptions: .noCoverage) + let convertProblems = try ConvertActionConverter.convert(context: context, outputConsumer: outputConsumer, sourceRepository: nil, emitDigest: false, documentationCoverageOptions: .noCoverage) XCTAssert(convertProblems.isEmpty, "Unexpected problems: \(context.problems.map(\.diagnostic.summary).joined(separator: "\n"))", file: file, line: line) let navigatorProblems = indexer.finalize(emitJSON: true, emitLMDB: false) From b50bc1aa419de1913b14a1ac6590be1e03296120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 12:24:29 +0200 Subject: [PATCH 13/19] Remove redundant "bundle" parameter from AutomaticCuration.seeAlso --- .../Infrastructure/Topic Graph/AutomaticCuration.swift | 3 +-- Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/Topic Graph/AutomaticCuration.swift b/Sources/SwiftDocC/Infrastructure/Topic Graph/AutomaticCuration.swift index be5516727..d0deba797 100644 --- a/Sources/SwiftDocC/Infrastructure/Topic Graph/AutomaticCuration.swift +++ b/Sources/SwiftDocC/Infrastructure/Topic Graph/AutomaticCuration.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2024 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -155,7 +155,6 @@ public struct AutomaticCuration { for node: DocumentationNode, withTraits variantsTraits: Set, context: DocumentationContext, - bundle: DocumentationBundle, renderContext: RenderContext?, renderer: DocumentationContentRenderer ) -> TaskGroup? { diff --git a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift index cddcb3420..d5e42d2c5 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift @@ -806,7 +806,6 @@ public struct RenderNodeTranslator: SemanticVisitor { for: documentationNode, withTraits: allowedTraits, context: context, - bundle: context.inputs, renderContext: renderContext, renderer: contentRenderer ) { @@ -1648,7 +1647,6 @@ public struct RenderNodeTranslator: SemanticVisitor { for: documentationNode, withTraits: allowedTraits, context: context, - bundle: context.inputs, renderContext: renderContext, renderer: contentRenderer ), !seeAlso.references.isEmpty { From a657d32606cdaa402a5c6a9dada5ace5bf2f07c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 13:55:22 +0200 Subject: [PATCH 14/19] Remove redundant "bundle" parameter from RenderNodeTranslator.defaultAvailability --- .../SwiftDocC/Model/Rendering/RenderNodeTranslator.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift index d5e42d2c5..d5a583e43 100644 --- a/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift +++ b/Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift @@ -1240,7 +1240,7 @@ public struct RenderNodeTranslator: SemanticVisitor { node.metadata.extendedModuleVariants = VariantCollection(from: symbol.extendedModuleVariants) - let defaultAvailability = defaultAvailability(for: context.inputs, moduleName: moduleName.symbolName, currentPlatforms: context.configuration.externalMetadata.currentPlatforms)? + let defaultAvailability = defaultAvailability(moduleName: moduleName.symbolName, currentPlatforms: context.configuration.externalMetadata.currentPlatforms)? .filter { $0.unconditionallyUnavailable != true } .sorted(by: AvailabilityRenderOrder.compare) @@ -1805,8 +1805,8 @@ public struct RenderNodeTranslator: SemanticVisitor { } /// The default availability for modules in a given bundle and module. - mutating func defaultAvailability(for bundle: DocumentationBundle, moduleName: String, currentPlatforms: [String: PlatformVersion]?) -> [AvailabilityRenderItem]? { - let identifier = BundleModuleIdentifier(bundle: bundle, moduleName: moduleName) + private mutating func defaultAvailability(moduleName: String, currentPlatforms: [String: PlatformVersion]?) -> [AvailabilityRenderItem]? { + let identifier = BundleModuleIdentifier(bundle: context.inputs, moduleName: moduleName) // Cached availability if let availability = bundleAvailability[identifier] { @@ -1814,7 +1814,7 @@ public struct RenderNodeTranslator: SemanticVisitor { } // Find default module availability if existing - guard let bundleDefaultAvailability = bundle.info.defaultAvailability, + guard let bundleDefaultAvailability = context.inputs.info.defaultAvailability, let moduleAvailability = bundleDefaultAvailability.modules[moduleName] else { return nil } From faaa64990ef63101f90f1756b4e17009c66c59df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 14:02:33 +0200 Subject: [PATCH 15/19] Remove redundant "bundle" parameter from DocumentationCurator --- .../Infrastructure/DocumentationContext.swift | 2 +- .../Infrastructure/DocumentationCurator.swift | 10 +++----- .../DocumentationCuratorTests.swift | 24 +++++++++---------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index 86651dc55..6c354a9a9 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -2457,7 +2457,7 @@ public class DocumentationContext { signposter.endInterval("Curate symbols", signpostHandle) } - var crawler = DocumentationCurator(in: self, bundle: bundle, initial: initial) + var crawler = DocumentationCurator(in: self, initial: initial) for reference in references { try crawler.crawlChildren( diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift b/Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift index 151996567..b470886fd 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2024 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -17,14 +17,10 @@ struct DocumentationCurator { /// The documentation context to crawl. private let context: DocumentationContext - /// The current bundle. - private let bundle: DocumentationBundle - private(set) var problems = [Problem]() - init(in context: DocumentationContext, bundle: DocumentationBundle, initial: Set = []) { + init(in context: DocumentationContext, initial: Set = []) { self.context = context - self.bundle = bundle self.curatedNodes = initial } @@ -99,7 +95,7 @@ struct DocumentationCurator { // - "documentation/CatalogName/ArticleName" switch path.components(separatedBy: "/").count { case 0,1: - return NodeURLGenerator.Path.article(bundleName: bundle.displayName, articleName: path).stringValue + return NodeURLGenerator.Path.article(bundleName: context.inputs.displayName, articleName: path).stringValue case 2: return "\(NodeURLGenerator.Path.documentationFolder)/\(path)" default: diff --git a/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift b/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift index 125b3ff2c..cab832ec1 100644 --- a/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift @@ -28,9 +28,9 @@ class DocumentationCuratorTests: XCTestCase { } func testCrawl() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var crawler = DocumentationCurator(in: context, bundle: bundle) + var crawler = DocumentationCurator(in: context) let mykit = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)) var symbolsWithCustomCuration = [ResolvedTopicReference]() @@ -75,7 +75,7 @@ class DocumentationCuratorTests: XCTestCase { } func testCrawlDiagnostics() async throws { - let (tempCatalogURL, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in + let (tempCatalogURL, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in let extensionFile = url.appendingPathComponent("documentation/myfunction.md") try """ @@ -97,7 +97,7 @@ class DocumentationCuratorTests: XCTestCase { } let extensionFile = tempCatalogURL.appendingPathComponent("documentation/myfunction.md") - var crawler = DocumentationCurator(in: context, bundle: bundle) + var crawler = DocumentationCurator(in: context) let mykit = try context.entity(with: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)) XCTAssertNoThrow(try crawler.crawlChildren(of: mykit.reference, prepareForCuration: { _ in }, relateNodes: { _, _ in })) @@ -286,7 +286,7 @@ class DocumentationCuratorTests: XCTestCase { } func testModuleUnderTechnologyRoot() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "SourceLocations") { url in + let (_, _, context) = try await testBundleAndContext(copying: "SourceLocations") { url in try """ # Root curating a module @@ -303,7 +303,7 @@ class DocumentationCuratorTests: XCTestCase { """.write(to: url.appendingPathComponent("Root.md"), atomically: true, encoding: .utf8) } - let crawler = DocumentationCurator(in: context, bundle: bundle) + let crawler = DocumentationCurator(in: context) XCTAssert(context.problems.isEmpty, "Expected no problems. Found: \(context.problems.map(\.diagnostic.summary))") guard let moduleNode = context.documentationCache["SourceLocations"], @@ -459,9 +459,9 @@ class DocumentationCuratorTests: XCTestCase { } func testSymbolLinkResolving() async throws { - let (bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (_, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - let crawler = DocumentationCurator(in: context, bundle: bundle) + let crawler = DocumentationCurator(in: context) // Resolve top-level symbol in module parent do { @@ -512,9 +512,9 @@ class DocumentationCuratorTests: XCTestCase { } func testLinkResolving() async throws { - let (sourceRoot, bundle, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") + let (sourceRoot, _, context) = try await testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests") - var crawler = DocumentationCurator(in: context, bundle: bundle) + var crawler = DocumentationCurator(in: context) // Resolve and curate an article in module root (absolute link) do { @@ -567,7 +567,7 @@ class DocumentationCuratorTests: XCTestCase { } func testGroupLinkValidation() async throws { - let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { root in + let (_, _, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", excludingPaths: []) { root in // Create a sidecar with invalid group links try! """ # ``SideKit`` @@ -607,7 +607,7 @@ class DocumentationCuratorTests: XCTestCase { """.write(to: root.appendingPathComponent("documentation").appendingPathComponent("api-collection.md"), atomically: true, encoding: .utf8) } - var crawler = DocumentationCurator(in: context, bundle: bundle) + var crawler = DocumentationCurator(in: context) let reference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/SideKit", sourceLanguage: .swift) try crawler.crawlChildren(of: reference, prepareForCuration: {_ in }) { (_, _) in } From 5898c48b66328b8ceab5b6c7abed4f69da307ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 14:04:06 +0200 Subject: [PATCH 16/19] Remove unused DocumentationContext.unregister method --- .../Infrastructure/DocumentationContext.swift | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index 6c354a9a9..79a9877b1 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -2626,21 +2626,6 @@ public class DocumentationContext { analyzeTopicGraph() } - /** - Unregister a documentation bundle with this context and clear any cached resources associated with it. - */ - private func unregister(_ bundle: DocumentationBundle) { - let referencesToRemove = topicGraph.nodes.keys.filter { - $0.bundleID == bundle.id - } - - for reference in referencesToRemove { - topicGraph.edges[reference]?.removeAll(where: { $0.bundleID == bundle.id }) - topicGraph.reverseEdges[reference]?.removeAll(where: { $0.bundleID == bundle.id }) - topicGraph.nodes[reference] = nil - } - } - // MARK: - Getting documentation relationships /** From 061e1db949637540766ba93044dcdee289021680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 14:17:46 +0200 Subject: [PATCH 17/19] Remove redundant "bundle" parameter from PathHierarchyBasedLinkResolver.referencesForSymbols --- .../Infrastructure/DocumentationContext.swift | 2 +- .../PathHierarchyBasedLinkResolver.swift | 8 ++++---- .../Infrastructure/SymbolDisambiguationTests.swift | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index 79a9877b1..3be5fc0c5 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -1014,7 +1014,7 @@ public class DocumentationContext { // Build references for all symbols in all of this module's symbol graphs. let symbolReferences = signposter.withIntervalSignpost("Disambiguate references") { - linkResolver.localResolver.referencesForSymbols(in: symbolGraphLoader.unifiedGraphs, bundle: bundle, context: self) + linkResolver.localResolver.referencesForSymbols(in: symbolGraphLoader.unifiedGraphs, context: self) } // Set the index and cache storage capacity to avoid ad-hoc storage resizing. diff --git a/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchyBasedLinkResolver.swift b/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchyBasedLinkResolver.swift index 597b6af77..652580be2 100644 --- a/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchyBasedLinkResolver.swift +++ b/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchyBasedLinkResolver.swift @@ -264,8 +264,8 @@ final class PathHierarchyBasedLinkResolver { /// /// - Parameters: /// - symbolGraph: The complete symbol graph to walk through. - /// - bundle: The bundle to use when creating symbol references. - func referencesForSymbols(in unifiedGraphs: [String: UnifiedSymbolGraph], bundle: DocumentationBundle, context: DocumentationContext) -> [SymbolGraph.Symbol.Identifier: ResolvedTopicReference] { + /// - context: The context that the symbols are a part of. + func referencesForSymbols(in unifiedGraphs: [String: UnifiedSymbolGraph], context: DocumentationContext) -> [SymbolGraph.Symbol.Identifier: ResolvedTopicReference] { let disambiguatedPaths = pathHierarchy.caseInsensitiveDisambiguatedPaths(includeDisambiguationForUnambiguousChildren: true, includeLanguage: true, allowAdvancedDisambiguation: false) var result: [SymbolGraph.Symbol.Identifier: ResolvedTopicReference] = [:] @@ -280,7 +280,7 @@ final class PathHierarchyBasedLinkResolver { pathComponents.count == componentsCount { let symbolReference = SymbolReference(pathComponents: pathComponents, interfaceLanguages: symbol.sourceLanguages) - return ResolvedTopicReference(symbolReference: symbolReference, moduleName: moduleName, bundle: bundle) + return ResolvedTopicReference(symbolReference: symbolReference, moduleName: moduleName, bundle: context.inputs) } guard let path = disambiguatedPaths[uniqueIdentifier] else { @@ -288,7 +288,7 @@ final class PathHierarchyBasedLinkResolver { } return ResolvedTopicReference( - bundleID: bundle.documentationRootReference.bundleID, + bundleID: context.inputs.documentationRootReference.bundleID, path: NodeURLGenerator.Path.documentationFolder + path, sourceLanguages: symbol.sourceLanguages ) diff --git a/Tests/SwiftDocCTests/Infrastructure/SymbolDisambiguationTests.swift b/Tests/SwiftDocCTests/Infrastructure/SymbolDisambiguationTests.swift index 797ac40e4..160722cda 100644 --- a/Tests/SwiftDocCTests/Infrastructure/SymbolDisambiguationTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/SymbolDisambiguationTests.swift @@ -189,12 +189,12 @@ class SymbolDisambiguationTests: XCTestCase { } func testMixedLanguageFramework() async throws { - let (bundle, context) = try await testBundleAndContext(named: "MixedLanguageFramework") + let (inputs, context) = try await testBundleAndContext(named: "MixedLanguageFramework") - var loader = SymbolGraphLoader(bundle: bundle, dataProvider: context.dataProvider) + var loader = SymbolGraphLoader(bundle: inputs, dataProvider: context.dataProvider) try loader.loadAll() - let references = context.linkResolver.localResolver.referencesForSymbols(in: loader.unifiedGraphs, bundle: bundle, context: context).mapValues(\.path) + let references = context.linkResolver.localResolver.referencesForSymbols(in: loader.unifiedGraphs, context: context).mapValues(\.path) XCTAssertEqual(Set(references.keys), [ SymbolGraph.Symbol.Identifier(precise: "c:@CM@TestFramework@objc(cs)MixedLanguageClassConformingToProtocol(im)mixedLanguageMethod", interfaceLanguage: "swift"), .init(precise: "c:@E@Foo", interfaceLanguage: "swift"), @@ -321,7 +321,7 @@ class SymbolDisambiguationTests: XCTestCase { let uniqueSymbolCount = Set(swiftSymbols.map(\.preciseID) + objectiveCSymbols.map(\.preciseID)).count XCTAssertEqual(unified.symbols.count, uniqueSymbolCount) - let bundle = DocumentationBundle( + let inputs = DocumentationBundle( info: DocumentationBundle.Info( displayName: "SymbolDisambiguationTests", id: "com.test.SymbolDisambiguationTests"), @@ -335,8 +335,8 @@ class SymbolDisambiguationTests: XCTestCase { objcSymbolGraphURL: try JSONEncoder().encode(graph2), ], fallback: nil) - let context = try await DocumentationContext(bundle: bundle, dataProvider: provider) + let context = try await DocumentationContext(bundle: inputs, dataProvider: provider) - return context.linkResolver.localResolver.referencesForSymbols(in: ["SymbolDisambiguationTests": unified], bundle: bundle, context: context) + return context.linkResolver.localResolver.referencesForSymbols(in: ["SymbolDisambiguationTests": unified], context: context) } } From 299719a99e5cc671eec10fcfec2a1545420a91e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 30 Sep 2025 14:28:36 +0200 Subject: [PATCH 18/19] Remove redundant "bundle" parameters from various private DocumentationContext methods --- .../Infrastructure/DocumentationContext.swift | 173 ++++++++---------- 1 file changed, 73 insertions(+), 100 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index 3be5fc0c5..4b64a3224 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -206,19 +206,19 @@ public class DocumentationContext { /// - configuration: A collection of configuration for the created context. /// - Throws: If an error is encountered while registering a documentation bundle. package init( - bundle: DocumentationBundle, + bundle inputs: DocumentationBundle, dataProvider: any DataProvider, diagnosticEngine: DiagnosticEngine = .init(), configuration: Configuration = .init() ) async throws { - self.inputs = bundle + self.inputs = inputs self.dataProvider = dataProvider self.diagnosticEngine = diagnosticEngine self.configuration = configuration self.linkResolver = LinkResolver(dataProvider: dataProvider) - ResolvedTopicReference.enableReferenceCaching(for: bundle.id) - try register(bundle) + ResolvedTopicReference.enableReferenceCaching(for: inputs.id) + try register() } /// Perform semantic analysis on a given `document` at a given `source` location and append any problems found to `problems`. @@ -226,11 +226,10 @@ public class DocumentationContext { /// - Parameters: /// - document: The document to analyze. /// - source: The location of the document. - /// - bundle: The bundle that the document belongs to. /// - problems: A mutable collection of problems to update with any problem encountered during the semantic analysis. /// - Returns: The result of the semantic analysis. - private func analyze(_ document: Document, at source: URL, in bundle: DocumentationBundle, engine: DiagnosticEngine) -> Semantic? { - var analyzer = SemanticAnalyzer(source: source, bundle: bundle) + private func analyze(_ document: Document, at source: URL, engine: DiagnosticEngine) -> Semantic? { + var analyzer = SemanticAnalyzer(source: source, bundle: inputs) let result = analyzer.visit(document) engine.emit(analyzer.problems) return result @@ -305,12 +304,11 @@ public class DocumentationContext { /// /// - Parameters: /// - references: A list of references to local nodes to visit to collect links. - /// - localBundleID: The local bundle ID, used to identify and skip absolute fully qualified local links. - private func preResolveExternalLinks(references: [ResolvedTopicReference], localBundleID: DocumentationBundle.Identifier) { + private func preResolveExternalLinks(references: [ResolvedTopicReference]) { preResolveExternalLinks(semanticObjects: references.compactMap({ reference -> ReferencedSemanticObject? in guard let node = try? entity(with: reference), let semantic = node.semantic else { return nil } return (reference: reference, semantic: semantic) - }), localBundleID: localBundleID) + })) } /// A tuple of a semantic object and its reference in the topic graph. @@ -327,8 +325,7 @@ public class DocumentationContext { /// /// - Parameters: /// - semanticObjects: A list of semantic objects to visit to collect links. - /// - localBundleID: The local bundle ID, used to identify and skip absolute fully qualified local links. - private func preResolveExternalLinks(semanticObjects: [ReferencedSemanticObject], localBundleID: DocumentationBundle.Identifier) { + private func preResolveExternalLinks(semanticObjects: [ReferencedSemanticObject]) { // If there are no external resolvers added we will not resolve any links. guard !configuration.externalDocumentationConfiguration.sources.isEmpty else { return } @@ -336,7 +333,7 @@ public class DocumentationContext { semanticObjects.concurrentPerform { _, semantic in autoreleasepool { // Walk the node and extract external link references. - var externalLinksCollector = ExternalReferenceWalker(localBundleID: localBundleID) + var externalLinksCollector = ExternalReferenceWalker(localBundleID: inputs.id) externalLinksCollector.visit(semantic) // Avoid any synchronization overhead if there are no references to add. @@ -385,7 +382,7 @@ public class DocumentationContext { /** Attempt to resolve links in curation-only documentation, converting any ``TopicReferences`` from `.unresolved` to `.resolved` where possible. */ - private func resolveLinks(curatedReferences: Set, bundle: DocumentationBundle) { + private func resolveLinks(curatedReferences: Set) { let signpostHandle = signposter.beginInterval("Resolve links", id: signposter.makeSignpostID()) defer { signposter.endInterval("Resolve links", signpostHandle) @@ -445,7 +442,7 @@ public class DocumentationContext { for alternateRepresentation in alternateRepresentations { let resolutionResult = resolver.resolve( alternateRepresentation.reference, - in: bundle.rootReference, + in: inputs.rootReference, range: alternateRepresentation.originalMarkup.range, severity: .warning ) @@ -542,12 +539,10 @@ public class DocumentationContext { /// - tutorialTableOfContentsResults: The list of temporary 'tutorial table-of-contents' pages. /// - tutorials: The list of temporary 'tutorial' pages. /// - tutorialArticles: The list of temporary 'tutorialArticle' pages. - /// - bundle: The bundle to resolve links against. private func resolveLinks( tutorialTableOfContents tutorialTableOfContentsResults: [SemanticResult], tutorials: [SemanticResult], - tutorialArticles: [SemanticResult], - bundle: DocumentationBundle + tutorialArticles: [SemanticResult] ) { let signpostHandle = signposter.beginInterval("Resolve links", id: signposter.makeSignpostID()) defer { @@ -698,7 +693,7 @@ public class DocumentationContext { // Articles are resolved in a separate pass } - private func registerDocuments(from bundle: DocumentationBundle) throws -> ( + private func registerDocuments() throws -> ( tutorialTableOfContentsResults: [SemanticResult], tutorials: [SemanticResult], tutorialArticles: [SemanticResult], @@ -718,7 +713,7 @@ public class DocumentationContext { let decodeError = Synchronized<(any Error)?>(nil) // Load and analyze documents concurrently - let analyzedDocuments: [(URL, Semantic)] = bundle.markupURLs.concurrentPerform { url, results in + let analyzedDocuments: [(URL, Semantic)] = inputs.markupURLs.concurrentPerform { url, results in guard decodeError.sync({ $0 == nil }) else { return } do { @@ -733,7 +728,7 @@ public class DocumentationContext { diagnosticEngine.emit(langChecker.problems) } - guard let analyzed = analyze(document, at: url, in: bundle, engine: diagnosticEngine) else { + guard let analyzed = analyze(document, at: url, engine: diagnosticEngine) else { return } @@ -760,8 +755,8 @@ public class DocumentationContext { // Store the references we encounter to ensure they're unique. The file name is currently the only part of the URL considered for the topic reference, so collisions may occur. let (url, analyzed) = analyzedDocument - let path = NodeURLGenerator.pathForSemantic(analyzed, source: url, bundle: bundle) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguage: .swift) + let path = NodeURLGenerator.pathForSemantic(analyzed, source: url, bundle: inputs) + let reference = ResolvedTopicReference(bundleID: inputs.id, path: path, sourceLanguage: .swift) // Since documentation extensions' filenames have no impact on the URL of pages, there is no need to enforce unique filenames for them. // At this point we consider all articles with an H1 containing link a "documentation extension." @@ -885,8 +880,7 @@ public class DocumentationContext { private func nodeWithInitializedContent( reference: ResolvedTopicReference, - match foundDocumentationExtension: DocumentationContext.SemanticResult
?, - bundle: DocumentationBundle + match foundDocumentationExtension: DocumentationContext.SemanticResult
? ) -> DocumentationNode { guard var updatedNode = documentationCache[reference] else { fatalError("A topic reference that has already been resolved should always exist in the cache.") @@ -896,7 +890,7 @@ public class DocumentationContext { updatedNode.initializeSymbolContent( documentationExtension: foundDocumentationExtension?.value, engine: diagnosticEngine, - bundle: bundle + bundle: inputs ) // After merging the documentation extension into the symbol, warn about deprecation summary for non-deprecated symbols. @@ -987,12 +981,8 @@ public class DocumentationContext { diagnosticEngine.emit(result.problems) } - /// Loads all graph files from a given `bundle` and merges them together while building the symbol relationships and loading any available markdown documentation for those symbols. - /// - /// - Parameter bundle: The bundle to load symbol graph files from. - /// - Returns: A pair of the references to all loaded modules and the hierarchy of all the loaded symbol's references. + /// Loads all graph files from the context's inputs and merges them together while building the symbol relationships and loading any available markdown documentation for those symbols. private func registerSymbols( - from bundle: DocumentationBundle, symbolGraphLoader: SymbolGraphLoader, documentationExtensions: [SemanticResult
] ) throws { @@ -1069,7 +1059,7 @@ public class DocumentationContext { // Use the default module kind for this bundle if one was provided, // otherwise fall back to 'Framework' - let moduleKindDisplayName = bundle.info.defaultModuleKind ?? "Framework" + let moduleKindDisplayName = inputs.info.defaultModuleKind ?? "Framework" let moduleSymbol = SymbolGraph.Symbol( identifier: moduleIdentifier, names: SymbolGraph.Symbol.Names(title: moduleName, navigator: nil, subHeading: nil, prose: nil), @@ -1079,7 +1069,7 @@ public class DocumentationContext { kind: SymbolGraph.Symbol.Kind(parsedIdentifier: .module, displayName: moduleKindDisplayName), mixins: [:]) let moduleSymbolReference = SymbolReference(moduleName, interfaceLanguages: moduleInterfaceLanguages, defaultSymbol: moduleSymbol) - moduleReference = ResolvedTopicReference(symbolReference: moduleSymbolReference, moduleName: moduleName, bundle: bundle) + moduleReference = ResolvedTopicReference(symbolReference: moduleSymbolReference, moduleName: moduleName, bundle: inputs) signposter.withIntervalSignpost("Add symbols to topic graph", id: signposter.makeSignpostID()) { addSymbolsToTopicGraph(symbolGraph: unifiedSymbolGraph, url: fileURL, symbolReferences: symbolReferences, moduleReference: moduleReference) @@ -1170,7 +1160,7 @@ public class DocumentationContext { // FIXME: Resolve the link relative to the module https://github.com/swiftlang/swift-docc/issues/516 let reference = TopicReference.unresolved(.init(topicURL: url)) - switch resolve(reference, in: bundle.rootReference, fromSymbolLink: true) { + switch resolve(reference, in: inputs.rootReference, fromSymbolLink: true) { case .success(let resolved): if let existing = uncuratedDocumentationExtensions[resolved] { if symbolsWithMultipleDocumentationExtensionMatches[resolved] == nil { @@ -1235,16 +1225,12 @@ public class DocumentationContext { Array(documentationCache.symbolReferences).concurrentMap { finalReference in // Match the symbol's documentation extension and initialize the node content. let match = uncuratedDocumentationExtensions[finalReference] - let updatedNode = nodeWithInitializedContent( - reference: finalReference, - match: match, - bundle: bundle - ) + let updatedNode = nodeWithInitializedContent(reference: finalReference, match: match) - return (( + return ( node: updatedNode, matchedArticleURL: match?.source - )) + ) } } @@ -1270,14 +1256,14 @@ public class DocumentationContext { } // Resolve any external references first - preResolveExternalLinks(references: Array(moduleReferences.values) + combinedSymbols.keys.compactMap({ documentationCache.reference(symbolID: $0) }), localBundleID: bundle.id) + preResolveExternalLinks(references: Array(moduleReferences.values) + combinedSymbols.keys.compactMap({ documentationCache.reference(symbolID: $0) })) // Look up and add symbols that are _referenced_ in the symbol graph but don't exist in the symbol graph. try resolveExternalSymbols(in: combinedSymbols, relationships: combinedRelationshipsBySelector) for (selector, relationships) in combinedRelationshipsBySelector { // Build relationships in the completed graph - buildRelationships(relationships, selector: selector, bundle: bundle) + buildRelationships(relationships, selector: selector) // Merge into target symbols the member symbols that get rendered on the same page as target. populateOnPageMemberRelationships(from: relationships, selector: selector) } @@ -1292,16 +1278,11 @@ public class DocumentationContext { /// /// - Parameters: /// - symbolGraph: The symbol graph whose symbols to add in-memory relationships to. - /// - bundle: The bundle that the symbols belong to. - /// - problems: A mutable collection of problems to update with any problem encountered while building symbol relationships. + /// - selector: The platform and language selector to build relationships for. /// /// ## See Also /// - ``SymbolGraphRelationshipsBuilder`` - func buildRelationships( - _ relationships: Set, - selector: UnifiedSymbolGraph.Selector, - bundle: DocumentationBundle - ) { + func buildRelationships(_ relationships: Set, selector: UnifiedSymbolGraph.Selector) { // Find all of the relationships which refer to an extended module. let extendedModuleRelationships = ExtendedTypeFormatTransformation.collapsedExtendedModuleRelationships(from: relationships) @@ -1320,7 +1301,7 @@ public class DocumentationContext { SymbolGraphRelationshipsBuilder.addConformanceRelationship( edge: edge, selector: selector, - in: bundle, + in: inputs, localCache: documentationCache, externalCache: externalCache, engine: diagnosticEngine @@ -1330,7 +1311,7 @@ public class DocumentationContext { SymbolGraphRelationshipsBuilder.addImplementationRelationship( edge: edge, selector: selector, - in: bundle, + in: inputs, context: self, localCache: documentationCache, engine: diagnosticEngine @@ -1340,7 +1321,7 @@ public class DocumentationContext { SymbolGraphRelationshipsBuilder.addInheritanceRelationship( edge: edge, selector: selector, - in: bundle, + in: inputs, localCache: documentationCache, externalCache: externalCache, engine: diagnosticEngine @@ -1632,9 +1613,9 @@ public class DocumentationContext { } } - private func registerMiscResources(from bundle: DocumentationBundle) throws { - let miscResources = Set(bundle.miscResourceURLs) - try assetManagers[bundle.id, default: DataAssetManager()].register(data: miscResources) + private func registerMiscResources() throws { + let miscResources = Set(inputs.miscResourceURLs) + try assetManagers[inputs.id, default: DataAssetManager()].register(data: miscResources) } private func registeredAssets(withExtensions extensions: Set? = nil, inContexts contexts: [DataAsset.Context] = DataAsset.Context.allCases, forBundleID bundleID: DocumentationBundle.Identifier) -> [DataAsset] { @@ -1691,11 +1672,11 @@ public class DocumentationContext { } } - private func registerRootPages(from articles: Articles, in bundle: DocumentationBundle) { + private func registerRootPages(from articles: Articles) { // Create a root leaf node for all root page articles for article in articles { // Create the documentation data - guard let (documentation, title) = DocumentationContext.documentationNodeAndTitle(for: article, kind: .collection, in: bundle) else { continue } + guard let (documentation, title) = Self.documentationNodeAndTitle(for: article, kind: .collection, in: inputs) else { continue } let reference = documentation.reference // Create the documentation node @@ -1724,21 +1705,17 @@ public class DocumentationContext { /// /// - Parameters: /// - articles: Articles to register with the documentation cache. - /// - bundle: The bundle containing the articles. /// - Returns: The articles that were registered, with their topic graph node updated to what's been added to the topic graph. - private func registerArticles( - _ articles: DocumentationContext.Articles, - in bundle: DocumentationBundle - ) -> DocumentationContext.Articles { + private func registerArticles(_ articles: DocumentationContext.Articles) -> DocumentationContext.Articles { articles.map { article in - guard let (documentation, title) = DocumentationContext.documentationNodeAndTitle( + guard let (documentation, title) = Self.documentationNodeAndTitle( for: article, // By default, articles are available in the languages the module that's being documented // is available in. It's possible to override that behavior using the `@SupportedLanguage` // directive though; see its documentation for more details. availableSourceLanguages: soleRootModuleReference.map { sourceLanguages(for: $0) }, kind: .article, - in: bundle + in: inputs ) else { return article } @@ -1768,9 +1745,8 @@ public class DocumentationContext { /// /// - Parameters: /// - articles: On input, a list of articles. If an article is used as a root it is removed from this list. - /// - bundle: The bundle containing the articles. - private func synthesizeArticleOnlyRootPage(articles: inout [DocumentationContext.SemanticResult
], bundle: DocumentationBundle) { - let title = bundle.displayName + private func synthesizeArticleOnlyRootPage(articles: inout [DocumentationContext.SemanticResult
]) { + let title = inputs.displayName // An inner helper function to register a new root node from an article func registerAsNewRootNode(_ articleResult: SemanticResult
) { @@ -1778,7 +1754,7 @@ public class DocumentationContext { let title = articleResult.source.deletingPathExtension().lastPathComponent // Create a new root-looking reference let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: inputs.id, path: NodeURLGenerator.Path.documentation(path: title).stringValue, sourceLanguages: [DocumentationContext.defaultLanguage(in: nil /* article-only content has no source language information */)] ) @@ -1797,13 +1773,13 @@ public class DocumentationContext { } let article = Article( markup: articleResult.value.markup, - metadata: Metadata(from: metadataMarkup, for: bundle), + metadata: Metadata(from: metadataMarkup, for: inputs), redirects: articleResult.value.redirects, options: articleResult.value.options ) let graphNode = TopicGraph.Node(reference: reference, kind: .module, source: articleResult.topicGraphNode.source, title: title) - registerRootPages(from: [.init(value: article, source: articleResult.source, topicGraphNode: graphNode)], in: bundle) + registerRootPages(from: [.init(value: article, source: articleResult.source, topicGraphNode: graphNode)]) } if articles.count == 1 { @@ -1817,7 +1793,7 @@ public class DocumentationContext { let path = NodeURLGenerator.Path.documentation(path: title).stringValue let sourceLanguage = DocumentationContext.defaultLanguage(in: []) - let reference = ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguages: [sourceLanguage]) + let reference = ResolvedTopicReference(bundleID: inputs.id, path: path, sourceLanguages: [sourceLanguage]) let graphNode = TopicGraph.Node(reference: reference, kind: .module, source: .external, title: title) topicGraph.addNode(graphNode) @@ -1830,7 +1806,7 @@ public class DocumentationContext { Heading(level: 1, Text(title)), metadataDirectiveMarkup ) - let metadata = Metadata(from: metadataDirectiveMarkup, for: bundle) + let metadata = Metadata(from: metadataDirectiveMarkup, for: inputs) let article = Article(markup: markup, metadata: metadata, redirects: nil, options: [:]) let documentationNode = DocumentationNode( reference: reference, @@ -1850,19 +1826,19 @@ public class DocumentationContext { /// - Parameters: /// - article: The article that will be used to create the returned documentation node. /// - kind: The kind that should be used to create the returned documentation node. - /// - bundle: The documentation bundle this article belongs to. + /// - inputs: The collection of inputs files that the article belongs to. /// - Returns: A documentation node and title for the given article semantic result. static func documentationNodeAndTitle( for article: DocumentationContext.SemanticResult
, availableSourceLanguages: Set? = nil, kind: DocumentationNode.Kind, - in bundle: DocumentationBundle + in inputs: DocumentationBundle ) -> (node: DocumentationNode, title: String)? { guard let articleMarkup = article.value.markup else { return nil } - let path = NodeURLGenerator.pathForSemantic(article.value, source: article.source, bundle: bundle) + let path = NodeURLGenerator.pathForSemantic(article.value, source: article.source, bundle: inputs) // Use the languages specified by the `@SupportedLanguage` directives if present. let availableSourceLanguages = article.value @@ -1882,7 +1858,7 @@ public class DocumentationContext { let defaultSourceLanguage = defaultLanguage(in: availableSourceLanguages) let reference = ResolvedTopicReference( - bundleID: bundle.id, + bundleID: inputs.id, path: path, sourceLanguages: availableSourceLanguages // FIXME: Pages in article-only catalogs should not be inferred as "Swift" as a fallback @@ -1960,11 +1936,11 @@ public class DocumentationContext { /** Register a documentation bundle with this context. */ - private func register(_ bundle: DocumentationBundle) throws { + private func register() throws { try shouldContinueRegistration() let currentFeatureFlags: FeatureFlags? - if let bundleFlags = bundle.info.featureFlags { + if let bundleFlags = inputs.info.featureFlags { currentFeatureFlags = FeatureFlags.current FeatureFlags.current.loadFlagsFromBundle(bundleFlags) @@ -2007,7 +1983,7 @@ public class DocumentationContext { discoveryGroup.async(queue: discoveryQueue) { [unowned self] in symbolGraphLoader = SymbolGraphLoader( - bundle: bundle, + bundle: inputs, dataProvider: dataProvider, symbolGraphTransformer: configuration.convertServiceConfiguration.symbolGraphTransformer ) @@ -2019,7 +1995,7 @@ public class DocumentationContext { hierarchyBasedResolver = signposter.withIntervalSignpost("Build PathHierarchy", id: signposter.makeSignpostID()) { PathHierarchyBasedLinkResolver(pathHierarchy: PathHierarchy( symbolGraphLoader: symbolGraphLoader, - bundleName: urlReadablePath(bundle.displayName), + bundleName: urlReadablePath(inputs.displayName), knownDisambiguatedPathComponents: configuration.convertServiceConfiguration.knownDisambiguatedSymbolPathComponents )) } @@ -2037,7 +2013,7 @@ public class DocumentationContext { discoveryGroup.async(queue: discoveryQueue) { [unowned self] in do { try signposter.withIntervalSignpost("Load resources", id: signposter.makeSignpostID()) { - try self.registerMiscResources(from: bundle) + try self.registerMiscResources() } } catch { // Pipe the error out of the dispatch queue. @@ -2063,7 +2039,7 @@ public class DocumentationContext { discoveryGroup.async(queue: discoveryQueue) { [unowned self] in do { result = try signposter.withIntervalSignpost("Load documents", id: signposter.makeSignpostID()) { - try self.registerDocuments(from: bundle) + try self.registerDocuments() } } catch { // Pipe the error out of the dispatch queue. @@ -2137,7 +2113,7 @@ public class DocumentationContext { } self.linkResolver.localResolver = hierarchyBasedResolver - hierarchyBasedResolver.addMappingForRoots(bundle: bundle) + hierarchyBasedResolver.addMappingForRoots(bundle: inputs) for tutorial in tutorials { hierarchyBasedResolver.addTutorial(tutorial) } @@ -2148,8 +2124,8 @@ public class DocumentationContext { hierarchyBasedResolver.addTutorialTableOfContents(tutorialTableOfContents) } - registerRootPages(from: rootPageArticles, in: bundle) - try registerSymbols(from: bundle, symbolGraphLoader: symbolGraphLoader, documentationExtensions: documentationExtensions) + registerRootPages(from: rootPageArticles) + try registerSymbols(symbolGraphLoader: symbolGraphLoader, documentationExtensions: documentationExtensions) // We don't need to keep the loader in memory after we've registered all symbols. symbolGraphLoader = nil @@ -2159,7 +2135,7 @@ public class DocumentationContext { !otherArticles.isEmpty, !configuration.convertServiceConfiguration.allowsRegisteringArticlesWithoutTechnologyRoot { - synthesizeArticleOnlyRootPage(articles: &otherArticles, bundle: bundle) + synthesizeArticleOnlyRootPage(articles: &otherArticles) } // Keep track of the root modules registered from symbol graph files, we'll need them to automatically @@ -2174,7 +2150,7 @@ public class DocumentationContext { // Articles that will be automatically curated can be resolved but they need to be pre registered before resolving links. let rootNodeForAutomaticCuration = soleRootModuleReference.flatMap(topicGraph.nodeWithReference(_:)) if configuration.convertServiceConfiguration.allowsRegisteringArticlesWithoutTechnologyRoot || rootNodeForAutomaticCuration != nil { - otherArticles = registerArticles(otherArticles, in: bundle) + otherArticles = registerArticles(otherArticles) try shouldContinueRegistration() } @@ -2182,14 +2158,12 @@ public class DocumentationContext { preResolveExternalLinks(semanticObjects: tutorialTableOfContentsResults.map(referencedSemanticObject) + tutorials.map(referencedSemanticObject) + - tutorialArticles.map(referencedSemanticObject), - localBundleID: bundle.id) + tutorialArticles.map(referencedSemanticObject)) resolveLinks( tutorialTableOfContents: tutorialTableOfContentsResults, tutorials: tutorials, - tutorialArticles: tutorialArticles, - bundle: bundle + tutorialArticles: tutorialArticles ) // After the resolving links in tutorial content all the local references are known and can be added to the referenceIndex for fast lookup. @@ -2202,7 +2176,7 @@ public class DocumentationContext { } try shouldContinueRegistration() - var allCuratedReferences = try crawlSymbolCuration(in: linkResolver.localResolver.topLevelSymbols(), bundle: bundle) + var allCuratedReferences = try crawlSymbolCuration(in: linkResolver.localResolver.topLevelSymbols()) // Store the list of manually curated references if doc coverage is on. if configuration.experimentalCoverageConfiguration.shouldStoreManuallyCuratedReferences { @@ -2217,13 +2191,13 @@ public class DocumentationContext { } // Crawl the rest of the symbols that haven't been crawled so far in hierarchy pre-order. - allCuratedReferences = try crawlSymbolCuration(in: automaticallyCurated.map(\.symbol), bundle: bundle, initial: allCuratedReferences) + allCuratedReferences = try crawlSymbolCuration(in: automaticallyCurated.map(\.symbol), initial: allCuratedReferences) // Automatically curate articles that haven't been manually curated // Article curation is only done automatically if there is only one root module if let rootNode = rootNodeForAutomaticCuration { let articleReferences = try autoCurateArticles(otherArticles, startingFrom: rootNode) - allCuratedReferences = try crawlSymbolCuration(in: articleReferences, bundle: bundle, initial: allCuratedReferences) + allCuratedReferences = try crawlSymbolCuration(in: articleReferences, initial: allCuratedReferences) } // Remove curation paths that have been created automatically above @@ -2241,14 +2215,14 @@ public class DocumentationContext { linkResolver.localResolver.addAnchorForSymbols(localCache: documentationCache) // Fifth, resolve links in nodes that are added solely via curation - preResolveExternalLinks(references: Array(allCuratedReferences), localBundleID: bundle.id) - resolveLinks(curatedReferences: allCuratedReferences, bundle: bundle) + preResolveExternalLinks(references: Array(allCuratedReferences)) + resolveLinks(curatedReferences: allCuratedReferences) if configuration.convertServiceConfiguration.fallbackResolver != nil { // When the ``ConvertService`` builds documentation for a single page there won't be a module or root // reference to auto-curate the page under, so the regular local link resolution code path won't visit // the single page. To ensure that links are resolved, explicitly visit all pages. - resolveLinks(curatedReferences: Set(knownPages), bundle: bundle) + resolveLinks(curatedReferences: Set(knownPages)) } // We should use a read-only context during render time (rdar://65130130). @@ -2447,11 +2421,10 @@ public class DocumentationContext { /// Crawls the hierarchy of the given list of nodes, adding relationships in the topic graph for all resolvable task group references. /// - Parameters: /// - references: A list of references to crawl. - /// - bundle: A documentation bundle. /// - initial: A list of references to skip when crawling. /// - Returns: The references of all the symbols that were curated. @discardableResult - func crawlSymbolCuration(in references: [ResolvedTopicReference], bundle: DocumentationBundle, initial: Set = []) throws -> Set { + func crawlSymbolCuration(in references: [ResolvedTopicReference], initial: Set = []) throws -> Set { let signpostHandle = signposter.beginInterval("Curate symbols", id: signposter.makeSignpostID()) defer { signposter.endInterval("Curate symbols", signpostHandle) From e1c04b7b04ca94cded0c0a24e5d1a8407d74ef39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Fri, 10 Oct 2025 09:48:55 +0200 Subject: [PATCH 19/19] Remove to local "bundle" variables --- .../DocumentationService/Convert/ConvertService.swift | 5 ++--- Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift index 8eef7e671..f55a9fe80 100644 --- a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift +++ b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift @@ -242,12 +242,11 @@ public struct ConvertService: DocumentationService { .compactMap { (value, isDocumentationExtensionContent) -> (ResolvedTopicReference, RenderReferenceStore.TopicContent)? in let (topicReference, article) = value - let bundle = context.inputs - guard bundle.id == topicReference.bundleID else { return nil } + guard context.inputs.id == topicReference.bundleID else { return nil } let renderer = DocumentationContentRenderer(context: context) let documentationNodeKind: DocumentationNode.Kind = isDocumentationExtensionContent ? .unknownSymbol : .article - let overridingDocumentationNode = DocumentationContext.documentationNodeAndTitle(for: article, kind: documentationNodeKind, in: bundle)?.node + let overridingDocumentationNode = DocumentationContext.documentationNodeAndTitle(for: article, kind: documentationNodeKind, in: context.inputs)?.node var dependencies = RenderReferenceDependencies() let renderReference = renderer.renderReference(for: topicReference, with: overridingDocumentationNode, dependencies: &dependencies) diff --git a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift index 93e00e526..e6407e905 100644 --- a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift +++ b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift @@ -431,12 +431,11 @@ public extension DocumentationNode { renderNode: RenderNode, includeTaskGroups: Bool = true ) -> [LinkDestinationSummary] { - let bundle = context.inputs - guard bundle.id == reference.bundleID else { + guard context.inputs.id == reference.bundleID else { // Don't return anything for external references that don't have a bundle in the context. return [] } - let urlGenerator = PresentationURLGenerator(context: context, baseURL: bundle.baseURL) + let urlGenerator = PresentationURLGenerator(context: context, baseURL: context.inputs.baseURL) let relativePresentationURL = urlGenerator.presentationURLForReference(reference).withoutHostAndPortAndScheme() var compiler = RenderContentCompiler(context: context, identifier: reference)