1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
# BSP Extensions
SourceKit-LSP extends the BSP protocol in the following ways.
## `$/cancelRequest`
Notification sent from SourceKit-LSP to the BSP server to cancel a request. If a BSP server doesn’t support cancellation, it should ignore this notification.
Definition is the same as in LSP.
## `build/initialize`
`InitializeBuildResultDataKind` can be `sourceKit`, in which case `InitializeBuildResultData` contains the following data.
```ts
export interface SourceKitInitializeBuildResponseData {
/** The directory to which the index store is written during compilation, ie. the path passed to `-index-store-path`
* for `swiftc` or `clang` invocations **/
indexStorePath?: string;
/** The path at which SourceKit-LSP can store its index database, aggregating data from `indexStorePath`.
* This should point to a directory that can be exclusively managed by SourceKit-LSP. Its exact location can be arbitrary. */
indexDatabasePath?: string;
/** Whether the build server supports the `buildTarget/prepare` request */
prepareProvider?: bool;
/** Whether the server implements the `textDocument/sourceKitOptions` request. */
sourceKitOptionsProvider?: bool;
/** The files to watch for changes.
* Changes to these files are sent to the BSP server using `workspace/didChangeWatchedFiles`.
* `FileSystemWatcher` is the same as in LSP. */
watchers: [FileSystemWatcher]?
}
```
## `build/taskStart`
If `data` contains a string value for the `workDoneProgressTitle` key, then the task's message will be displayed in the client as a work done progress with that title.
## `buildTarget/didChange`
`changes` can be `null` to indicate that all targets have changed.
## `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`
- params: `PrepareParams`
```ts
export interface PrepareParams {
/** A list of build targets to prepare. */
targets: BuildTargetIdentifier[];
/** A unique identifier generated by the client to identify this request.
* The server may include this id in triggered notifications or responses. **/
originId?: OriginId;
}
```
## `builtTarget/sources`
`SourceItemDataKind` can be `sourceKit` in which case `SourceItem.data` contains the following data.
```ts
export interface SourceKitSourceItemData {
/** The language of the source file. If `nil`, the language is inferred from the file extension. */
language? LanguageId;
/** Whether the file is a header file that is clearly associated with one target.
*
* For example header files in SwiftPM projects are always associated to one target and SwiftPM can provide build
* settings for that header file.
*
* In general, build systems don't need to list all header files in the `buildTarget/sources` request: Semantic
* functionality for header files is usually provided by finding a main file that includes the header file and
* inferring build settings from it. Listing header files in `buildTarget/sources` allows SourceKit-LSP to provide
* semantic functionality for header files if they haven't been included by any main file. **/
isHeader?: bool;
}
```
## `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`
- params: `TextDocumentSourceKitOptionsParams`
- result: `TextDocumentSourceKitOptionsResult`
```ts
export interface TextDocumentSourceKitOptionsRequest {
/** The URI of the document to get options for */
textDocument: TextDocumentIdentifier;
/** The target for which the build setting should be returned.
*
* A source file might be part of multiple targets and might have different compiler arguments in those two targets,
* thus the target is necessary in this request. **/
target: BuildTargetIdentifier;
/** The language with which the document was opened in the editor. */
language: LanguageId;
}
export interface TextDocumentSourceKitOptionsResult {
/** The compiler options required for the requested file. */
compilerArguments: string[];
/** The working directory for the compile command. */
workingDirectory?: string;
}
```
## `workspace/buildTargets`
`BuildTargetTag` can have the following additional values
```ts
export interface BuildTargetTag {
// ...
/** This is a target of a dependency from the project the user opened, eg. a target that builds a SwiftPM dependency. */
export const Dependency = "dependency";
/** This target only exists to provide compiler arguments for SourceKit-LSP can't be built standalone.
*
* For example, a SwiftPM package manifest is in a non-buildable target. **/
export const NotBuildable = "not-buildable";
}
```
`BuildTargetDataKind` can be `sourceKit` in which case `BuildTarget.data` contains the following data.
```ts
export interface SourceKitBuildTarget {
/** The toolchain that should be used to build this target. The URI should point to the directory that contains the
* `usr` directory. On macOS, this is typically a bundle ending in `.xctoolchain`. If the toolchain is installed to
* `/` on Linux, the toolchain URI would point to `/`.
*
* If no toolchain is given, SourceKit-LSP will pick a toolchain to use for this target. **/
toolchain?: URI;
}
```
## `workspace/didChangeWatchedFiles`
Notification sent from SourceKit-LSP to the build system to indicate that files within the project have been modified.
SourceKit-LSP may send file change notifications for a superset of the files that the BSP server requested to watch in `watchers`. It is the BSP server’s responsibility to filter the file watch notifications for the ones it is actually interested in.
Definition is the same as in LSP.
## `workspace/waitForBuildSystemUpdates`
This request is a no-op and doesn't have any effects.
If the build system is currently updating the build graph, this request should return after those updates have finished processing.
- method: `workspace/waitForBuildSystemUpdates`
|