@@ -297,7 +297,7 @@ package actor SwiftLanguageService: LanguageService, Sendable {
297
297
}
298
298
}
299
299
300
- func buildSettings( for document: DocumentURI , fallbackAfterTimeout: Bool ) async -> SwiftCompileCommand ? {
300
+ func buildSettings( for document: DocumentURI , fallbackAfterTimeout: Bool ) async -> FileBuildSettings ? {
301
301
let buildSettingsFile = document. buildSettingsFile
302
302
303
303
guard let sourceKitLSPServer else {
@@ -307,11 +307,15 @@ package actor SwiftLanguageService: LanguageService, Sendable {
307
307
guard let workspace = await sourceKitLSPServer. workspaceForDocument ( uri: buildSettingsFile) else {
308
308
return nil
309
309
}
310
- if let settings = await workspace. buildSystemManager. buildSettingsInferredFromMainFile (
310
+ return await workspace. buildSystemManager. buildSettingsInferredFromMainFile (
311
311
for: buildSettingsFile,
312
312
language: . swift,
313
313
fallbackAfterTimeout: fallbackAfterTimeout
314
- ) {
314
+ )
315
+ }
316
+
317
+ func compileCommand( for document: DocumentURI , fallbackAfterTimeout: Bool ) async -> SwiftCompileCommand ? {
318
+ if let settings = await self . buildSettings ( for: document, fallbackAfterTimeout: fallbackAfterTimeout) {
315
319
return SwiftCompileCommand ( settings)
316
320
} else {
317
321
return nil
@@ -471,7 +475,7 @@ extension SwiftLanguageService {
471
475
try await self . sendSourcekitdRequest ( closeReq, fileContents: nil )
472
476
}
473
477
474
- let buildSettings = await buildSettings ( for: snapshot. uri, fallbackAfterTimeout: true )
478
+ let buildSettings = await compileCommand ( for: snapshot. uri, fallbackAfterTimeout: true )
475
479
let openReq = openDocumentSourcekitdRequest (
476
480
snapshot: snapshot,
477
481
compileCommand: buildSettings
@@ -493,7 +497,7 @@ extension SwiftLanguageService {
493
497
guard ( try ? documentManager. openDocuments. contains ( uri) ) ?? false else {
494
498
return
495
499
}
496
- let newBuildSettings = await self . buildSettings ( for: uri, fallbackAfterTimeout: false )
500
+ let newBuildSettings = await self . compileCommand ( for: uri, fallbackAfterTimeout: false )
497
501
if newBuildSettings != buildSettingsForOpenFiles [ uri] {
498
502
// Close and re-open the document internally to inform sourcekitd to update the compile command. At the moment
499
503
// there's no better way to do this.
@@ -563,7 +567,7 @@ extension SwiftLanguageService {
563
567
cancelInFlightPublishDiagnosticsTask ( for: notification. textDocument. uri)
564
568
await diagnosticReportManager. removeItemsFromCache ( with: notification. textDocument. uri)
565
569
566
- let buildSettings = await self . buildSettings ( for: snapshot. uri, fallbackAfterTimeout: true )
570
+ let buildSettings = await self . compileCommand ( for: snapshot. uri, fallbackAfterTimeout: true )
567
571
buildSettingsForOpenFiles [ snapshot. uri] = buildSettings
568
572
569
573
let req = openDocumentSourcekitdRequest ( snapshot: snapshot, compileCommand: buildSettings)
@@ -626,7 +630,7 @@ extension SwiftLanguageService {
626
630
}
627
631
do {
628
632
let snapshot = try await self . latestSnapshot ( for: document)
629
- let buildSettings = await self . buildSettings ( for: document, fallbackAfterTimeout: false )
633
+ let buildSettings = await self . compileCommand ( for: document, fallbackAfterTimeout: false )
630
634
let diagnosticReport = try await self . diagnosticReportManager. diagnosticReport (
631
635
for: snapshot,
632
636
buildSettings: buildSettings
@@ -976,7 +980,7 @@ extension SwiftLanguageService {
976
980
977
981
func retrieveQuickFixCodeActions( _ params: CodeActionRequest ) async throws -> [ CodeAction ] {
978
982
let snapshot = try await self . latestSnapshot ( for: params. textDocument. uri)
979
- let buildSettings = await self . buildSettings ( for: params. textDocument. uri, fallbackAfterTimeout: true )
983
+ let buildSettings = await self . compileCommand ( for: params. textDocument. uri, fallbackAfterTimeout: true )
980
984
let diagnosticReport = try await self . diagnosticReportManager. diagnosticReport (
981
985
for: snapshot,
982
986
buildSettings: buildSettings
@@ -1084,7 +1088,7 @@ extension SwiftLanguageService {
1084
1088
req. textDocument. uri. buildSettingsFile
1085
1089
)
1086
1090
let snapshot = try await self . latestSnapshot ( for: req. textDocument. uri)
1087
- let buildSettings = await self . buildSettings ( for: req. textDocument. uri, fallbackAfterTimeout: false )
1091
+ let buildSettings = await self . compileCommand ( for: req. textDocument. uri, fallbackAfterTimeout: false )
1088
1092
try Task . checkCancellation ( )
1089
1093
let diagnosticReport = try await self . diagnosticReportManager. diagnosticReport (
1090
1094
for: snapshot,
0 commit comments