@@ -127,10 +127,10 @@ public actor SourceKitLSPServer {
127
127
/// initializer.
128
128
private nonisolated ( unsafe) var indexProgressManager: IndexProgressManager !
129
129
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 ?
134
134
135
135
/// **Public for testing**
136
136
public var _documentManager : DocumentManager {
@@ -898,6 +898,27 @@ extension SourceKitLSPServer {
898
898
)
899
899
}
900
900
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
+
901
922
/// Creates a workspace at the given `uri`.
902
923
///
903
924
/// If the build system that was determined for the workspace does not satisfy `condition`, `nil` is returned.
@@ -916,13 +937,7 @@ extension SourceKitLSPServer {
916
937
options: options,
917
938
toolchainRegistry: toolchainRegistry,
918
939
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)
926
941
}
927
942
)
928
943
guard await condition ( buildSystem) else {
0 commit comments