File: Implementing%20a%20BSP%20server.md

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (44 lines) | stat: -rw-r--r-- 2,686 bytes parent folder | download
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
# Implementing a BSP server

SourceKit-LSP can connect to any build system to provide semantic functionality through the [Build Server Protocol (BSP)](https://build-server-protocol.github.io). This is a short guide of the requests and notifications that a BSP server for SourceKit-LSP should implement. For more detailed information, refer to the [BSP spec](https://build-server-protocol.github.io/docs/specification) and the [SourceKit-LSP BSP Extensions](BSP%20Extensions.md). This document just references BSP methods and properties and those specification documents contain their documentation.

## Required lifecycle methods

In order to be launched and shut down successfully, the BSP server must implement the following methods

- `build/initialize`
- `build/initialized`
- `build/shutdown`
- `build/exit`

The `build/initialize` response must have `dataKind: "sourceKit"` and `data.sourceKitOptionsProvider: true`. In order to provide global code navigation features such as call hierarchy and global rename, the build server must set `data.indexDatabasePath` and `data.indexStorePath`.

## Retrieving build settings

In order to provide semantic functionality for source files, the BSP server must provide the following methods:

- `workspace/buildTargets`
- `buildTarget/sources`
- `textDocument/sourceKitOptions`
- `buildTarget/didChange`
- `workspace/waitForBuildSystemUpdates`

If the build system does not have a notion of targets, eg. because it provides build settings from a file akin to a JSON compilation database, it may use a single dummy target for all source files or a separate target for each source file, either choice will work.

If the build system loads the entire build graph during initialization, it may immediately return from `workspace/waitForBuildSystemUpdates`.

## Supporting background indexing

To support background indexing, the build system must set `data.prepareProvider: true` in the `build/initialize` response and implement the `buildTarget/prepare` method. The compiler options used to prepare a target should match those sent for `textDocument/sourceKitOptions` in order to avoid mismatches when loading modules.

## Optional methods

The following methods are not necessary to implement for SourceKit-LSP to work but might help with the implementation of the build server.

- `build/logMessage`
- `build/taskStart`, `build/taskProgress`, and `build/taskFinish`
- `workspace/didChangeWatchedFiles`

## Build server discovery

To make your build server discoverable, create a [BSP connection specification](https://build-server-protocol.github.io/docs/overview/server-discovery) file named `buildServer.json` in the root of your project.