Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions Contributor Documentation/BSP Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface SourceKitInitializeBuildResponseData {
/** Whether the build server supports the `buildTarget/prepare` request */
prepareProvider?: bool;

/** Whether the server implements the `textDocument/sourceKitOptions` request. */
/** Whether the server implements the `sourcekit/textDocument/sourceKitOptions` request. */
sourceKitOptionsProvider?: bool;

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

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

## `buildTarget/prepare`
## `sourcekit/buildTarget/prepare`

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

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.

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

- method: `buildTarget/prepare`
- method: `sourcekit/buildTarget/prepare`
- params: `PrepareParams`
- result: `void`

> [!NOTE]
> This request was previously named `buildTarget/prepare`. The old name is still accepted for backward compatibility.

```ts
export interface PrepareParams {
/** A list of build targets to prepare. */
Expand Down Expand Up @@ -156,18 +159,23 @@ export interface SourceKitSourceItemData {
}
```

## `textDocument/sourceKitOptions`
## `sourcekit/textDocument/sourceKitOptions`

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.

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.

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

- method: `textDocument/sourceKitOptions`
- method: `sourcekit/textDocument/sourceKitOptions`
- params: `TextDocumentSourceKitOptionsParams`
- result: `TextDocumentSourceKitOptionsResult`

> [!NOTE]
> This request was previously named `textDocument/sourceKitOptions`. The old name is still accepted for backward compatibility.

Also note that the `data` field in `TextDocumentSourceKitOptionsResult` is exposed to LSP clients via `sourcekit/workspace/sourceKitOptions` (previously `workspace/_sourceKitOptions`).

```ts
export interface TextDocumentSourceKitOptionsRequest {
/** The URI of the document to get options for */
Expand Down Expand Up @@ -236,10 +244,13 @@ SourceKit-LSP may send file change notifications for a superset of the files tha

Definition is the same as in LSP.

## `workspace/waitForBuildSystemUpdates`
## `sourcekit/workspace/waitForBuildSystemUpdates`

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

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

- method: `workspace/waitForBuildSystemUpdates`
- method: `sourcekit/workspace/waitForBuildSystemUpdates`

> [!NOTE]
> This request was previously named `workspace/waitForBuildSystemUpdates`. The old name is still accepted for backward compatibility.
79 changes: 59 additions & 20 deletions Contributor Documentation/LSP Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ interface SKCompletionOptions {
}
```

## `textDocument/doccDocumentation`
## `sourcekit/textDocument/doccDocumentation`

New request that generates documentation for a symbol at a given cursor location.

> [!NOTE]
> This request was previously named `textDocument/doccDocumentation`. The old name is still accepted for backward compatibility.

Primarily designed to support live preview of Swift documentation in editors.

This request looks up the nearest documentable symbol (if any) at a given cursor location within
Expand All @@ -124,7 +127,7 @@ failed LSP error code (-32803) that contains a human-readable error message. Thi
be displayed within the live preview editor to indicate that something has gone wrong.

At the moment this request is only available on macOS and Linux. SourceKit-LSP will advertise
`textDocument/doccDocumentation` in its experimental server capabilities if it supports it.
`sourcekit/textDocument/doccDocumentation` in its experimental server capabilities if it supports it.

- params: `DoccDocumentationParams`
- result: `DoccDocumentationResponse`
Expand Down Expand Up @@ -285,10 +288,13 @@ interface SymbolDetails {
}
```

## `textDocument/tests`
## `sourcekit/textDocument/tests`

New request that returns symbols for all the test classes and test methods within a file.

> [!NOTE]
> This request was previously named `textDocument/tests`. The old name is still accepted for backward compatibility.

- params: `DocumentTestsParams`
- result: `TestItem[]`

Expand Down Expand Up @@ -368,10 +374,13 @@ export interface DocumentTestsParams {
}
```

## `sourceKit/_isIndexing`
## `sourcekit/isIndexing`

Request from the client to the server querying whether SourceKit-LSP is currently performing an background indexing tasks, including target preparation.

> [!NOTE]
> This request was previously named `sourceKit/_isIndexing`. The old name is still accepted for backward compatibility.

> [!IMPORTANT]
> This request is experimental and may be modified or removed in future versions of SourceKit-LSP without notice. Do not rely on it.

Expand Down Expand Up @@ -448,18 +457,21 @@ export interface WorkspaceSymbolNamesResult {
}
```

## `window/didChangeActiveDocument`
## `sourcekit/window/didChangeActiveDocument`

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

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

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

> [!NOTE]
> This notification was previously named `window/didChangeActiveDocument`. The old name is still accepted for backward compatibility.

- params: `DidChangeActiveDocumentParams`

```ts
Expand Down Expand Up @@ -533,12 +545,15 @@ export interface StructuredLogEnd {
}
```

## `workspace/_setOptions`
## `sourcekit/workspace/setOptions`

New request to modify runtime options of SourceKit-LSP.

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

> [!NOTE]
> This request was previously named `workspace/_setOptions`. The old name is still accepted for backward compatibility.

> [!IMPORTANT]
> 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.

Expand All @@ -554,12 +569,15 @@ export interface SetOptionsParams {
}
```

## `workspace/_sourceKitOptions`
## `sourcekit/workspace/sourceKitOptions`

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

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.

> [!NOTE]
> This request was previously named `workspace/_sourceKitOptions`. The old name is still accepted for backward compatibility.

> [!IMPORTANT]
> 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.

Expand Down Expand Up @@ -651,12 +669,15 @@ export interface SourceKitOptionsResult {
}
```

## `workspace/_outputPaths`
## `sourcekit/workspace/outputPaths`

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

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

> [!NOTE]
> This request was previously named `workspace/_outputPaths`. The old name is still accepted for backward compatibility.

> [!IMPORTANT]
> 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.

Expand Down Expand Up @@ -685,12 +706,15 @@ export interface OutputPathsResult {
}
```

## `workspace/getReferenceDocument`
## `sourcekit/workspace/getReferenceDocument`

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

Enable the experimental client capability `"workspace/getReferenceDocument"` so that the server responds with reference document URLs for certain requests or commands whenever possible.
Enable the experimental client capability `"sourcekit/workspace/getReferenceDocument"` so that the server responds with reference document URLs for certain requests or commands whenever possible.

> [!NOTE]
> This request was previously named `workspace/getReferenceDocument`. The old name is still accepted for backward compatibility.

- params: `GetReferenceDocumentParams`

Expand All @@ -712,13 +736,16 @@ export interface GetReferenceDocumentResult {
}
```

## `workspace/peekDocuments`
## `sourcekit/workspace/peekDocuments`

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

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

It requires the experimental client capability `"workspace/peekDocuments"` to use.
It requires the experimental client capability `"sourcekit/workspace/peekDocuments"` to use.

> [!NOTE]
> This request was previously named `workspace/peekDocuments`. The old name is still accepted for backward compatibility.

- params: `PeekDocumentsParams`
- result: `PeekDocumentsResult`
Expand Down Expand Up @@ -749,7 +776,7 @@ export interface PeekDocumentsResult {
}
```

## `workspace/playgrounds`
## `sourcekit/workspace/playgrounds`

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

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

The request fetches the list of all macros found in the workspace, returning the location, identifier, and optional label
when available for each #Playground macro expansion. If you want to keep the list of playgrounds up to date without needing to
call `workspace/playgrounds` each time a document is changed, you can filter for `swift.play` CodeLens returned by the `textDocument/codelens` request.
call `sourcekit/workspace/playgrounds` each time a document is changed, you can filter for `swift.play` CodeLens returned by the `textDocument/codelens` request.

SourceKit-LSP will advertise `sourcekit/workspace/playgrounds` in its experimental server capabilities if it supports it.

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

- params: `WorkspacePlaygroundParams`
- result: `Playground[]`
Expand Down Expand Up @@ -795,10 +825,13 @@ export interface Playground {
}
```

## `workspace/synchronize`
## `sourcekit/workspace/synchronize`

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.

> [!NOTE]
> This request was previously named `workspace/synchronize`. The old name is still accepted for backward compatibility.

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:
- Automated tests that need to wait for background indexing to finish and then checking the result of request results
- Automated tests that need to wait for requests like file changes to be handled and checking behavior after those have been processed
Expand Down Expand Up @@ -837,23 +870,29 @@ export interface SynchronizeParams {
}
```

## `workspace/tests`
## `sourcekit/workspace/tests`

New request that returns symbols for all the test classes and test methods within the current workspace.

> [!NOTE]
> This request was previously named `workspace/tests`. The old name is still accepted for backward compatibility.

- params: `WorkspaceTestsParams`
- result: `TestItem[]`

```ts
export interface WorkspaceTestsParams {}
```

## `workspace/triggerReindex`
## `sourcekit/workspace/triggerReindex`

New request to re-index all files open in the SourceKit-LSP server.

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.

> [!NOTE]
> This request was previously named `workspace/triggerReindex`. The old name is still accepted for backward compatibility.


- params: `TriggerReindexParams`
- result: `void`
Expand Down
18 changes: 17 additions & 1 deletion Sources/BuildServerIntegration/BuildServerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,29 @@ package actor BuildServerManager: QueueBasedMessageHandler {
}
let initializeResponse: InitializeBuildResponse?
do {
var experimentalCapabilities: [String: LSPAny] = [:]
func addCapability(_ method: String, _ value: LSPAny) {
experimentalCapabilities[method] = value
if let legacy = MessageRegistry.bspLegacyNames[method] {
experimentalCapabilities[legacy] = value
}
}
// client -> server
addCapability(BuildTargetPrepareRequest.method, .dictionary(["version": .int(1)]))
addCapability(TextDocumentSourceKitOptionsRequest.method, .dictionary(["version": .int(1)]))
addCapability(WorkspaceWaitForBuildSystemUpdatesRequest.method, .dictionary(["version": .int(1)]))
// server -> client
addCapability(FileOptionsChangedNotification.method, .dictionary(["version": .int(1)]))
initializeResponse = try await buildServerAdapter.send(
InitializeBuildRequest(
displayName: "SourceKit-LSP",
version: "",
bspVersion: "2.2.0",
rootUri: URI(buildServerSpec.projectRoot),
capabilities: BuildClientCapabilities(languageIds: [.c, .cpp, .objective_c, .objective_cpp, .swift])
capabilities: BuildClientCapabilities(
languageIds: [.c, .cpp, .objective_c, .objective_cpp, .swift],
experimental: .dictionary(experimentalCapabilities)
)
)
)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ actor ExternalBuildServerAdapter {
var messagesToSourceKitLSPHandler: any MessageHandler

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

/// After a `build/initialize` request has been sent to the BSP server, that request, so we can replay it in case the
/// server crashes.
Expand Down Expand Up @@ -223,7 +223,10 @@ actor ExternalBuildServerAdapter {
self.projectRoot = projectRoot
self.serverConfig = config
self.messagesToSourceKitLSPHandler = messagesToSourceKitLSPHandler
self.connectionToBuildServer = try await self.createConnectionToBspServer()
self.connectionToBuildServer = LegacyNameFallbackConnection(
try await self.createConnectionToBspServer(),
legacyNames: MessageRegistry.bspLegacyNames
)
}

init(
Expand Down Expand Up @@ -400,7 +403,10 @@ actor ExternalBuildServerAdapter {
// crash recovery and doesn't need to gain it because it is deprecated).
_ = try await restartedConnection.send(initializeRequest)
restartedConnection.send(OnBuildInitializedNotification())
self.connectionToBuildServer = restartedConnection
self.connectionToBuildServer = LegacyNameFallbackConnection(
restartedConnection,
legacyNames: MessageRegistry.bspLegacyNames
)

// The build targets might have changed after the restart. Send a `buildTarget/didChange` notification to
// SourceKit-LSP to discard cached information.
Expand Down
2 changes: 1 addition & 1 deletion Sources/BuildServerIntegration/LegacyBuildServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import ToolsProtocolsSwiftExtensions
/// This build server should be phased out in favor of the pull-based settings model described in
/// https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400
actor LegacyBuildServer: MessageHandler, BuiltInBuildServer {
private var buildServer: JSONRPCConnection?
private var buildServer: (any Connection)?

/// The queue on which all messages that originate from the build server are
/// handled.
Expand Down
1 change: 0 additions & 1 deletion Sources/LanguageServerProtocolExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

add_library(LanguageServerProtocolExtensions STATIC
Connection+Send.swift
DocumentURI+symlinkTarget.swift
Language+Inference.swift
ResponseError+Init.swift
Expand Down
Loading