10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ package import Foundation
14
+
15
+ package protocol DocCCatalogIndex : Sendable {
16
+ func documentationExtension( for symbolLink: any DocCSymbolLink ) -> URL ?
17
+ }
18
+
13
19
#if canImport(SwiftDocC)
14
- import Foundation
15
20
@preconcurrency import SwiftDocC
16
21
import SwiftExtensions
17
22
18
23
final actor DocCCatalogIndexManager {
19
24
private let server : DocCServer
20
- private var catalogToIndexMap = [ URL : Result < DocCCatalogIndex , DocCIndexError > ] ( )
25
+ private var catalogToIndexMap = [ URL : Result < DocCCatalogIndexImpl , DocCIndexError > ] ( )
21
26
22
27
init ( server: DocCServer ) {
23
28
self . server = server
@@ -32,11 +37,11 @@ final actor DocCCatalogIndexManager {
32
37
}
33
38
}
34
39
35
- func index( for catalogURL: URL ) async throws ( DocCIndexError) -> DocCCatalogIndex {
40
+ func index( for catalogURL: URL ) async throws ( DocCIndexError) -> DocCCatalogIndexImpl {
36
41
if let existingCatalog = catalogToIndexMap [ catalogURL] {
37
42
return try existingCatalog. get ( )
38
43
}
39
- let catalogIndexResult : Result < DocCCatalogIndex , DocCIndexError >
44
+ let catalogIndexResult : Result < DocCCatalogIndexImpl , DocCIndexError >
40
45
do {
41
46
let convertResponse = try await server. convert (
42
47
externalIDsToConvert: [ ] ,
@@ -62,37 +67,37 @@ final actor DocCCatalogIndexManager {
62
67
Result { try JSONDecoder ( ) . decode ( RenderReferenceStore . self, from: renderReferenceStoreData) }
63
68
. flatMapError { . failure( . decodingFailure( $0) ) }
64
69
}
65
- . map { DocCCatalogIndex ( from: $0) }
70
+ . map { DocCCatalogIndexImpl ( from: $0) }
66
71
} catch {
67
- catalogIndexResult = . failure( . serverError ( error) )
72
+ catalogIndexResult = . failure( . internalError ( error) )
68
73
}
69
74
catalogToIndexMap [ catalogURL] = catalogIndexResult
70
75
return try catalogIndexResult. get ( )
71
76
}
72
77
}
73
78
74
79
/// Represents a potential error that the ``DocCCatalogIndexManager`` could encounter while indexing
75
- enum DocCIndexError : LocalizedError {
80
+ package enum DocCIndexError : LocalizedError {
76
81
case decodingFailure( Error )
77
- case serverError ( DocCServerError )
82
+ case internalError ( LocalizedError )
78
83
case unexpectedlyNilRenderReferenceStore
79
84
80
- var errorDescription : String ? {
85
+ package var errorDescription : String ? {
81
86
switch self {
82
87
case . decodingFailure( let decodingError) :
83
88
return " Failed to decode a received message: \( decodingError. localizedDescription) "
84
- case . serverError ( let serverError ) :
85
- return " DocC server failed to convert the catalog : \( serverError . localizedDescription) "
89
+ case . internalError ( let internalError ) :
90
+ return " An internal error occurred : \( internalError . localizedDescription) "
86
91
case . unexpectedlyNilRenderReferenceStore:
87
92
return " Did not receive a RenderReferenceStore from the DocC server "
88
93
}
89
94
}
90
95
}
91
96
92
- struct DocCCatalogIndex : Sendable {
97
+ package struct DocCCatalogIndexImpl : DocCCatalogIndex {
93
98
private let assetReferenceToDataAsset : [ String : DataAsset ]
94
99
private let fuzzyAssetReferenceToDataAsset : [ String : DataAsset ]
95
- private let documentationExtensionToSourceURL : [ DocCSymbolLink : URL ]
100
+ private let documentationExtensionToSourceURL : [ DocCSymbolLinkImpl : URL ]
96
101
let articlePathToSourceURLAndReference : [ String : ( URL , TopicRenderReference ) ]
97
102
let tutorialPathToSourceURLAndReference : [ String : ( URL , TopicRenderReference ) ]
98
103
let tutorialOverviewPathToSourceURLAndReference : [ String : ( URL , TopicRenderReference ) ]
@@ -101,8 +106,11 @@ struct DocCCatalogIndex: Sendable {
101
106
assetReferenceToDataAsset [ assetReference. assetName] ?? fuzzyAssetReferenceToDataAsset [ assetReference. assetName]
102
107
}
103
108
104
- func documentationExtension( for symbolLink: DocCSymbolLink ) -> URL ? {
105
- documentationExtensionToSourceURL [ symbolLink]
109
+ package func documentationExtension( for symbolLink: any DocCSymbolLink ) -> URL ? {
110
+ guard let symbolLink = symbolLink as? DocCSymbolLinkImpl else {
111
+ return nil
112
+ }
113
+ return documentationExtensionToSourceURL [ symbolLink]
106
114
}
107
115
108
116
init ( from renderReferenceStore: RenderReferenceStore ) {
@@ -121,7 +129,7 @@ struct DocCCatalogIndex: Sendable {
121
129
self . assetReferenceToDataAsset = assetReferenceToDataAsset
122
130
self . fuzzyAssetReferenceToDataAsset = fuzzyAssetReferenceToDataAsset
123
131
// Markdown and Tutorial content
124
- var documentationExtensionToSourceURL = [ DocCSymbolLink : URL] ( )
132
+ var documentationExtensionToSourceURL = [ DocCSymbolLinkImpl : URL] ( )
125
133
var articlePathToSourceURLAndReference = [ String: ( URL, TopicRenderReference) ] ( )
126
134
var tutorialPathToSourceURLAndReference = [ String: ( URL, TopicRenderReference) ] ( )
127
135
var tutorialOverviewPathToSourceURLAndReference = [ String: ( URL, TopicRenderReference) ] ( )
@@ -138,7 +146,7 @@ struct DocCCatalogIndex: Sendable {
138
146
else {
139
147
continue
140
148
}
141
- let doccSymbolLink = DocCSymbolLink ( absoluteSymbolLink: absoluteSymbolLink)
149
+ let doccSymbolLink = DocCSymbolLinkImpl ( absoluteSymbolLink: absoluteSymbolLink)
142
150
documentationExtensionToSourceURL [ doccSymbolLink] = topicContentValue. source
143
151
} else if topicRenderReference. kind == . article {
144
152
articlePathToSourceURLAndReference [ renderReferenceKey. url. lastPathComponent] = (
0 commit comments