@@ -127,10 +127,10 @@ public actor SourceKitLSPServer {
127127 /// initializer.
128128 private nonisolated ( unsafe) var indexProgressManager: IndexProgressManager !
129129
130- private var packageLoadingWorkDoneProgress = WorkDoneProgressState (
131- " SourceKitLSP.SourceKitLSPServer.reloadPackage " ,
132- title : " SourceKit-LSP: Reloading Package "
133- )
130+ /// Number of workspaces that are currently reloading swift package. When this is not 0, a
131+ /// `packageLoadingWorkDoneProgress` is created to show a work done progress indicator in the client.
132+ private var inProgressPackageLoadingOperations = 0
133+ private var packageLoadingWorkDoneProgress : WorkDoneProgressManager ?
134134
135135 /// **Public for testing**
136136 public var _documentManager : DocumentManager {
@@ -898,6 +898,27 @@ extension SourceKitLSPServer {
898898 )
899899 }
900900
901+ private func reloadPackageStatusCallback( _ status: ReloadPackageStatus ) async {
902+ switch status {
903+ case . start:
904+ inProgressPackageLoadingOperations += 1
905+ if let capabilityRegistry, packageLoadingWorkDoneProgress == nil {
906+ packageLoadingWorkDoneProgress = WorkDoneProgressManager (
907+ server: self ,
908+ capabilityRegistry: capabilityRegistry,
909+ initialDebounce: options. workDoneProgressDebounceDuration,
910+ title: " SourceKit-LSP: Reloading Package "
911+ )
912+ }
913+ case . end:
914+ inProgressPackageLoadingOperations -= 1
915+ if inProgressPackageLoadingOperations == 0 , let packageLoadingWorkDoneProgress {
916+ self . packageLoadingWorkDoneProgress = nil
917+ await packageLoadingWorkDoneProgress. end ( )
918+ }
919+ }
920+ }
921+
901922 /// Creates a workspace at the given `uri`.
902923 ///
903924 /// If the build system that was determined for the workspace does not satisfy `condition`, `nil` is returned.
@@ -916,13 +937,7 @@ extension SourceKitLSPServer {
916937 options: options,
917938 toolchainRegistry: toolchainRegistry,
918939 reloadPackageStatusCallback: { [ weak self] status in
919- guard let self else { return }
920- switch status {
921- case . start:
922- await self . packageLoadingWorkDoneProgress. startProgress ( server: self )
923- case . end:
924- await self . packageLoadingWorkDoneProgress. endProgress ( server: self )
925- }
940+ await self ? . reloadPackageStatusCallback ( status)
926941 }
927942 )
928943 guard await condition ( buildSystem) else {
0 commit comments