Skip to content

Commit 26dfb6b

Browse files
committed
Merge branch 'main' into remove-long-disabled-integration-test
# Conflicts: # Tests/SwiftDocCUtilitiesTests/PreviewActionIntegrationTests.swift
2 parents d83032f + 7317f80 commit 26dfb6b

File tree

77 files changed

+831
-895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+831
-895
lines changed

Sources/SwiftDocC/Infrastructure/Diagnostics/DiagnosticEngine.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ public final class DiagnosticEngine {
2727
///
2828
/// This filter level is inclusive, i.e. if a level of ``DiagnosticSeverity/information`` is specified,
2929
/// diagnostics with a severity up to and including `.information` will be printed.
30-
public var filterLevel: DiagnosticSeverity {
31-
didSet {
32-
self.filter = { $0.diagnostic.severity.rawValue <= self.filterLevel.rawValue }
33-
}
34-
}
30+
public var filterLevel: DiagnosticSeverity
3531

3632
/// Returns a Boolean value indicating whether the engine contains a consumer that satisfies the given predicate.
3733
/// - Parameter predicate: A closure that takes one of the engine's consumers as its argument and returns a Boolean value that indicates whether the passed consumer represents a match.
@@ -46,7 +42,9 @@ public final class DiagnosticEngine {
4642
private let treatWarningsAsErrors: Bool
4743

4844
/// Determines which problems should be emitted.
49-
private var filter: (Problem) -> Bool
45+
private func shouldEmit(_ problem: Problem) -> Bool {
46+
problem.diagnostic.severity.rawValue <= filterLevel.rawValue
47+
}
5048

5149
/// A convenience accessor for retrieving all of the diagnostics this engine currently holds.
5250
public var problems: [Problem] {
@@ -57,7 +55,6 @@ public final class DiagnosticEngine {
5755
public init(filterLevel: DiagnosticSeverity = .warning, treatWarningsAsErrors: Bool = false) {
5856
self.filterLevel = filterLevel
5957
self.treatWarningsAsErrors = treatWarningsAsErrors
60-
self.filter = { $0.diagnostic.severity.rawValue <= filterLevel.rawValue }
6158
}
6259

6360
/// Removes all of the encountered diagnostics from this engine.
@@ -85,7 +82,7 @@ public final class DiagnosticEngine {
8582
}
8683
return problem
8784
}
88-
let filteredProblems = mappedProblems.filter(filter)
85+
let filteredProblems = mappedProblems.filter(shouldEmit)
8986
guard !filteredProblems.isEmpty else { return }
9087

9188
if filteredProblems.containsErrors {

Sources/SwiftDocC/Infrastructure/DocumentationBundle.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public struct DocumentationBundle {
128128
self.themeSettings = themeSettings
129129
self.rootReference = ResolvedTopicReference(bundleIdentifier: info.identifier, path: "/", sourceLanguage: .swift)
130130
self.documentationRootReference = ResolvedTopicReference(bundleIdentifier: info.identifier, path: NodeURLGenerator.Path.documentationFolder, sourceLanguage: .swift)
131-
self.tutorialsRootReference = ResolvedTopicReference(bundleIdentifier: info.identifier, path: NodeURLGenerator.Path.tutorialsFolder, sourceLanguage: .swift)
132-
self.technologyTutorialsRootReference = tutorialsRootReference.appendingPath(urlReadablePath(info.displayName))
131+
self.tutorialTableOfContentsContainer = ResolvedTopicReference(bundleIdentifier: info.identifier, path: NodeURLGenerator.Path.tutorialsFolder, sourceLanguage: .swift)
132+
self.tutorialsContainerReference = tutorialTableOfContentsContainer.appendingPath(urlReadablePath(info.displayName))
133133
self.articlesDocumentationRootReference = documentationRootReference.appendingPath(urlReadablePath(info.displayName))
134134
}
135135

@@ -154,12 +154,22 @@ public struct DocumentationBundle {
154154
/// Default path to resolve symbol links.
155155
public private(set) var documentationRootReference: ResolvedTopicReference
156156

157-
/// Default path to resolve technology links.
158-
public var tutorialsRootReference: ResolvedTopicReference
157+
@available(*, deprecated, renamed: "tutorialTableOfContentsContainer", message: "Use 'tutorialTableOfContentsContainer' instead. This deprecated API will be removed after 6.2 is released")
158+
public var tutorialsRootReference: ResolvedTopicReference {
159+
tutorialTableOfContentsContainer
160+
}
161+
162+
/// Default path to resolve tutorial table-of-contents links.
163+
public var tutorialTableOfContentsContainer: ResolvedTopicReference
164+
165+
@available(*, deprecated, renamed: "tutorialsContainerReference", message: "Use 'tutorialsContainerReference' instead. This deprecated API will be removed after 6.2 is released")
166+
public var technologyTutorialsRootReference: ResolvedTopicReference {
167+
tutorialsContainerReference
168+
}
169+
170+
/// Default path to resolve tutorial links.
171+
public var tutorialsContainerReference: ResolvedTopicReference
159172

160-
/// Default path to resolve tutorials.
161-
public var technologyTutorialsRootReference: ResolvedTopicReference
162-
163173
/// Default path to resolve articles.
164174
public var articlesDocumentationRootReference: ResolvedTopicReference
165175
}

Sources/SwiftDocC/Infrastructure/DocumentationContext+Breadcrumbs.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ extension DocumentationContext {
1313
struct PathOptions: OptionSet {
1414
let rawValue: Int
1515

16-
/// Prefer a technology as the canonical path over a shorter path.
17-
static let preferTechnologyRoot = PathOptions(rawValue: 1 << 0)
16+
/// Prefer a tutorial table-of-contents page as the canonical path over a shorter path.
17+
static let preferTutorialTableOfContentsRoot = PathOptions(rawValue: 1 << 0)
1818
}
1919

2020
/// Finds all finite (acyclic) paths, also called "breadcrumbs", to the given reference in the topic graph.
@@ -38,9 +38,9 @@ extension DocumentationContext {
3838
// To match the caller's expectations we remove the starting point and then flip the paths.
3939
.map { $0.dropFirst().reversed() }
4040
.sorted { (lhs, rhs) -> Bool in
41-
// Order a path rooted in a technology as the canonical one.
42-
if options.contains(.preferTechnologyRoot), let first = lhs.first {
43-
return try! entity(with: first).semantic is Technology
41+
// Order a path rooted in a tutorial table-of-contents as the canonical one.
42+
if options.contains(.preferTutorialTableOfContentsRoot), let first = lhs.first {
43+
return try! entity(with: first).semantic is TutorialTableOfContents
4444
}
4545

4646
return breadcrumbsAreInIncreasingOrder(lhs, rhs)

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
136136
/// The set of all manually curated references if `shouldStoreManuallyCuratedReferences` was true at the time of processing and has remained `true` since.. Nil if curation has not been processed yet.
137137
public private(set) var manuallyCuratedReferences: Set<ResolvedTopicReference>?
138138

139-
/// The root technology nodes of the Topic Graph.
139+
@available(*, deprecated, renamed: "tutorialTableOfContentsReferences", message: "Use 'tutorialTableOfContentsReferences' This deprecated API will be removed after 6.2 is released")
140140
public var rootTechnologies: [ResolvedTopicReference] {
141+
tutorialTableOfContentsReferences
142+
}
143+
144+
/// The tutorial table-of-contents nodes in the topic graph.
145+
public var tutorialTableOfContentsReferences: [ResolvedTopicReference] {
141146
return topicGraph.nodes.values.compactMap { node in
142-
guard node.kind == .technology && parents(of: node.reference).isEmpty else {
147+
guard node.kind == .tutorialTableOfContents && parents(of: node.reference).isEmpty else {
143148
return nil
144149
}
145150
return node.reference
@@ -606,65 +611,65 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
606611
/// up in the context, not from the arrays that was passed as arguments.
607612
///
608613
/// - Parameters:
609-
/// - technologies: The list of temporary 'technology' pages.
614+
/// - tutorialTableOfContentsResults: The list of temporary 'tutorial table-of-contents' pages.
610615
/// - tutorials: The list of temporary 'tutorial' pages.
611616
/// - tutorialArticles: The list of temporary 'tutorialArticle' pages.
612617
/// - bundle: The bundle to resolve links against.
613-
private func resolveLinks(technologies: [SemanticResult<Technology>],
614-
tutorials: [SemanticResult<Tutorial>],
615-
tutorialArticles: [SemanticResult<TutorialArticle>],
616-
bundle: DocumentationBundle) {
617-
618+
private func resolveLinks(
619+
tutorialTableOfContents tutorialTableOfContentsResults: [SemanticResult<TutorialTableOfContents>],
620+
tutorials: [SemanticResult<Tutorial>],
621+
tutorialArticles: [SemanticResult<TutorialArticle>],
622+
bundle: DocumentationBundle
623+
) {
618624
let sourceLanguages = soleRootModuleReference.map { self.sourceLanguages(for: $0) } ?? [.swift]
619625

620-
// Technologies
621-
622-
for technologyResult in technologies {
626+
// Tutorial table-of-contents
627+
628+
for tableOfContentsResult in tutorialTableOfContentsResults {
623629
autoreleasepool {
624-
let url = technologyResult.source
625-
let unresolvedTechnology = technologyResult.value
630+
let url = tableOfContentsResult.source
626631
var resolver = ReferenceResolver(context: self, bundle: bundle)
627-
let technology = resolver.visit(unresolvedTechnology) as! Technology
632+
let tableOfContents = resolver.visit(tableOfContentsResult.value) as! TutorialTableOfContents
628633
diagnosticEngine.emit(resolver.problems)
629634

630635
// Add to document map
631-
documentLocationMap[url] = technologyResult.topicGraphNode.reference
632-
633-
let technologyReference = technologyResult.topicGraphNode.reference.withSourceLanguages(sourceLanguages)
636+
documentLocationMap[url] = tableOfContentsResult.topicGraphNode.reference
634637

635-
let technologyNode = DocumentationNode(
636-
reference: technologyReference,
637-
kind: .technology,
638+
let tableOfContentsReference = tableOfContentsResult.topicGraphNode.reference.withSourceLanguages(sourceLanguages)
639+
640+
let tutorialTableOfContentsNode = DocumentationNode(
641+
reference: tableOfContentsReference,
642+
kind: .tutorialTableOfContents,
638643
sourceLanguage: Self.defaultLanguage(in: sourceLanguages),
639644
availableSourceLanguages: sourceLanguages,
640-
name: .conceptual(title: technology.intro.title),
641-
markup: technology.originalMarkup,
642-
semantic: technology
645+
name: .conceptual(title: tableOfContents.intro.title),
646+
markup: tableOfContents.originalMarkup,
647+
semantic: tableOfContents
643648
)
644-
documentationCache[technologyReference] = technologyNode
649+
documentationCache[tableOfContentsReference] = tutorialTableOfContentsNode
645650

646-
// Update the reference in the topic graph with the technology's available languages.
651+
// Update the reference in the topic graph with the table-of-contents page's available languages.
647652
topicGraph.updateReference(
648-
technologyResult.topicGraphNode.reference,
649-
newReference: technologyReference
653+
tableOfContentsResult.topicGraphNode.reference,
654+
newReference: tableOfContentsReference
650655
)
651656

652657
let anonymousVolumeName = "$volume"
653658

654-
for volume in technology.volumes {
659+
for volume in tableOfContents.volumes {
655660
// Graph node: Volume
656-
let volumeReference = technologyNode.reference.appendingPath(volume.name ?? anonymousVolumeName)
661+
let volumeReference = tutorialTableOfContentsNode.reference.appendingPath(volume.name ?? anonymousVolumeName)
657662
let volumeNode = TopicGraph.Node(reference: volumeReference, kind: .volume, source: .file(url: url), title: volume.name ?? anonymousVolumeName)
658663
topicGraph.addNode(volumeNode)
659664

660-
// Graph edge: Technology -> Volume
661-
topicGraph.addEdge(from: technologyResult.topicGraphNode, to: volumeNode)
665+
// Graph edge: Tutorial table-of-contents -> Volume
666+
topicGraph.addEdge(from: tableOfContentsResult.topicGraphNode, to: volumeNode)
662667

663668
for chapter in volume.chapters {
664669
// Graph node: Module
665670
let baseNodeReference: ResolvedTopicReference
666671
if volume.name == nil {
667-
baseNodeReference = technologyNode.reference
672+
baseNodeReference = tutorialTableOfContentsNode.reference
668673
} else {
669674
baseNodeReference = volumeNode.reference
670675
}
@@ -761,15 +766,15 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
761766
}
762767

763768
private func registerDocuments(from bundle: DocumentationBundle) throws -> (
764-
technologies: [SemanticResult<Technology>],
769+
tutorialTableOfContentsResults: [SemanticResult<TutorialTableOfContents>],
765770
tutorials: [SemanticResult<Tutorial>],
766771
tutorialArticles: [SemanticResult<TutorialArticle>],
767772
articles: [SemanticResult<Article>],
768773
documentationExtensions: [SemanticResult<Article>]
769774
) {
770775
// First, try to understand the basic structure of the document by
771776
// analyzing it and putting references in as "unresolved".
772-
var technologies = [SemanticResult<Technology>]()
777+
var tutorialTableOfContentsResults = [SemanticResult<TutorialTableOfContents>]()
773778
var tutorials = [SemanticResult<Tutorial>]()
774779
var tutorialArticles = [SemanticResult<TutorialArticle>]()
775780
var articles = [SemanticResult<Article>]()
@@ -857,11 +862,11 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
857862
Add all topic graph nodes up front before resolution starts, because
858863
there may be circular linking.
859864
*/
860-
if let technology = analyzed as? Technology {
861-
let topicGraphNode = TopicGraph.Node(reference: reference, kind: .technology, source: .file(url: url), title: technology.intro.title)
865+
if let tableOfContents = analyzed as? TutorialTableOfContents {
866+
let topicGraphNode = TopicGraph.Node(reference: reference, kind: .tutorialTableOfContents, source: .file(url: url), title: tableOfContents.intro.title)
862867
topicGraph.addNode(topicGraphNode)
863-
let result = SemanticResult(value: technology, source: url, topicGraphNode: topicGraphNode)
864-
technologies.append(result)
868+
let result = SemanticResult(value: tableOfContents, source: url, topicGraphNode: topicGraphNode)
869+
tutorialTableOfContentsResults.append(result)
865870
} else if let tutorial = analyzed as? Tutorial {
866871
let topicGraphNode = TopicGraph.Node(reference: reference, kind: .tutorial, source: .file(url: url), title: tutorial.title ?? "")
867872
topicGraph.addNode(topicGraphNode)
@@ -920,7 +925,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
920925
}
921926
}
922927

923-
return (technologies, tutorials, tutorialArticles, articles, documentationExtensions)
928+
return (tutorialTableOfContentsResults, tutorials, tutorialArticles, articles, documentationExtensions)
924929
}
925930

926931
private func insertLandmarks(_ landmarks: some Sequence<Landmark>, from topicGraphNode: TopicGraph.Node, source url: URL) {
@@ -1331,6 +1336,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
13311336
}
13321337

13331338
private func shouldContinueRegistration() throws {
1339+
try Task.checkCancellation()
13341340
guard isRegistrationEnabled.sync({ $0 }) else {
13351341
throw ContextError.registrationDisabled
13361342
}
@@ -1773,6 +1779,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
17731779
///
17741780
/// When given `false` the context will try to cancel as quick as possible
17751781
/// any ongoing bundle registrations.
1782+
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released")
17761783
public func setRegistrationEnabled(_ value: Bool) {
17771784
isRegistrationEnabled.sync({ $0 = value })
17781785
}
@@ -2098,7 +2105,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
20982105
// symbols or attempt to resolve links/references since the topic graph may not contain all documents
20992106
// or all symbols yet.
21002107
var result: (
2101-
technologies: [SemanticResult<Technology>],
2108+
tutorialTableOfContentsResults: [SemanticResult<TutorialTableOfContents>],
21022109
tutorials: [SemanticResult<Tutorial>],
21032110
tutorialArticles: [SemanticResult<TutorialArticle>],
21042111
articles: [SemanticResult<Article>],
@@ -2137,7 +2144,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
21372144
}
21382145

21392146
// All discovery went well, process the inputs.
2140-
let (technologies, tutorials, tutorialArticles, allArticles, documentationExtensions) = result
2147+
let (tutorialTableOfContentsResults, tutorials, tutorialArticles, allArticles, documentationExtensions) = result
21412148
var (otherArticles, rootPageArticles) = splitArticles(allArticles)
21422149

21432150
let globalOptions = (allArticles + documentationExtensions).compactMap { article in
@@ -2185,8 +2192,8 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
21852192
for article in tutorialArticles {
21862193
hierarchyBasedResolver.addTutorialArticle(article)
21872194
}
2188-
for technology in technologies {
2189-
hierarchyBasedResolver.addTechnology(technology)
2195+
for tutorialTableOfContents in tutorialTableOfContentsResults {
2196+
hierarchyBasedResolver.addTutorialTableOfContents(tutorialTableOfContents)
21902197
}
21912198

21922199
registerRootPages(from: rootPageArticles, in: bundle)
@@ -2221,13 +2228,13 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
22212228

22222229
// Third, any processing that relies on resolving other content is done, mainly resolving links.
22232230
preResolveExternalLinks(semanticObjects:
2224-
technologies.map(referencedSemanticObject) +
2231+
tutorialTableOfContentsResults.map(referencedSemanticObject) +
22252232
tutorials.map(referencedSemanticObject) +
22262233
tutorialArticles.map(referencedSemanticObject),
22272234
localBundleID: bundle.identifier)
22282235

22292236
resolveLinks(
2230-
technologies: technologies,
2237+
tutorialTableOfContents: tutorialTableOfContentsResults,
22312238
tutorials: tutorials,
22322239
tutorialArticles: tutorialArticles,
22332240
bundle: bundle
@@ -2913,8 +2920,8 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
29132920
extension DocumentationContext {
29142921

29152922
/// The nodes that are allowed to be roots in the topic graph.
2916-
static var allowedRootNodeKinds: [DocumentationNode.Kind] = [.technology, .module]
2917-
2923+
static var allowedRootNodeKinds: [DocumentationNode.Kind] = [.tutorialTableOfContents, .module]
2924+
29182925
func analyzeTopicGraph() {
29192926
// Find all nodes that are loose in the graph and have no parent but aren't supposed to
29202927
let unexpectedRoots = topicGraph.nodes.values.filter { node in

0 commit comments

Comments
 (0)