Skip to content

Commit 216609f

Browse files
authored
Merge pull request #2632 from rintaro/message-sourcekit-prefix
Prefix LSP/BSP extension methods with `sourcekit/`
2 parents 7323a95 + 25a8eb7 commit 216609f

12 files changed

Lines changed: 141 additions & 88 deletions

Contributor Documentation/BSP Extensions.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface SourceKitInitializeBuildResponseData {
2828
/** Whether the build server supports the `buildTarget/prepare` request */
2929
prepareProvider?: bool;
3030

31-
/** Whether the server implements the `textDocument/sourceKitOptions` request. */
31+
/** Whether the server implements the `sourcekit/textDocument/sourceKitOptions` request. */
3232
sourceKitOptionsProvider?: bool;
3333

3434
/** The files to watch for changes.
@@ -91,18 +91,21 @@ If `data` contains a string value for the `workDoneProgressTitle` key, then the
9191

9292
`changes` can be `null` to indicate that all targets have changed.
9393

94-
## `buildTarget/prepare`
94+
## `sourcekit/buildTarget/prepare`
9595

9696
The prepare build target request is sent from the client to the server to prepare the given list of build targets for editor functionality.
9797

9898
To do so, the build server should perform any work that is necessary to typecheck the files in the given target. This includes, but is not limited to: Building Swift modules for all dependencies and running code generation scripts. Compared to a full build, the build server may skip actions that are not necessary for type checking, such as object file generation but the exact steps necessary are dependent on the build system. SwiftPM implements this step using the `swift build --experimental-prepare-for-indexing` command.
9999

100100
The server communicates during the initialize handshake whether this method is supported or not by setting `prepareProvider: true` in `SourceKitInitializeBuildResponseData`.
101101

102-
- method: `buildTarget/prepare`
102+
- method: `sourcekit/buildTarget/prepare`
103103
- params: `PrepareParams`
104104
- result: `void`
105105

106+
> [!NOTE]
107+
> This request was previously named `buildTarget/prepare`. The old name is still accepted for backward compatibility.
108+
106109
```ts
107110
export interface PrepareParams {
108111
/** A list of build targets to prepare. */
@@ -156,18 +159,23 @@ export interface SourceKitSourceItemData {
156159
}
157160
```
158161

159-
## `textDocument/sourceKitOptions`
162+
## `sourcekit/textDocument/sourceKitOptions`
160163

161164
The `TextDocumentSourceKitOptionsRequest` request is sent from the client to the server to query for the list of compiler options necessary to compile this file in the given target.
162165

163166
The build settings are considered up-to-date and can be cached by SourceKit-LSP until a `buildTarget/didChange` is sent for the requested target.
164167

165168
The request may return `nil` if it doesn't have any build settings for this file in the given target.
166169

167-
- method: `textDocument/sourceKitOptions`
170+
- method: `sourcekit/textDocument/sourceKitOptions`
168171
- params: `TextDocumentSourceKitOptionsParams`
169172
- result: `TextDocumentSourceKitOptionsResult`
170173

174+
> [!NOTE]
175+
> This request was previously named `textDocument/sourceKitOptions`. The old name is still accepted for backward compatibility.
176+
177+
Also note that the `data` field in `TextDocumentSourceKitOptionsResult` is exposed to LSP clients via `sourcekit/workspace/sourceKitOptions` (previously `workspace/_sourceKitOptions`).
178+
171179
```ts
172180
export interface TextDocumentSourceKitOptionsRequest {
173181
/** The URI of the document to get options for */
@@ -236,10 +244,13 @@ SourceKit-LSP may send file change notifications for a superset of the files tha
236244

237245
Definition is the same as in LSP.
238246

239-
## `workspace/waitForBuildSystemUpdates`
247+
## `sourcekit/workspace/waitForBuildSystemUpdates`
240248

241249
This request is a no-op and doesn't have any effects.
242250

243251
If the build server is currently updating the build graph, this request should return after those updates have finished processing.
244252

245-
- method: `workspace/waitForBuildSystemUpdates`
253+
- method: `sourcekit/workspace/waitForBuildSystemUpdates`
254+
255+
> [!NOTE]
256+
> This request was previously named `workspace/waitForBuildSystemUpdates`. The old name is still accepted for backward compatibility.

Contributor Documentation/LSP Extensions.md

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ interface SKCompletionOptions {
103103
}
104104
```
105105
106-
## `textDocument/doccDocumentation`
106+
## `sourcekit/textDocument/doccDocumentation`
107107
108108
New request that generates documentation for a symbol at a given cursor location.
109109
110+
> [!NOTE]
111+
> This request was previously named `textDocument/doccDocumentation`. The old name is still accepted for backward compatibility.
112+
110113
Primarily designed to support live preview of Swift documentation in editors.
111114
112115
This request looks up the nearest documentable symbol (if any) at a given cursor location within
@@ -124,7 +127,7 @@ failed LSP error code (-32803) that contains a human-readable error message. Thi
124127
be displayed within the live preview editor to indicate that something has gone wrong.
125128
126129
At the moment this request is only available on macOS and Linux. SourceKit-LSP will advertise
127-
`textDocument/doccDocumentation` in its experimental server capabilities if it supports it.
130+
`sourcekit/textDocument/doccDocumentation` in its experimental server capabilities if it supports it.
128131
129132
- params: `DoccDocumentationParams`
130133
- result: `DoccDocumentationResponse`
@@ -285,10 +288,13 @@ interface SymbolDetails {
285288
}
286289
```
287290
288-
## `textDocument/tests`
291+
## `sourcekit/textDocument/tests`
289292
290293
New request that returns symbols for all the test classes and test methods within a file.
291294
295+
> [!NOTE]
296+
> This request was previously named `textDocument/tests`. The old name is still accepted for backward compatibility.
297+
292298
- params: `DocumentTestsParams`
293299
- result: `TestItem[]`
294300
@@ -368,10 +374,13 @@ export interface DocumentTestsParams {
368374
}
369375
```
370376
371-
## `sourceKit/_isIndexing`
377+
## `sourcekit/isIndexing`
372378
373379
Request from the client to the server querying whether SourceKit-LSP is currently performing an background indexing tasks, including target preparation.
374380
381+
> [!NOTE]
382+
> This request was previously named `sourceKit/_isIndexing`. The old name is still accepted for backward compatibility.
383+
375384
> [!IMPORTANT]
376385
> This request is experimental and may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
377386
@@ -448,18 +457,21 @@ export interface WorkspaceSymbolNamesResult {
448457
}
449458
```
450459

451-
## `window/didChangeActiveDocument`
460+
## `sourcekit/window/didChangeActiveDocument`
452461

453462
New notification from the client to the server, telling SourceKit-LSP which document is the currently active primary document.
454463

455464
This notification should only be called for documents that the editor has opened in SourceKit-LSP using the `textDocument/didOpen` notification.
456465

457466
By default, SourceKit-LSP infers the currently active editor document from the last document that received a request.
458467
If the client supports active reporting of the currently active document, it should check for the
459-
`window/didChangeActiveDocument` experimental server capability. If that capability is present, it should respond with
460-
the `window/didChangeActiveDocument` experimental client capability and send this notification whenever the currently
468+
`sourcekit/window/didChangeActiveDocument` experimental server capability. If that capability is present, it should respond with
469+
the `sourcekit/window/didChangeActiveDocument` experimental client capability and send this notification whenever the currently
461470
active document changes.
462471

472+
> [!NOTE]
473+
> This notification was previously named `window/didChangeActiveDocument`. The old name is still accepted for backward compatibility.
474+
463475
- params: `DidChangeActiveDocumentParams`
464476

465477
```ts
@@ -533,12 +545,15 @@ export interface StructuredLogEnd {
533545
}
534546
```
535547

536-
## `workspace/_setOptions`
548+
## `sourcekit/workspace/setOptions`
537549

538550
New request to modify runtime options of SourceKit-LSP.
539551

540552
Any options not specified in this request will be left as-is.
541553

554+
> [!NOTE]
555+
> This request was previously named `workspace/_setOptions`. The old name is still accepted for backward compatibility.
556+
542557
> [!IMPORTANT]
543558
> This request is experimental, guarded behind the `set-options-request` experimental feature, and may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
544559

@@ -554,12 +569,15 @@ export interface SetOptionsParams {
554569
}
555570
```
556571

557-
## `workspace/_sourceKitOptions`
572+
## `sourcekit/workspace/sourceKitOptions`
558573

559574
New request from the client to the server to retrieve the compiler arguments that SourceKit-LSP uses to process the document.
560575

561576
This request does not require the document to be opened in SourceKit-LSP. This is also why it has the `workspace/` instead of the `textDocument/` prefix.
562577

578+
> [!NOTE]
579+
> This request was previously named `workspace/_sourceKitOptions`. The old name is still accepted for backward compatibility.
580+
563581
> [!IMPORTANT]
564582
> This request is experimental, guarded behind the `sourcekit-options-request` experimental feature, and may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
565583

@@ -651,12 +669,15 @@ export interface SourceKitOptionsResult {
651669
}
652670
```
653671

654-
## `workspace/_outputPaths`
672+
## `sourcekit/workspace/outputPaths`
655673

656674
New request from the client to the server to retrieve the output paths of a target (see the `buildTarget/outputPaths` BSP request).
657675

658676
This request will only succeed if the build server supports the `buildTarget/outputPaths` request.
659677

678+
> [!NOTE]
679+
> This request was previously named `workspace/_outputPaths`. The old name is still accepted for backward compatibility.
680+
660681
> [!IMPORTANT]
661682
> This request is experimental, guarded behind the `output-paths-request` experimental feature, and may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.
662683

@@ -685,12 +706,15 @@ export interface OutputPathsResult {
685706
}
686707
```
687708

688-
## `workspace/getReferenceDocument`
709+
## `sourcekit/workspace/getReferenceDocument`
689710

690711
Request from the client to the server asking for contents of a URI having a custom scheme.
691712
For example: "sourcekit-lsp:"
692713

693-
Enable the experimental client capability `"workspace/getReferenceDocument"` so that the server responds with reference document URLs for certain requests or commands whenever possible.
714+
Enable the experimental client capability `"sourcekit/workspace/getReferenceDocument"` so that the server responds with reference document URLs for certain requests or commands whenever possible.
715+
716+
> [!NOTE]
717+
> This request was previously named `workspace/getReferenceDocument`. The old name is still accepted for backward compatibility.
694718

695719
- params: `GetReferenceDocumentParams`
696720

@@ -712,13 +736,16 @@ export interface GetReferenceDocumentResult {
712736
}
713737
```
714738

715-
## `workspace/peekDocuments`
739+
## `sourcekit/workspace/peekDocuments`
716740

717741
Request from the server to the client to show the given documents in a "peeked" editor.
718742

719743
This request is handled by the client to show the given documents in a "peeked" editor (i.e. inline with / inside the editor canvas).
720744

721-
It requires the experimental client capability `"workspace/peekDocuments"` to use.
745+
It requires the experimental client capability `"sourcekit/workspace/peekDocuments"` to use.
746+
747+
> [!NOTE]
748+
> This request was previously named `workspace/peekDocuments`. The old name is still accepted for backward compatibility.
722749

723750
- params: `PeekDocumentsParams`
724751
- result: `PeekDocumentsResult`
@@ -749,7 +776,7 @@ export interface PeekDocumentsResult {
749776
}
750777
```
751778

752-
## `workspace/playgrounds`
779+
## `sourcekit/workspace/playgrounds`
753780

754781
New request for returning the list of all #Playground macros in the workspace.
755782

@@ -758,9 +785,12 @@ jumping to the locations where the #Playground macro was expanded.
758785

759786
The request fetches the list of all macros found in the workspace, returning the location, identifier, and optional label
760787
when available for each #Playground macro expansion. If you want to keep the list of playgrounds up to date without needing to
761-
call `workspace/playgrounds` each time a document is changed, you can filter for `swift.play` CodeLens returned by the `textDocument/codelens` request.
788+
call `sourcekit/workspace/playgrounds` each time a document is changed, you can filter for `swift.play` CodeLens returned by the `textDocument/codelens` request.
789+
790+
SourceKit-LSP will advertise `sourcekit/workspace/playgrounds` in its experimental server capabilities if it supports it.
762791

763-
SourceKit-LSP will advertise `workspace/playgrounds` in its experimental server capabilities if it supports it.
792+
> [!NOTE]
793+
> This request was previously named `workspace/playgrounds`. The old name is still accepted for backward compatibility.
764794

765795
- params: `WorkspacePlaygroundParams`
766796
- result: `Playground[]`
@@ -795,10 +825,13 @@ export interface Playground {
795825
}
796826
```
797827
798-
## `workspace/synchronize`
828+
## `sourcekit/workspace/synchronize`
799829
800830
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.
801831
832+
> [!NOTE]
833+
> This request was previously named `workspace/synchronize`. The old name is still accepted for backward compatibility.
834+
802835
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:
803836
- Automated tests that need to wait for background indexing to finish and then checking the result of request results
804837
- Automated tests that need to wait for requests like file changes to be handled and checking behavior after those have been processed
@@ -837,23 +870,29 @@ export interface SynchronizeParams {
837870
}
838871
```
839872
840-
## `workspace/tests`
873+
## `sourcekit/workspace/tests`
841874
842875
New request that returns symbols for all the test classes and test methods within the current workspace.
843876
877+
> [!NOTE]
878+
> This request was previously named `workspace/tests`. The old name is still accepted for backward compatibility.
879+
844880
- params: `WorkspaceTestsParams`
845881
- result: `TestItem[]`
846882
847883
```ts
848884
export interface WorkspaceTestsParams {}
849885
```
850886
851-
## `workspace/triggerReindex`
887+
## `sourcekit/workspace/triggerReindex`
852888
853889
New request to re-index all files open in the SourceKit-LSP server.
854890
855891
Users should not need to rely on this request. The index should always be updated automatically in the background. Having to invoke this request means there is a bug in SourceKit-LSP's automatic re-indexing. It does, however, offer a workaround to re-index files when such a bug occurs where otherwise there would be no workaround.
856892
893+
> [!NOTE]
894+
> This request was previously named `workspace/triggerReindex`. The old name is still accepted for backward compatibility.
895+
857896
858897
- params: `TriggerReindexParams`
859898
- result: `void`

Sources/BuildServerIntegration/BuildServerManager.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,29 @@ package actor BuildServerManager: QueueBasedMessageHandler {
629629
}
630630
let initializeResponse: InitializeBuildResponse?
631631
do {
632+
var experimentalCapabilities: [String: LSPAny] = [:]
633+
func addCapability(_ method: String, _ value: LSPAny) {
634+
experimentalCapabilities[method] = value
635+
if let legacy = MessageRegistry.bspLegacyNames[method] {
636+
experimentalCapabilities[legacy] = value
637+
}
638+
}
639+
// client -> server
640+
addCapability(BuildTargetPrepareRequest.method, .dictionary(["version": .int(1)]))
641+
addCapability(TextDocumentSourceKitOptionsRequest.method, .dictionary(["version": .int(1)]))
642+
addCapability(WorkspaceWaitForBuildSystemUpdatesRequest.method, .dictionary(["version": .int(1)]))
643+
// server -> client
644+
addCapability(FileOptionsChangedNotification.method, .dictionary(["version": .int(1)]))
632645
initializeResponse = try await buildServerAdapter.send(
633646
InitializeBuildRequest(
634647
displayName: "SourceKit-LSP",
635648
version: "",
636649
bspVersion: "2.2.0",
637650
rootUri: URI(buildServerSpec.projectRoot),
638-
capabilities: BuildClientCapabilities(languageIds: [.c, .cpp, .objective_c, .objective_cpp, .swift])
651+
capabilities: BuildClientCapabilities(
652+
languageIds: [.c, .cpp, .objective_c, .objective_cpp, .swift],
653+
experimental: .dictionary(experimentalCapabilities)
654+
)
639655
)
640656
)
641657
} catch {

Sources/BuildServerIntegration/ExternalBuildServerAdapter.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ actor ExternalBuildServerAdapter {
191191
var messagesToSourceKitLSPHandler: any MessageHandler
192192

193193
/// The JSON-RPC connection between SourceKit-LSP and the BSP server.
194-
private(set) var connectionToBuildServer: JSONRPCConnection?
194+
private(set) var connectionToBuildServer: LegacyNameFallbackConnection?
195195

196196
/// After a `build/initialize` request has been sent to the BSP server, that request, so we can replay it in case the
197197
/// server crashes.
@@ -224,7 +224,10 @@ actor ExternalBuildServerAdapter {
224224
self.projectRoot = projectRoot
225225
self.serverConfig = config
226226
self.messagesToSourceKitLSPHandler = messagesToSourceKitLSPHandler
227-
self.connectionToBuildServer = try await self.createConnectionToBspServer()
227+
self.connectionToBuildServer = LegacyNameFallbackConnection(
228+
try await self.createConnectionToBspServer(),
229+
legacyNames: MessageRegistry.bspLegacyNames
230+
)
228231
}
229232

230233
init(
@@ -401,7 +404,10 @@ actor ExternalBuildServerAdapter {
401404
// crash recovery and doesn't need to gain it because it is deprecated).
402405
_ = try await restartedConnection.send(initializeRequest)
403406
restartedConnection.send(OnBuildInitializedNotification())
404-
self.connectionToBuildServer = restartedConnection
407+
self.connectionToBuildServer = LegacyNameFallbackConnection(
408+
restartedConnection,
409+
legacyNames: MessageRegistry.bspLegacyNames
410+
)
405411

406412
// The build targets might have changed after the restart. Send a `buildTarget/didChange` notification to
407413
// SourceKit-LSP to discard cached information.

Sources/BuildServerIntegration/LegacyBuildServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import ToolsProtocolsSwiftExtensions
3434
/// This build server should be phased out in favor of the pull-based settings model described in
3535
/// https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400
3636
actor LegacyBuildServer: MessageHandler, BuiltInBuildServer {
37-
private var buildServer: JSONRPCConnection?
37+
private var buildServer: (any Connection)?
3838

3939
/// The queue on which all messages that originate from the build server are
4040
/// handled.

Sources/LanguageServerProtocolExtensions/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
add_library(LanguageServerProtocolExtensions STATIC
3-
Connection+Send.swift
43
DocumentURI+symlinkTarget.swift
54
Language+Inference.swift
65
ResponseError+Init.swift

0 commit comments

Comments
 (0)