Skip to content

Commit e540e16

Browse files
authored
Revert "Show a progress indicator in the editor if SourceKit-LSP is reloading packages"
1 parent ee269d3 commit e540e16

File tree

4 files changed

+11
-141
lines changed

4 files changed

+11
-141
lines changed

Sources/LSPTestSupport/TestJSONRPCConnection.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@ public final class TestClient: MessageHandler {
137137
}
138138

139139
public func handle<R: RequestType>(_ params: R, id: RequestID, from clientID: ObjectIdentifier, reply: @escaping (LSPResult<R.Response>) -> Void) {
140-
if R.self == CreateWorkDoneProgressRequest.self {
141-
// We don’t want to require tests to specify request handlers for work done progress.
142-
// Simply ignore requests to create WorkDoneProgress for now.
143-
reply(.failure(.unknown("WorkDone not supported in TestClient")))
144-
return
145-
}
146-
147140
let cancellationToken = CancellationToken()
148141

149142
let request = Request(params, id: id, clientID: clientID, cancellation: cancellationToken, reply: reply)

Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ import func TSCBasic.resolveSymlinks
3535
import protocol TSCBasic.FileSystem
3636
import var TSCBasic.localFileSystem
3737

38-
/// Parameter of `reloadPackageStatusCallback` in ``SwiftPMWorkspace``.
39-
///
40-
/// Informs the callback about whether `reloadPackage` started or finished executing.
41-
public enum ReloadPackageStatus {
42-
case start
43-
case end
44-
}
45-
4638
/// Swift Package Manager build system and workspace support.
4739
///
4840
/// This class implements the `BuildSystem` interface to provide the build settings for a Swift
@@ -86,25 +78,18 @@ public final class SwiftPMWorkspace {
8678
/// - `sourceDirToTarget`
8779
let queue: DispatchQueue = .init(label: "SwiftPMWorkspace.queue", qos: .utility)
8880

89-
/// This callback is informed when `reloadPackage` starts and ends executing.
90-
var reloadPackageStatusCallback: (ReloadPackageStatus) -> Void
91-
92-
9381
/// Creates a build system using the Swift Package Manager, if this workspace is a package.
9482
///
9583
/// - Parameters:
9684
/// - workspace: The workspace root path.
9785
/// - toolchainRegistry: The toolchain registry to use to provide the Swift compiler used for
9886
/// manifest parsing and runtime support.
99-
/// - reloadPackageStatusCallback: Will be informed when `reloadPackage` starts and ends executing.
10087
/// - Throws: If there is an error loading the package, or no manifest is found.
10188
public init(
10289
workspacePath: TSCAbsolutePath,
10390
toolchainRegistry: ToolchainRegistry,
10491
fileSystem: FileSystem = localFileSystem,
105-
buildSetup: BuildSetup,
106-
reloadPackageStatusCallback: @escaping (ReloadPackageStatus) -> Void = { _ in }
107-
) throws
92+
buildSetup: BuildSetup) throws
10893
{
10994
self.workspacePath = workspacePath
11095
self.fileSystem = fileSystem
@@ -157,31 +142,23 @@ public final class SwiftPMWorkspace {
157142
)
158143

159144
self.packageGraph = try PackageGraph(rootPackages: [], dependencies: [], binaryArtifacts: [:])
160-
self.reloadPackageStatusCallback = reloadPackageStatusCallback
161145

162146
try reloadPackage()
163147
}
164148

165149
/// Creates a build system using the Swift Package Manager, if this workspace is a package.
166-
///
167-
/// - Parameters:
168-
/// - reloadPackageStatusCallback: Will be informed when `reloadPackage` starts and ends executing.
150+
///
169151
/// - Returns: nil if `workspacePath` is not part of a package or there is an error.
170-
public convenience init?(
171-
url: URL,
172-
toolchainRegistry: ToolchainRegistry,
173-
buildSetup: BuildSetup,
174-
reloadPackageStatusCallback: @escaping (ReloadPackageStatus) -> Void
175-
)
152+
public convenience init?(url: URL,
153+
toolchainRegistry: ToolchainRegistry,
154+
buildSetup: BuildSetup)
176155
{
177156
do {
178157
try self.init(
179158
workspacePath: try TSCAbsolutePath(validating: url.path),
180159
toolchainRegistry: toolchainRegistry,
181160
fileSystem: localFileSystem,
182-
buildSetup: buildSetup,
183-
reloadPackageStatusCallback: reloadPackageStatusCallback
184-
)
161+
buildSetup: buildSetup)
185162
} catch Error.noManifest(let path) {
186163
log("could not find manifest, or not a SwiftPM package: \(path)", level: .warning)
187164
return nil
@@ -198,11 +175,6 @@ extension SwiftPMWorkspace {
198175
/// dependencies.
199176
/// Must only be called on `queue` or from the initializer.
200177
func reloadPackage() throws {
201-
reloadPackageStatusCallback(.start)
202-
defer {
203-
reloadPackageStatusCallback(.end)
204-
}
205-
206178

207179
let observabilitySystem = ObservabilitySystem({ scope, diagnostic in
208180
log(diagnostic.description, level: diagnostic.severity.asLogLevel)

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -58,84 +58,6 @@ enum LanguageServerType: Hashable {
5858
}
5959
}
6060

61-
/// Keeps track of the state to send work done progress updates to the client
62-
final class WorkDoneProgressState {
63-
private enum State {
64-
/// No `WorkDoneProgress` has been created.
65-
case noProgress
66-
/// We have sent the request to create a `WorkDoneProgress` but haven’t received a respose yet.
67-
case creating
68-
/// A `WorkDoneProgress` has been created.
69-
case created
70-
/// The creation of a `WorkDoneProgress has failed`.
71-
///
72-
/// This causes us to just give up creating any more `WorkDoneProgress` in
73-
/// the future as those will most likely also fail.
74-
case progressCreationFailed
75-
}
76-
77-
/// How many active tasks are running.
78-
///
79-
/// A work done progress should be displayed if activeTasks > 0
80-
private var activeTasks: Int = 0
81-
private var state: State = .noProgress
82-
83-
/// The token by which we track the `WorkDoneProgress`.
84-
private let token: ProgressToken
85-
86-
/// The title that should be displayed to the user in the UI.
87-
private let title: String
88-
89-
init(_ token: String, title: String) {
90-
self.token = ProgressToken.string(token)
91-
self.title = title
92-
}
93-
94-
/// Start a new task, creating a new `WorkDoneProgress` if none is running right now.
95-
///
96-
/// - Parameter server: The server that is used to create the `WorkDoneProgress` on the client
97-
///
98-
/// - Important: Must be called on `server.queue`.
99-
func startProgress(server: SourceKitServer) {
100-
dispatchPrecondition(condition: .onQueue(server.queue))
101-
activeTasks += 1
102-
if state == .noProgress {
103-
state = .creating
104-
// Discard the handle. We don't support cancellation of the creation of a work done progress.
105-
_ = server.client.send(CreateWorkDoneProgressRequest(token: token), queue: server.queue) { result in
106-
if result.success != nil {
107-
if self.activeTasks == 0 {
108-
// ActiveTasks might have been decreased while we created the `WorkDoneProgress`
109-
self.state = .noProgress
110-
server.client.send(WorkDoneProgress(token: self.token, value: .end(WorkDoneProgressEnd())))
111-
} else {
112-
self.state = .created
113-
server.client.send(WorkDoneProgress(token: self.token, value: .begin(WorkDoneProgressBegin(title: self.title))))
114-
}
115-
} else {
116-
self.state = .progressCreationFailed
117-
}
118-
}
119-
}
120-
}
121-
122-
/// End a new task stated using `startProgress`.
123-
///
124-
/// If this drops the active task count to 0, the work done progress is ended on the client.
125-
///
126-
/// - Parameter server: The server that is used to send and update of the `WorkDoneProgress` to the client
127-
///
128-
/// - Important: Must be called on `server.queue`.
129-
func endProgress(server: SourceKitServer) {
130-
dispatchPrecondition(condition: .onQueue(server.queue))
131-
assert(activeTasks > 0, "Unbalanced startProgress/endProgress calls")
132-
activeTasks -= 1
133-
if state == .created && activeTasks == 0 {
134-
server.client.send(WorkDoneProgress(token: token, value: .end(WorkDoneProgressEnd())))
135-
}
136-
}
137-
}
138-
13961
/// The SourceKit language server.
14062
///
14163
/// This is the client-facing language server implementation, providing indexing, multiple-toolchain
@@ -158,8 +80,6 @@ public final class SourceKitServer: LanguageServer {
15880

15981
private let documentManager = DocumentManager()
16082

161-
private var packageLoadingWorkDoneProgress = WorkDoneProgressState("SourceKitLSP.SoruceKitServer.reloadPackage", title: "Reloading Package")
162-
16383
/// **Public for testing**
16484
public var _documentManager: DocumentManager {
16585
return documentManager
@@ -639,18 +559,7 @@ extension SourceKitServer {
639559
capabilityRegistry: capabilityRegistry,
640560
toolchainRegistry: self.toolchainRegistry,
641561
buildSetup: self.options.buildSetup,
642-
indexOptions: self.options.indexOptions,
643-
reloadPackageStatusCallback: { status in
644-
self.queue.async {
645-
switch status {
646-
case .start:
647-
self.packageLoadingWorkDoneProgress.startProgress(server: self)
648-
case .end:
649-
self.packageLoadingWorkDoneProgress.endProgress(server: self)
650-
}
651-
}
652-
}
653-
)
562+
indexOptions: self.options.indexOptions)
654563
}
655564

656565
func initialize(_ req: Request<InitializeRequest>) {

Sources/SourceKitLSP/Workspace.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,15 @@ public final class Workspace {
8484
capabilityRegistry: CapabilityRegistry,
8585
toolchainRegistry: ToolchainRegistry,
8686
buildSetup: BuildSetup,
87-
indexOptions: IndexOptions = IndexOptions(),
88-
reloadPackageStatusCallback: @escaping (ReloadPackageStatus) -> Void
87+
indexOptions: IndexOptions = IndexOptions()
8988
) throws {
9089
var buildSystem: BuildSystem? = nil
9190
if let rootUrl = rootUri.fileURL, let rootPath = try? AbsolutePath(validating: rootUrl.path) {
9291
if let buildServer = BuildServerBuildSystem(projectRoot: rootPath, buildSetup: buildSetup) {
9392
buildSystem = buildServer
94-
} else if let swiftpm = SwiftPMWorkspace(
95-
url: rootUrl,
96-
toolchainRegistry: toolchainRegistry,
97-
buildSetup: buildSetup,
98-
reloadPackageStatusCallback: reloadPackageStatusCallback
99-
) {
93+
} else if let swiftpm = SwiftPMWorkspace(url: rootUrl,
94+
toolchainRegistry: toolchainRegistry,
95+
buildSetup: buildSetup) {
10096
buildSystem = swiftpm
10197
} else {
10298
buildSystem = CompilationDatabaseBuildSystem(projectRoot: rootPath)

0 commit comments

Comments
 (0)