@@ -110,57 +110,38 @@ package struct SwiftPMTestHooks: Sendable {
110110/// Package Manager (SwiftPM) package. The settings are determined by loading the Package.swift
111111/// manifest using `libSwiftPM` and constructing a build plan using the default (debug) parameters.
112112package actor SwiftPMBuildSystem {
113-
114113 package enum Error : Swift . Error {
115-
116114 /// Could not find a manifest (Package.swift file). This is not a package.
117115 case noManifest( workspacePath: TSCAbsolutePath )
118116
119117 /// Could not determine an appropriate toolchain for swiftpm to use for manifest loading.
120118 case cannotDetermineHostToolchain
121119 }
122120
121+ // MARK: Integration with SourceKit-LSP
122+
123+ /// Options that allow the user to pass extra compiler flags.
124+ private let options : SourceKitLSPOptions
125+
126+ private let testHooks : SwiftPMTestHooks
127+
123128 /// Delegate to handle any build system events.
124129 package weak var delegate : BuildSystemIntegration . BuildSystemDelegate ? = nil
125130
126131 package func setDelegate( _ delegate: BuildSystemIntegration . BuildSystemDelegate ? ) async {
127132 self . delegate = delegate
128133 }
129134
135+ /// This callback is informed when `reloadPackage` starts and ends executing.
136+ private var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
137+
130138 /// Callbacks that should be called if the list of possible test files has changed.
131139 private var testFilesDidChangeCallbacks : [ ( ) async -> Void ] = [ ]
132140
133- private let workspacePath : TSCAbsolutePath
134-
135- /// Options that allow the user to pass extra compiler flags.
136- private let options : SourceKitLSPOptions
137-
138- /// The directory containing `Package.swift`.
139- package var projectRoot : TSCAbsolutePath
140-
141- private var buildDescription : SourceKitLSPAPI . BuildDescription ?
142- private var modulesGraph : ModulesGraph
143- private let workspace : Workspace
144- package let toolsBuildParameters : BuildParameters
145- package let destinationBuildParameters : BuildParameters
146- private let fileSystem : FileSystem
147- private let toolchain : Toolchain
148-
149- private var fileToTargets : [ DocumentURI : [ SwiftBuildTarget ] ] = [ : ]
150- private var sourceDirToTargets : [ DocumentURI : [ SwiftBuildTarget ] ] = [ : ]
151-
152- /// Maps configured targets ids to their SwiftPM build target as well as an index in their topological sorting.
153- ///
154- /// Targets with lower index are more low level, ie. targets with higher indices depend on targets with lower indices.
155- private var targets : [ ConfiguredTarget : ( index: Int , buildTarget: SwiftBuildTarget ) ] = [ : ]
156-
157141 /// The URIs for which the delegate has registered for change notifications,
158142 /// mapped to the language the delegate specified when registering for change notifications.
159143 private var watchedFiles : Set < DocumentURI > = [ ]
160144
161- /// This callback is informed when `reloadPackage` starts and ends executing.
162- private var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
163-
164145 /// Debounces calls to `delegate.filesDependenciesUpdated`.
165146 ///
166147 /// This is to ensure we don't call `filesDependenciesUpdated` for the same file multiple time if the client does not
@@ -171,16 +152,45 @@ package actor SwiftPMBuildSystem {
171152 /// Force-unwrapped optional because initializing it requires access to `self`.
172153 private var fileDependenciesUpdatedDebouncer : Debouncer < Set < DocumentURI > > ! = nil
173154
155+ /// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
156+ /// user's build.
157+ private var isForIndexBuild : Bool { options. backgroundIndexingOrDefault }
158+
159+ // MARK: Build system options (set once and not modified)
160+
161+ /// The path at which the LSP workspace is opened. This might be a subdirectory of the path that contains the
162+ /// `Package.swift`.
163+ private let workspacePath : TSCAbsolutePath
164+
165+ /// The directory containing `Package.swift`.
166+ package let projectRoot : TSCAbsolutePath
167+
168+ package let toolsBuildParameters : BuildParameters
169+ package let destinationBuildParameters : BuildParameters
170+
171+ private let fileSystem : FileSystem
172+ private let toolchain : Toolchain
173+ private let workspace : Workspace
174+
174175 /// A `ObservabilitySystem` from `SwiftPM` that logs.
175176 private let observabilitySystem = ObservabilitySystem ( { scope, diagnostic in
176177 logger. log ( level: diagnostic. severity. asLogLevel, " SwiftPM log: \( diagnostic. description) " )
177178 } )
178179
179- /// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
180- /// user's build.
181- private var isForIndexBuild : Bool { options. backgroundIndexingOrDefault }
180+ // MARK: Build system state (modified on package reload)
182181
183- private let testHooks : SwiftPMTestHooks
182+ /// The entry point via with we can access the `SourceKitLSPAPI` provided by SwiftPM.
183+ private var buildDescription : SourceKitLSPAPI . BuildDescription ?
184+
185+ private var modulesGraph : ModulesGraph
186+
187+ private var fileToTargets : [ DocumentURI : [ SwiftBuildTarget ] ] = [ : ]
188+ private var sourceDirToTargets : [ DocumentURI : [ SwiftBuildTarget ] ] = [ : ]
189+
190+ /// Maps configured targets ids to their SwiftPM build target as well as an index in their topological sorting.
191+ ///
192+ /// Targets with lower index are more low level, ie. targets with higher indices depend on targets with lower indices.
193+ private var targets : [ ConfiguredTarget : ( index: Int , buildTarget: SwiftBuildTarget ) ] = [ : ]
184194
185195 /// Creates a build system using the Swift Package Manager, if this workspace is a package.
186196 ///
0 commit comments