Skip to content

Commit 93c9f2b

Browse files
committed
Prefix SourceKit-LSP extension methods with sourcekit/
Rename all SourceKit-LSP–specific LSP and BSP extension requests and notifications to use the `sourcekit/` prefix (e.g. `workspace/tests` → `sourcekit/workspace/tests`). * Register the legacy name alias in `MessageRegistry` so incoming messages from existing clients are still dispatched correctly. * Advertise both the new and legacy method names in the `experimental` capability dict so old clients can still discover the capabilities they know. * Accept legacy names advertised by old clients in `CapabilityRegistry`. * Use `LegacyNameFallbackConnection` to retry requests with the legacy method name when the peer returns `methodNotFound` for a `sourcekit/`-prefixed request. Used in: * `SourceKitLSPServer.client` (server→client) to keep old editors working * `ExternalBuildServerAdapter.connectionToBuildServer` (SourceKit-LSP→BSP) to keep old build servers working
1 parent ec0080e commit 93c9f2b

11 files changed

Lines changed: 120 additions & 85 deletions

File tree

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
@@ -389,18 +398,21 @@ export interface IsIndexingResult {
389398
}
390399
```
391400
392-
## `window/didChangeActiveDocument`
401+
## `sourcekit/window/didChangeActiveDocument`
393402
394403
New notification from the client to the server, telling SourceKit-LSP which document is the currently active primary document.
395404
396405
This notification should only be called for documents that the editor has opened in SourceKit-LSP using the `textDocument/didOpen` notification.
397406
398407
By default, SourceKit-LSP infers the currently active editor document from the last document that received a request.
399408
If the client supports active reporting of the currently active document, it should check for the
400-
`window/didChangeActiveDocument` experimental server capability. If that capability is present, it should respond with
401-
the `window/didChangeActiveDocument` experimental client capability and send this notification whenever the currently
409+
`sourcekit/window/didChangeActiveDocument` experimental server capability. If that capability is present, it should respond with
410+
the `sourcekit/window/didChangeActiveDocument` experimental client capability and send this notification whenever the currently
402411
active document changes.
403412
413+
> [!NOTE]
414+
> This notification was previously named `window/didChangeActiveDocument`. The old name is still accepted for backward compatibility.
415+
404416
- params: `DidChangeActiveDocumentParams`
405417
406418
```ts
@@ -474,12 +486,15 @@ export interface StructuredLogEnd {
474486
}
475487
```
476488
477-
## `workspace/_setOptions`
489+
## `sourcekit/workspace/setOptions`
478490
479491
New request to modify runtime options of SourceKit-LSP.
480492
481493
Any options not specified in this request will be left as-is.
482494
495+
> [!NOTE]
496+
> This request was previously named `workspace/_setOptions`. The old name is still accepted for backward compatibility.
497+
483498
> [!IMPORTANT]
484499
> 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.
485500
@@ -495,12 +510,15 @@ export interface SetOptionsParams {
495510
}
496511
```
497512
498-
## `workspace/_sourceKitOptions`
513+
## `sourcekit/workspace/sourceKitOptions`
499514
500515
New request from the client to the server to retrieve the compiler arguments that SourceKit-LSP uses to process the document.
501516
502517
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.
503518
519+
> [!NOTE]
520+
> This request was previously named `workspace/_sourceKitOptions`. The old name is still accepted for backward compatibility.
521+
504522
> [!IMPORTANT]
505523
> 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.
506524
@@ -592,12 +610,15 @@ export interface SourceKitOptionsResult {
592610
}
593611
```
594612
595-
## `workspace/_outputPaths`
613+
## `sourcekit/workspace/outputPaths`
596614
597615
New request from the client to the server to retrieve the output paths of a target (see the `buildTarget/outputPaths` BSP request).
598616
599617
This request will only succeed if the build server supports the `buildTarget/outputPaths` request.
600618
619+
> [!NOTE]
620+
> This request was previously named `workspace/_outputPaths`. The old name is still accepted for backward compatibility.
621+
601622
> [!IMPORTANT]
602623
> 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.
603624
@@ -626,12 +647,15 @@ export interface OutputPathsResult {
626647
}
627648
```
628649
629-
## `workspace/getReferenceDocument`
650+
## `sourcekit/workspace/getReferenceDocument`
630651
631652
Request from the client to the server asking for contents of a URI having a custom scheme.
632653
For example: "sourcekit-lsp:"
633654
634-
Enable the experimental client capability `"workspace/getReferenceDocument"` so that the server responds with reference document URLs for certain requests or commands whenever possible.
655+
Enable the experimental client capability `"sourcekit/workspace/getReferenceDocument"` so that the server responds with reference document URLs for certain requests or commands whenever possible.
656+
657+
> [!NOTE]
658+
> This request was previously named `workspace/getReferenceDocument`. The old name is still accepted for backward compatibility.
635659
636660
- params: `GetReferenceDocumentParams`
637661
@@ -653,13 +677,16 @@ export interface GetReferenceDocumentResult {
653677
}
654678
```
655679
656-
## `workspace/peekDocuments`
680+
## `sourcekit/workspace/peekDocuments`
657681
658682
Request from the server to the client to show the given documents in a "peeked" editor.
659683
660684
This request is handled by the client to show the given documents in a "peeked" editor (i.e. inline with / inside the editor canvas).
661685
662-
It requires the experimental client capability `"workspace/peekDocuments"` to use.
686+
It requires the experimental client capability `"sourcekit/workspace/peekDocuments"` to use.
687+
688+
> [!NOTE]
689+
> This request was previously named `workspace/peekDocuments`. The old name is still accepted for backward compatibility.
663690
664691
- params: `PeekDocumentsParams`
665692
- result: `PeekDocumentsResult`
@@ -690,7 +717,7 @@ export interface PeekDocumentsResult {
690717
}
691718
```
692719
693-
## `workspace/playgrounds`
720+
## `sourcekit/workspace/playgrounds`
694721
695722
New request for returning the list of all #Playground macros in the workspace.
696723
@@ -699,9 +726,12 @@ jumping to the locations where the #Playground macro was expanded.
699726
700727
The request fetches the list of all macros found in the workspace, returning the location, identifier, and optional label
701728
when available for each #Playground macro expansion. If you want to keep the list of playgrounds up to date without needing to
702-
call `workspace/playgrounds` each time a document is changed, you can filter for `swift.play` CodeLens returned by the `textDocument/codelens` request.
729+
call `sourcekit/workspace/playgrounds` each time a document is changed, you can filter for `swift.play` CodeLens returned by the `textDocument/codelens` request.
730+
731+
SourceKit-LSP will advertise `sourcekit/workspace/playgrounds` in its experimental server capabilities if it supports it.
703732
704-
SourceKit-LSP will advertise `workspace/playgrounds` in its experimental server capabilities if it supports it.
733+
> [!NOTE]
734+
> This request was previously named `workspace/playgrounds`. The old name is still accepted for backward compatibility.
705735
706736
- params: `WorkspacePlaygroundParams`
707737
- result: `Playground[]`
@@ -736,10 +766,13 @@ export interface Playground {
736766
}
737767
```
738768
739-
## `workspace/synchronize`
769+
## `sourcekit/workspace/synchronize`
740770
741771
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.
742772
773+
> [!NOTE]
774+
> This request was previously named `workspace/synchronize`. The old name is still accepted for backward compatibility.
775+
743776
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:
744777
- Automated tests that need to wait for background indexing to finish and then checking the result of request results
745778
- Automated tests that need to wait for requests like file changes to be handled and checking behavior after those have been processed
@@ -778,23 +811,29 @@ export interface SynchronizeParams {
778811
}
779812
```
780813
781-
## `workspace/tests`
814+
## `sourcekit/workspace/tests`
782815
783816
New request that returns symbols for all the test classes and test methods within the current workspace.
784817
818+
> [!NOTE]
819+
> This request was previously named `workspace/tests`. The old name is still accepted for backward compatibility.
820+
785821
- params: `WorkspaceTestsParams`
786822
- result: `TestItem[]`
787823
788824
```ts
789825
export interface WorkspaceTestsParams {}
790826
```
791827
792-
## `workspace/triggerReindex`
828+
## `sourcekit/workspace/triggerReindex`
793829
794830
New request to re-index all files open in the SourceKit-LSP server.
795831
796832
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.
797833
834+
> [!NOTE]
835+
> This request was previously named `workspace/triggerReindex`. The old name is still accepted for backward compatibility.
836+
798837
799838
- params: `TriggerReindexParams`
800839
- result: `void`

Sources/BuildServerIntegration/ExternalBuildServerAdapter.swift

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

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

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

229232
init(
@@ -400,7 +403,10 @@ actor ExternalBuildServerAdapter {
400403
// crash recovery and doesn't need to gain it because it is deprecated).
401404
_ = try await restartedConnection.send(initializeRequest)
402405
restartedConnection.send(OnBuildInitializedNotification())
403-
self.connectionToBuildServer = restartedConnection
406+
self.connectionToBuildServer = LegacyNameFallbackConnection(
407+
restartedConnection,
408+
legacyNames: MessageRegistry.bspLegacyNames
409+
)
404410

405411
// The build targets might have changed after the restart. Send a `buildTarget/didChange` notification to
406412
// 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)