Skip to content

Commit 374554b

Browse files
authored
Merge pull request #2092 from ahoppen/official-synchronization
Make `workspace/synchronize` a non-experimental request
2 parents 3fb72cd + 73016af commit 374554b

File tree

6 files changed

+60
-41
lines changed

6 files changed

+60
-41
lines changed

Contributor Documentation/LSP Extensions.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -664,33 +664,6 @@ export interface SourceKitOptionsResult {
664664
}
665665
```
666666
667-
## `workspace/_synchronize`
668-
669-
New request from the client to the server to wait for SourceKit-LSP to handle all ongoing requests and, optionally, wait for background activity to finish.
670-
671-
> [!IMPORTANT]
672-
> This request is experimental, guarded behind the `synchronize-request` experimental feature and may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
673-
674-
- params: `SynchronizeParams`
675-
- result: `void`
676-
677-
```ts
678-
export interface SynchronizeParams {
679-
/**
680-
* Wait for the build server to have an up-to-date build graph by sending a `workspace/waitForBuildSystemUpdates` to
681-
* it.
682-
*/
683-
buildServerUpdates?: bool
684-
685-
/**
686-
* Wait for background indexing to finish and all index unit files to be loaded into indexstore-db.
687-
*
688-
* Implies `buildServerUpdates = true`.
689-
*/
690-
index?: bool
691-
}
692-
```
693-
694667
## `workspace/_outputPaths`
695668
696669
New request from the client to the server to retrieve the output paths of a target (see the `buildTarget/outputPaths` BSP request).
@@ -789,6 +762,40 @@ export interface PeekDocumentsResult {
789762
}
790763
```
791764
765+
## `workspace/synchronize`
766+
767+
Request from the client to the server to wait for SourceKit-LSP to handle all ongoing requests and, optionally, wait for background activity to finish.
768+
769+
This method is intended to be used in automated environments which need to wait for background activity to finish before executing requests that rely on that background activity to finish. Examples of such cases are:
770+
- Automated tests that need to wait for background indexing to finish and then checking the result of request results
771+
- Automated tests that need to wait for requests like file changes to be handled and checking behavior after those have been processed
772+
- Code analysis tools that want to use SourceKit-LSP to gather information about the project but can only do so after the index has been loaded
773+
774+
Because this request waits for all other SourceKit-LSP requests to finish, it limits parallel request handling and is ill-suited for any kind of interactive environment. In those environments, it is preferable to quickly give the user a result based on the data that is available and (let the user) re-perform the action if the underlying index data has changed.
775+
776+
- params: `SynchronizeParams`
777+
- result: `void`
778+
779+
```ts
780+
export interface SynchronizeParams {
781+
/**
782+
* Wait for the build server to have an up-to-date build graph by sending a `workspace/waitForBuildSystemUpdates` to
783+
* it.
784+
*
785+
* This is implied by `index = true`.
786+
*
787+
* This option is experimental, guarded behind the `synchronize-for-build-system-updates` experimental feature, and
788+
* may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
789+
*/
790+
buildServerUpdates?: bool
791+
792+
/**
793+
* Wait for background indexing to finish and all index unit files to be loaded into indexstore-db.
794+
*/
795+
index?: bool
796+
}
797+
```
798+
792799
## `workspace/tests`
793800
794801
New request that returns symbols for all the test classes and test methods within the current workspace.

Sources/LanguageServerProtocol/Requests/SynchronizeRequest.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,35 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// Wait for SourceKit-LSP to handle all ongoing requests and, optionally, wait for background activity to finish.
13+
/// Request from the client to the server to wait for SourceKit-LSP to handle all ongoing requests and, optionally, wait
14+
/// for background activity to finish.
1415
///
15-
/// **LSP Extension, For Testing**.
16+
/// This method is intended to be used in automated environments which need to wait for background activity to finish
17+
/// before executing requests that rely on that background activity to finish. Examples of such cases are:
18+
/// - Automated tests that need to wait for background indexing to finish and then checking the result of request
19+
/// results
20+
/// - Automated tests that need to wait for requests like file changes to be handled and checking behavior after those
21+
/// have been processed
22+
/// - Code analysis tools that want to use SourceKit-LSP to gather information about the project but can only do so
23+
/// after the index has been loaded
24+
///
25+
/// Because this request waits for all other SourceKit-LSP requests to finish, it limits parallel request handling and
26+
/// is ill-suited for any kind of interactive environment. In those environments, it is preferable to quickly give the
27+
/// user a result based on the data that is available and (let the user) re-perform the action if the underlying index
28+
/// data has changed.
1629
public struct SynchronizeRequest: RequestType {
17-
public static let method: String = "workspace/_synchronize"
30+
public static let method: String = "workspace/synchronize"
1831
public typealias Response = VoidResponse
1932

2033
/// Wait for the build server to have an up-to-date build graph by sending a `workspace/waitForBuildSystemUpdates` to
2134
/// it.
35+
/// This is implied by `index = true`.
36+
///
37+
/// This option is experimental, guarded behind the `synchronize-for-build-system-updates` experimental feature, and
38+
/// may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
2239
public var buildServerUpdates: Bool?
2340

2441
/// Wait for background indexing to finish and all index unit files to be loaded into indexstore-db.
25-
///
26-
/// Implies `buildServerUpdates = true`.
2742
public var index: Bool?
2843

2944
public init(buildServerUpdates: Bool? = nil, index: Bool? = nil) {

Sources/SKOptions/ExperimentalFeatures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public enum ExperimentalFeature: String, Codable, Sendable, CaseIterable {
4040
/// - Note: Internal option
4141
case outputPathsRequest = "output-paths-request"
4242

43-
/// Enable the `workspace/_synchronize` request.
43+
/// Enable the `buildServerUpdates` option in the `workspace/synchronize` request.
4444
///
4545
/// - Note: Internal option, for testing only
46-
case synchronizeRequest = "synchronize-request"
46+
case synchronizeForBuildSystemUpdates = "synchronize-for-build-system-updates"
4747
}

Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension SourceKitLSPOptions {
3636
servicePlugin: try pluginPaths.servicePlugin.filePath
3737
),
3838
backgroundIndexing: backgroundIndexing,
39-
experimentalFeatures: experimentalFeatures.union([.synchronizeRequest]),
39+
experimentalFeatures: experimentalFeatures,
4040
swiftPublishDiagnosticsDebounceDuration: 0,
4141
workDoneProgressDebounceDuration: 0
4242
)

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,8 +2540,8 @@ extension SourceKitLSPServer {
25402540
}
25412541

25422542
func synchronize(_ req: SynchronizeRequest) async throws -> VoidResponse {
2543-
guard self.options.hasExperimentalFeature(.synchronizeRequest) else {
2544-
throw ResponseError.unknown("\(SynchronizeRequest.method) indexing is an experimental request")
2543+
if req.buildServerUpdates != nil, !self.options.hasExperimentalFeature(.synchronizeForBuildSystemUpdates) {
2544+
throw ResponseError.unknown("\(SynchronizeRequest.method).buildServerUpdates is an experimental request option")
25452545
}
25462546
for workspace in workspaces {
25472547
await workspace.synchronize(req)

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,10 +1633,7 @@ final class BackgroundIndexingTests: XCTestCase {
16331633
]
16341634
)
16351635
""",
1636-
options: SourceKitLSPOptions(
1637-
backgroundPreparationMode: .enabled,
1638-
experimentalFeatures: [.synchronizeRequest]
1639-
),
1636+
options: SourceKitLSPOptions(backgroundPreparationMode: .enabled),
16401637
enableBackgroundIndexing: true
16411638
)
16421639

0 commit comments

Comments
 (0)