@@ -104,47 +104,35 @@ extension DocumentationLanguageService {
104
104
guard let index = workspace. index ( checkedFor: . deletedFiles) else {
105
105
throw ResponseError . requestFailed ( doccDocumentationError: . indexNotAvailable)
106
106
}
107
- guard let symbolLink = DocCSymbolLink ( linkString: symbolName) ,
108
- let symbolOccurrence = try await index. primaryDefinitionOrDeclarationOccurrence (
109
- ofDocCSymbolLink: symbolLink,
110
- fetchSymbolGraph: { location in
111
- guard let symbolWorkspace = await sourceKitLSPServer. workspaceForDocument ( uri: location. documentUri) else {
112
- throw ResponseError . internalError ( " Unable to find language service for \( location. documentUri) " )
107
+ return try await sourceKitLSPServer. withOnDiskDocumentManager { onDiskDocumentManager in
108
+ guard let symbolLink = DocCSymbolLink ( linkString: symbolName) ,
109
+ let symbolOccurrence = try await index. primaryDefinitionOrDeclarationOccurrence (
110
+ ofDocCSymbolLink: symbolLink,
111
+ fetchSymbolGraph: { location in
112
+ return try await sourceKitLSPServer. primaryLanguageService (
113
+ for: location. documentUri,
114
+ workspace. buildServerManager. defaultLanguageInCanonicalTarget ( for: location. documentUri) ,
115
+ in: workspace
116
+ )
117
+ . symbolGraph ( forOnDiskContentsAt: location, in: workspace, manager: onDiskDocumentManager)
113
118
}
114
- let languageService = try await sourceKitLSPServer. primaryLanguageService (
115
- for: location. documentUri,
116
- . swift,
117
- in: symbolWorkspace
118
- )
119
- return try await languageService. symbolGraph (
120
- forOnDiskContentsOf: location. documentUri,
121
- at: location
122
- )
123
- }
119
+ )
120
+ else {
121
+ throw ResponseError . requestFailed ( doccDocumentationError: . symbolNotFound( symbolName) )
122
+ }
123
+ let symbolGraph = try await sourceKitLSPServer. primaryLanguageService (
124
+ for: symbolOccurrence. location. documentUri,
125
+ workspace. buildServerManager. defaultLanguageInCanonicalTarget ( for: symbolOccurrence. location. documentUri) ,
126
+ in: workspace
127
+ ) . symbolGraph ( forOnDiskContentsAt: symbolOccurrence. location, in: workspace, manager: onDiskDocumentManager)
128
+ return try await documentationManager. renderDocCDocumentation (
129
+ symbolUSR: symbolOccurrence. symbol. usr,
130
+ symbolGraph: symbolGraph,
131
+ markupFile: snapshot. text,
132
+ moduleName: moduleName,
133
+ catalogURL: catalogURL
124
134
)
125
- else {
126
- throw ResponseError . requestFailed ( doccDocumentationError: . symbolNotFound( symbolName) )
127
135
}
128
- let symbolDocumentUri = symbolOccurrence. location. documentUri
129
- guard let symbolWorkspace = await sourceKitLSPServer. workspaceForDocument ( uri: symbolDocumentUri) else {
130
- throw ResponseError . internalError ( " Unable to find language service for \( symbolDocumentUri) " )
131
- }
132
- let languageService = try await sourceKitLSPServer. primaryLanguageService (
133
- for: symbolDocumentUri,
134
- . swift,
135
- in: symbolWorkspace
136
- )
137
- let symbolGraph = try await languageService. symbolGraph (
138
- forOnDiskContentsOf: symbolDocumentUri,
139
- at: symbolOccurrence. location
140
- )
141
- return try await documentationManager. renderDocCDocumentation (
142
- symbolUSR: symbolOccurrence. symbol. usr,
143
- symbolGraph: symbolGraph,
144
- markupFile: snapshot. text,
145
- moduleName: moduleName,
146
- catalogURL: catalogURL
147
- )
148
136
}
149
137
// This is a page representing the module itself.
150
138
// Create a dummy symbol graph and tell SwiftDocC to convert the module name.
@@ -175,24 +163,26 @@ extension DocumentationLanguageService {
175
163
in: workspace
176
164
) . symbolGraph ( for: snapshot, at: position)
177
165
// Locate the documentation extension and include it in the request if one exists
178
- let markupExtensionFile = await orLog ( " Finding markup extension file for symbol \( symbolUSR) " ) {
179
- try await findMarkupExtensionFile (
180
- workspace: workspace,
181
- documentationManager: documentationManager,
182
- catalogURL: catalogURL,
183
- for: symbolUSR,
184
- fetchSymbolGraph: { location in
185
- guard let symbolWorkspace = await sourceKitLSPServer. workspaceForDocument ( uri: location. documentUri) else {
186
- throw ResponseError . internalError ( " Unable to find language service for \( location. documentUri) " )
166
+ let markupExtensionFile = await sourceKitLSPServer. withOnDiskDocumentManager {
167
+ [ documentationManager, documentManager = try documentManager] onDiskDocumentManager in
168
+ await orLog ( " Finding markup extension file for symbol \( symbolUSR) " ) {
169
+ try await Self . findMarkupExtensionFile (
170
+ workspace: workspace,
171
+ documentationManager: documentationManager,
172
+ documentManager: documentManager,
173
+ catalogURL: catalogURL,
174
+ for: symbolUSR,
175
+ fetchSymbolGraph: { location in
176
+ try await sourceKitLSPServer. primaryLanguageService (
177
+ for: location. documentUri,
178
+ snapshot. language,
179
+ in: workspace
180
+ )
181
+ . symbolGraph ( forOnDiskContentsAt: location, in: workspace, manager: onDiskDocumentManager)
182
+
187
183
}
188
- let languageService = try await sourceKitLSPServer. primaryLanguageService (
189
- for: location. documentUri,
190
- . swift,
191
- in: symbolWorkspace
192
- )
193
- return try await languageService. symbolGraph ( forOnDiskContentsOf: location. documentUri, at: location)
194
- }
195
- )
184
+ )
185
+ }
196
186
}
197
187
return try await documentationManager. renderDocCDocumentation (
198
188
symbolUSR: symbolUSR,
@@ -204,9 +194,10 @@ extension DocumentationLanguageService {
204
194
)
205
195
}
206
196
207
- private func findMarkupExtensionFile(
197
+ private static func findMarkupExtensionFile(
208
198
workspace: Workspace ,
209
199
documentationManager: DocCDocumentationManager ,
200
+ documentManager: DocumentManager ,
210
201
catalogURL: URL ? ,
211
202
for symbolUSR: String ,
212
203
fetchSymbolGraph: @Sendable ( SymbolLocation) async throws -> String ?
@@ -215,16 +206,17 @@ extension DocumentationLanguageService {
215
206
return nil
216
207
}
217
208
let catalogIndex = try await documentationManager. catalogIndex ( for: catalogURL)
218
- guard let index = workspace. index ( checkedFor: . deletedFiles) ,
219
- let symbolInformation = try await index. doccSymbolInformation (
220
- ofUSR: symbolUSR,
221
- fetchSymbolGraph: fetchSymbolGraph
222
- ) ,
223
- let markupExtensionFileURL = catalogIndex. documentationExtension ( for: symbolInformation)
224
- else {
209
+ guard let index = workspace. index ( checkedFor: . deletedFiles) else {
210
+ return nil
211
+ }
212
+ let symbolInformation = try await index. doccSymbolInformation (
213
+ ofUSR: symbolUSR,
214
+ fetchSymbolGraph: fetchSymbolGraph
215
+ )
216
+ guard let markupExtensionFileURL = catalogIndex. documentationExtension ( for: symbolInformation) else {
225
217
return nil
226
218
}
227
- return try ? documentManager. latestSnapshotOrDisk (
219
+ return documentManager. latestSnapshotOrDisk (
228
220
DocumentURI ( markupExtensionFileURL) ,
229
221
language: . markdown
230
222
) ? . text
0 commit comments