@@ -110,57 +110,38 @@ package struct SwiftPMTestHooks: Sendable {
110
110
/// Package Manager (SwiftPM) package. The settings are determined by loading the Package.swift
111
111
/// manifest using `libSwiftPM` and constructing a build plan using the default (debug) parameters.
112
112
package actor SwiftPMBuildSystem {
113
-
114
113
package enum Error : Swift . Error {
115
-
116
114
/// Could not find a manifest (Package.swift file). This is not a package.
117
115
case noManifest( workspacePath: TSCAbsolutePath )
118
116
119
117
/// Could not determine an appropriate toolchain for swiftpm to use for manifest loading.
120
118
case cannotDetermineHostToolchain
121
119
}
122
120
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
+
123
128
/// Delegate to handle any build system events.
124
129
package weak var delegate : BuildSystemIntegration . BuildSystemDelegate ? = nil
125
130
126
131
package func setDelegate( _ delegate: BuildSystemIntegration . BuildSystemDelegate ? ) async {
127
132
self . delegate = delegate
128
133
}
129
134
135
+ /// This callback is informed when `reloadPackage` starts and ends executing.
136
+ private var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
137
+
130
138
/// Callbacks that should be called if the list of possible test files has changed.
131
139
private var testFilesDidChangeCallbacks : [ ( ) async -> Void ] = [ ]
132
140
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
-
157
141
/// The URIs for which the delegate has registered for change notifications,
158
142
/// mapped to the language the delegate specified when registering for change notifications.
159
143
private var watchedFiles : Set < DocumentURI > = [ ]
160
144
161
- /// This callback is informed when `reloadPackage` starts and ends executing.
162
- private var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
163
-
164
145
/// Debounces calls to `delegate.filesDependenciesUpdated`.
165
146
///
166
147
/// 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 {
171
152
/// Force-unwrapped optional because initializing it requires access to `self`.
172
153
private var fileDependenciesUpdatedDebouncer : Debouncer < Set < DocumentURI > > ! = nil
173
154
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
+
174
175
/// A `ObservabilitySystem` from `SwiftPM` that logs.
175
176
private let observabilitySystem = ObservabilitySystem ( { scope, diagnostic in
176
177
logger. log ( level: diagnostic. severity. asLogLevel, " SwiftPM log: \( diagnostic. description) " )
177
178
} )
178
179
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)
182
181
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 ) ] = [ : ]
184
194
185
195
/// Creates a build system using the Swift Package Manager, if this workspace is a package.
186
196
///
0 commit comments