@@ -104,47 +104,35 @@ extension DocumentationLanguageService {
104104 guard let index = workspace. index ( checkedFor: . deletedFiles) else {
105105 throw ResponseError . requestFailed ( doccDocumentationError: . indexNotAvailable)
106106 }
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)
113118 }
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
124134 )
125- else {
126- throw ResponseError . requestFailed ( doccDocumentationError: . symbolNotFound( symbolName) )
127135 }
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- )
148136 }
149137 // This is a page representing the module itself.
150138 // Create a dummy symbol graph and tell SwiftDocC to convert the module name.
@@ -175,24 +163,26 @@ extension DocumentationLanguageService {
175163 in: workspace
176164 ) . symbolGraph ( for: snapshot, at: position)
177165 // 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+
187183 }
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+ }
196186 }
197187 return try await documentationManager. renderDocCDocumentation (
198188 symbolUSR: symbolUSR,
@@ -204,9 +194,10 @@ extension DocumentationLanguageService {
204194 )
205195 }
206196
207- private func findMarkupExtensionFile(
197+ private static func findMarkupExtensionFile(
208198 workspace: Workspace ,
209199 documentationManager: DocCDocumentationManager ,
200+ documentManager: DocumentManager ,
210201 catalogURL: URL ? ,
211202 for symbolUSR: String ,
212203 fetchSymbolGraph: @Sendable ( SymbolLocation) async throws -> String ?
@@ -215,16 +206,17 @@ extension DocumentationLanguageService {
215206 return nil
216207 }
217208 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 {
225217 return nil
226218 }
227- return try ? documentManager. latestSnapshotOrDisk (
219+ return documentManager. latestSnapshotOrDisk (
228220 DocumentURI ( markupExtensionFileURL) ,
229221 language: . markdown
230222 ) ? . text
0 commit comments