Skip to content

Commit 1f1e440

Browse files
authored
Merge pull request #2060 from ahoppen/synchronize-request
Generalize `PollIndexRequest` and `BarrierRequest` into a single `SynchronizeRequest`
2 parents 6eb8006 + 5fba169 commit 1f1e440

25 files changed

+144
-127
lines changed

Contributor Documentation/LSP Extensions.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -546,20 +546,6 @@ export interface StructuredLogEnd {
546546
}
547547
```
548548
549-
## `workspace/_pollIndex`
550-
551-
New request to wait until the index is up-to-date.
552-
553-
> [!IMPORTANT]
554-
> This request is experimental and may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
555-
556-
- params: `PollIndexParams`
557-
- result: `void`
558-
559-
```ts
560-
export interface PollIndexParams {}
561-
```
562-
563549
## `workspace/_setOptions`
564550
565551
New request to modify runtime options of SourceKit-LSP.
@@ -678,6 +664,33 @@ export interface SourceKitOptionsResult {
678664
}
679665
```
680666
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+
681694
## `workspace/_outputPaths`
682695
683696
New request from the client to the server to retrieve the output paths of a target (see the `buildTarget/outputPaths` BSP request).

Documentation/Configuration File.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The structure of the file is currently not guaranteed to be stable. Options may
5454
- `noLazy`: Prepare a target without generating object files but do not do lazy type checking and function body skipping. This uses SwiftPM's `--experimental-prepare-for-indexing-no-lazy` flag.
5555
- `enabled`: Prepare a target without generating object files.
5656
- `cancelTextDocumentRequestsOnEditAndClose: boolean`: Whether sending a `textDocument/didChange` or `textDocument/didClose` notification for a document should cancel all pending requests for that document.
57-
- `experimentalFeatures: ("on-type-formatting"|"set-options-request"|"sourcekit-options-request"|"is-indexing-request"|"structured-logs"|"output-paths-request")[]`: Experimental features that are enabled.
57+
- `experimentalFeatures: ("on-type-formatting"|"structured-logs")[]`: Experimental features that are enabled.
5858
- `swiftPublishDiagnosticsDebounceDuration: number`: The time that `SwiftLanguageService` should wait after an edit before starting to compute diagnostics and sending a `PublishDiagnosticsNotification`.
5959
- `workDoneProgressDebounceDuration: number`: When a task is started that should be displayed to the client as a work done progress, how many milliseconds to wait before actually starting the work done progress. This prevents flickering of the work done progress in the client for short-lived index tasks which end within this duration.
6060
- `sourcekitdRequestTimeout: number`: The maximum duration that a sourcekitd request should be allowed to execute before being declared as timed out. In general, editors should cancel requests that they are no longer interested in, but in case editors don't cancel requests, this ensures that a long-running non-cancelled request is not blocking sourcekitd and thus most semantic functionality. In particular, VS Code does not cancel the semantic tokens request, which can cause a long-running AST build that blocks sourcekitd.

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/OptionSchema.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct OptionSchemaContext {
150150
guard let caseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
151151
return []
152152
}
153-
return try caseDecl.elements.map {
153+
return try caseDecl.elements.compactMap {
154154
guard $0.parameterClause == nil else {
155155
throw ConfigSchemaGenError("Associated values in enum cases are not supported: \(caseDecl)")
156156
}
@@ -168,7 +168,11 @@ struct OptionSchemaContext {
168168
} else {
169169
name = $0.name.text
170170
}
171-
return OptionTypeSchama.Case(name: name, description: Self.extractDocComment(caseDecl.leadingTrivia))
171+
let description = Self.extractDocComment(caseDecl.leadingTrivia)
172+
if description?.contains("- Note: Internal option") ?? false {
173+
return nil
174+
}
175+
return OptionTypeSchama.Case(name: name, description: description)
172176
}
173177
}
174178
let typeName = node.name.text

Sources/Diagnose/IndexCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ package struct IndexCommand: AsyncParsableCommand {
103103
messageHandler: messageHandler
104104
)
105105
let start = ContinuousClock.now
106-
_ = try await inProcessClient.send(PollIndexRequest())
106+
_ = try await inProcessClient.send(SynchronizeRequest(index: true))
107107
print("Indexing finished in \(start.duration(to: .now))")
108108
if await messageHandler.hasSeenError {
109109
throw ExitCode(1)

Sources/LanguageServerProtocol/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ add_library(LanguageServerProtocol STATIC
2727
Notifications/WorkDoneProgress.swift
2828

2929
Requests/ApplyEditRequest.swift
30-
Requests/BarrierRequest.swift
3130
Requests/CallHierarchyIncomingCallsRequest.swift
3231
Requests/CallHierarchyOutgoingCallsRequest.swift
3332
Requests/CallHierarchyPrepareRequest.swift
@@ -72,7 +71,6 @@ add_library(LanguageServerProtocol STATIC
7271
Requests/MonikersRequest.swift
7372
Requests/OutputPathsRequest.swift
7473
Requests/PeekDocumentsRequest.swift
75-
Requests/PollIndexRequest.swift
7674
Requests/PrepareRenameRequest.swift
7775
Requests/ReferencesRequest.swift
7876
Requests/RegisterCapabilityRequest.swift
@@ -85,6 +83,7 @@ add_library(LanguageServerProtocol STATIC
8583
Requests/SignatureHelpRequest.swift
8684
Requests/SourceKitOptionsRequest.swift
8785
Requests/SymbolInfoRequest.swift
86+
Requests/SynchronizeRequest.swift
8887
Requests/TriggerReindexRequest.swift
8988
Requests/TypeDefinitionRequest.swift
9089
Requests/TypeHierarchyPrepareRequest.swift

Sources/LanguageServerProtocol/Messages.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
1818
public let builtinRequests: [_RequestType.Type] = [
1919
ApplyEditRequest.self,
20-
BarrierRequest.self,
2120
CallHierarchyIncomingCallsRequest.self,
2221
CallHierarchyOutgoingCallsRequest.self,
2322
CallHierarchyPrepareRequest.self,
@@ -63,7 +62,7 @@ public let builtinRequests: [_RequestType.Type] = [
6362
MonikersRequest.self,
6463
OutputPathsRequest.self,
6564
PeekDocumentsRequest.self,
66-
PollIndexRequest.self,
65+
SynchronizeRequest.self,
6766
PrepareRenameRequest.self,
6867
ReferencesRequest.self,
6968
RegisterCapabilityRequest.self,

Sources/LanguageServerProtocol/Requests/BarrierRequest.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

Sources/LanguageServerProtocol/Requests/PollIndexRequest.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// Wait for SourceKit-LSP to handle all ongoing requests and, optionally, wait for background activity to finish.
14+
///
15+
/// **LSP Extension, For Testing**.
16+
public struct SynchronizeRequest: RequestType {
17+
public static let method: String = "workspace/_synchronize"
18+
public typealias Response = VoidResponse
19+
20+
/// Wait for the build server to have an up-to-date build graph by sending a `workspace/waitForBuildSystemUpdates` to
21+
/// it.
22+
public var buildServerUpdates: Bool?
23+
24+
/// Wait for background indexing to finish and all index unit files to be loaded into indexstore-db.
25+
///
26+
/// Implies `buildServerUpdates = true`.
27+
public var index: Bool?
28+
29+
public init(buildServerUpdates: Bool? = nil, index: Bool? = nil) {
30+
self.buildServerUpdates = buildServerUpdates
31+
self.index = index
32+
}
33+
}

Sources/SKOptions/ExperimentalFeatures.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,30 @@ public enum ExperimentalFeature: String, Codable, Sendable, CaseIterable {
1818
case onTypeFormatting = "on-type-formatting"
1919

2020
/// Enable support for the `workspace/_setOptions` request.
21+
///
22+
/// - Note: Internal option
2123
case setOptionsRequest = "set-options-request"
2224

2325
/// Enable the `workspace/_sourceKitOptions` request.
26+
///
27+
/// - Note: Internal option
2428
case sourceKitOptionsRequest = "sourcekit-options-request"
2529

2630
/// Enable the `sourceKit/_isIndexing` request.
31+
///
32+
/// - Note: Internal option
2733
case isIndexingRequest = "is-indexing-request"
2834

2935
/// Indicate that the client can handle the experimental `structure` field in the `window/logMessage` notification.
3036
case structuredLogs = "structured-logs"
3137

3238
/// Enable the `workspace/_outputPaths` request.
39+
///
40+
/// - Note: Internal option
3341
case outputPathsRequest = "output-paths-request"
42+
43+
/// Enable the `workspace/_synchronize` request.
44+
///
45+
/// - Note: Internal option, for testing only
46+
case synchronizeRequest = "synchronize-request"
3447
}

0 commit comments

Comments
 (0)