Skip to content

Rename build system to build server in most cases #2201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
22 changes: 20 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"program": "${workspaceFolder:sourcekit-lsp}/.build/debug/sourcekit-lsp",
"args": [],
"cwd": "${workspaceFolder:sourcekit-lsp}",
"preLaunchTask": "swift: Build Debug sourcekit-lsp",
"preLaunchTask": "swift: Build Debug sourcekit-lsp"
},
{
"type": "swift",
Expand All @@ -16,14 +16,32 @@
"program": "${workspaceFolder:sourcekit-lsp}/.build/release/sourcekit-lsp",
"args": [],
"cwd": "${workspaceFolder:sourcekit-lsp}",
"preLaunchTask": "swift: Build Release sourcekit-lsp",
"preLaunchTask": "swift: Build Release sourcekit-lsp"
},
{
"type": "swift",
"request": "attach",
"name": "Attach sourcekit-lsp (debug)",
"program": "${workspaceFolder:sourcekit-lsp}/.build/debug/sourcekit-lsp",
"waitFor": true
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:sourcekit-lsp}/SourceKitLSPDevUtils",
"name": "Debug sourcekit-lsp-dev-utils (SourceKitLSPDevUtils)",
"program": "${workspaceFolder:sourcekit-lsp}/SourceKitLSPDevUtils/.build/debug/sourcekit-lsp-dev-utils",
"preLaunchTask": "swift: Build Debug sourcekit-lsp-dev-utils (SourceKitLSPDevUtils)"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:sourcekit-lsp}/SourceKitLSPDevUtils",
"name": "Release sourcekit-lsp-dev-utils (SourceKitLSPDevUtils)",
"program": "${workspaceFolder:sourcekit-lsp}/SourceKitLSPDevUtils/.build/release/sourcekit-lsp-dev-utils",
"preLaunchTask": "swift: Build Release sourcekit-lsp-dev-utils (SourceKitLSPDevUtils)"
}
]
}
6 changes: 3 additions & 3 deletions Contributor Documentation/BSP Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface SourceKitSourceItemData {
/** The language of the source file. If `nil`, the language is inferred from the file extension. */
language?: LanguageId;

/**
/**
* The kind of source file that this source item represents. If omitted, the item is assumed to be a normal source
* file, ie. omitting this key is equivalent to specifying it as `source`.
*/
Expand Down Expand Up @@ -172,7 +172,7 @@ export interface SourceKitBuildTarget {

## `workspace/didChangeWatchedFiles`

Notification sent from SourceKit-LSP to the build system to indicate that files within the project have been modified.
Notification sent from SourceKit-LSP to the build server 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.

Expand All @@ -182,6 +182,6 @@ Definition is the same as in LSP.

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.
If the build server is currently updating the build graph, this request should return after those updates have finished processing.

- method: `workspace/waitForBuildSystemUpdates`
4 changes: 2 additions & 2 deletions Contributor Documentation/Background Indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Preparation of a target should perform the minimal amount of work to build all `

### Status tracking

When SourceKit-LSP is launched, all targets are considered to be out-of-date. This needs to be done because source files might have changed since SourceKit-LSP was last started – if the module wasn’t modified since the last SourceKit-LSP launch, we re-prepare the target and rely on the build system to produce a fast null build.
When SourceKit-LSP is launched, all targets are considered to be out-of-date. This needs to be done because source files might have changed since SourceKit-LSP was last started – if the module wasn’t modified since the last SourceKit-LSP launch, we re-prepare the target and rely on the build server to produce a fast null build.

After we have prepared a target, we mark it as being up-to-date in `SemanticIndexManager.preparationUpToDateTracker`. That way we don’t need to invoke the build system every time we want to perform semantic functionality of a source file, which saves us the time of a null build (which can hundreds of milliseconds for SwiftPM). If a source file is changed (as noted through file watching), all of its target’s dependencies are marked as out-of-date. Note that the target that the source file belongs to is not marked as out-of-date – preparation of a target builds all dependencies but does not need to build the target’s module itself. The next operation that requires the target to be prepared will trigger a preparation job.
After we have prepared a target, we mark it as being up-to-date in `SemanticIndexManager.preparationUpToDateTracker`. That way we don’t need to invoke the build server every time we want to perform semantic functionality of a source file, which saves us the time of a null build (which can hundreds of milliseconds for SwiftPM). If a source file is changed (as noted through file watching), all of its target’s dependencies are marked as out-of-date. Note that the target that the source file belongs to is not marked as out-of-date – preparation of a target builds all dependencies but does not need to build the target’s module itself. The next operation that requires the target to be prepared will trigger a preparation job.

## Updating the index store

Expand Down
2 changes: 1 addition & 1 deletion Contributor Documentation/Implementing a BSP server.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If the build system loads the entire build graph during initialization, it may i

## 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.
To support background indexing, the build server 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

Expand Down
2 changes: 1 addition & 1 deletion Contributor Documentation/LSP Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ export interface SourceKitOptionsRequest {
* If set to `true` and build settings could not be determined within a timeout (see `buildSettingsTimeout` in the
* SourceKit-LSP configuration file), this request returns fallback build settings.
*
* If set to `true` the request only finishes when build settings were provided by the build system.
* If set to `true` the request only finishes when build settings were provided by the build server.
*/
allowFallbackSettings: bool
}
Expand Down
4 changes: 2 additions & 2 deletions Contributor Documentation/Modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ The SourceKit-LSP package contains the following non-testing modules.

Swift types to represent the [Build Server Protocol (BSP) specification](https://build-server-protocol.github.io/docs/specification). These types should also be usable when implementing a BSP client and thus this module should not have any dependencies other than the LanguageServerProtocol module, with which it shares some types.

### BuildSystemIntegration
### BuildServerIntegration

Defines the queries SourceKit-LSP can ask of a build system, like getting compiler arguments for a file, finding a target’s dependencies or preparing a target.
Defines the queries SourceKit-LSP can ask of a build server, like getting compiler arguments for a file, finding a target’s dependencies or preparing a target.

### CAtomics

Expand Down
10 changes: 5 additions & 5 deletions Contributor Documentation/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ For requests that require knowledge about the project’s index, like call hiera

[sourcekitd](https://github.com/apple/swift/tree/main/tools/SourceKit) is implemented in the Swift compiler’s repository and uses the Swift compiler’s understanding of Swift code to provide semantic functionality. On macOS, sourcekitd is run as an XPC service and all other platforms sourcekitd is run in the sourcekit-lsp process. This means that on macOS, a crash of sourcekitd can be recovered by re-launching sourcekitd, while on other platforms a crash inside sourcekitd crashes sourcekit-lsp.

## Build systems
## Build servers

Basically all semantic functionality requires knowledge about how a file is being built (like module search paths to be able to resolve `import` statements). SourceKit-LSP consults a `BuildSystem` to get this information. Note that the term build system has a somewhat loose definition in SourceKit-LSP. It’s less about building the project and more about providing information that would be used if building the project. Build systems that are currently supported are:
- `SwiftPMBuildSystem`: Reads a `Package.swift` at the project’s root
- `CompilationDatabaseBuildSystem`: Reads a `compile_commands.json` file to provide build settings for files. `compile_commands.json` can eg. be generated by CMake.
- `BuildServerBuildSystem`: Launches an external build server process to provide build settings.
Basically all semantic functionality requires knowledge about how a file is being built (like module search paths to be able to resolve `import` statements). SourceKit-LSP consults a *build server* to get this information. Build servers that are currently supported are:
- `SwiftPMBuildServer`: Reads a `Package.swift` at the project’s root
- `CompilationDatabaseBuildServer`: Reads a `compile_commands.json` file to provide build settings for files. `compile_commands.json` can eg. be generated by CMake.
- `ExternalBuildServerAdapter`: Launches an external BSP server process to provide build settings.

## Logging

Expand Down
4 changes: 2 additions & 2 deletions Documentation/Configuration File.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ The structure of the file is currently not guaranteed to be stable. Options may
- `disableSandbox: boolean`: Disables running subprocesses from SwiftPM in a sandbox. Equivalent to SwiftPM's `--disable-sandbox` option. Useful when running `sourcekit-lsp` in a sandbox because nested sandboxes are not supported.
- `compilationDatabase`: Dictionary with the following keys, defining options for workspaces with a compilation database.
- `searchPaths: string[]`: Additional paths to search for a compilation database, relative to a workspace root.
- `fallbackBuildSystem`: Dictionary with the following keys, defining options for files that aren't managed by any build system.
- `fallbackBuildSystem`: Dictionary with the following keys, defining options for files that aren't managed by any build server.
- `cCompilerFlags: string[]`: Extra arguments passed to the compiler for C files.
- `cxxCompilerFlags: string[]`: Extra arguments passed to the compiler for C++ files.
- `swiftCompilerFlags: string[]`: Extra arguments passed to the compiler for Swift files.
- `sdk: string`: The SDK to use for fallback arguments. Default is to infer the SDK using `xcrun`.
- `buildSettingsTimeout: integer`: Number of milliseconds to wait for build settings from the build system before using fallback build settings.
- `buildSettingsTimeout: integer`: Number of milliseconds to wait for build settings from the build server before using fallback build settings.
- `clangdOptions: string[]`: Extra command line arguments passed to `clangd` when launching it.
- `index`: Options related to indexing.
- `indexPrefixMap: [string: string]`: Path remappings for remapping index data for local use.
Expand Down
30 changes: 15 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var targets: [Target] = [
.executableTarget(
name: "sourcekit-lsp",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"Diagnose",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
Expand Down Expand Up @@ -74,10 +74,10 @@ var targets: [Target] = [
swiftSettings: globalSwiftSettings
),

// MARK: BuildSystemIntegration
// MARK: BuildServerIntegration

.target(
name: "BuildSystemIntegration",
name: "BuildServerIntegration",
dependencies: [
"BuildServerProtocol",
"LanguageServerProtocol",
Expand All @@ -101,9 +101,9 @@ var targets: [Target] = [
),

.testTarget(
name: "BuildSystemIntegrationTests",
name: "BuildServerIntegrationTests",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"LanguageServerProtocol",
"SKOptions",
"SKTestSupport",
Expand Down Expand Up @@ -183,7 +183,7 @@ var targets: [Target] = [
.target(
name: "Diagnose",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"InProcessClient",
"LanguageServerProtocolExtensions",
"SKLogging",
Expand All @@ -204,7 +204,7 @@ var targets: [Target] = [
.testTarget(
name: "DiagnoseTests",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"Diagnose",
"SKLogging",
"SKTestSupport",
Expand All @@ -221,7 +221,7 @@ var targets: [Target] = [
name: "DocCDocumentation",
dependencies: [
"BuildServerProtocol",
"BuildSystemIntegration",
"BuildServerIntegration",
"LanguageServerProtocol",
"SemanticIndex",
"SKLogging",
Expand All @@ -239,7 +239,7 @@ var targets: [Target] = [
.target(
name: "InProcessClient",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"LanguageServerProtocol",
"SKLogging",
"SKOptions",
Expand Down Expand Up @@ -313,7 +313,7 @@ var targets: [Target] = [
name: "SemanticIndex",
dependencies: [
"BuildServerProtocol",
"BuildSystemIntegration",
"BuildServerIntegration",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"SKLogging",
Expand Down Expand Up @@ -428,7 +428,7 @@ var targets: [Target] = [
.target(
name: "SKTestSupport",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"CSKTestSupport",
"Csourcekitd",
"InProcessClient",
Expand Down Expand Up @@ -481,7 +481,7 @@ var targets: [Target] = [
.testTarget(
name: "SourceKitDTests",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"SourceKitD",
"SKTestSupport",
"SwiftExtensions",
Expand All @@ -496,7 +496,7 @@ var targets: [Target] = [
name: "SourceKitLSP",
dependencies: [
"BuildServerProtocol",
"BuildSystemIntegration",
"BuildServerIntegration",
"DocCDocumentation",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
Expand Down Expand Up @@ -529,7 +529,7 @@ var targets: [Target] = [
name: "SourceKitLSPTests",
dependencies: [
"BuildServerProtocol",
"BuildSystemIntegration",
"BuildServerIntegration",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"SemanticIndex",
Expand Down Expand Up @@ -643,7 +643,7 @@ var targets: [Target] = [
.testTarget(
name: "SwiftSourceKitPluginTests",
dependencies: [
"BuildSystemIntegration",
"BuildServerIntegration",
"CompletionScoring",
"Csourcekitd",
"LanguageServerProtocol",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ package struct SwiftPMTestHooks: Sendable {
}
}

package struct BuildSystemHooks: Sendable {
package struct BuildServerHooks: Sendable {
package var swiftPMTestHooks: SwiftPMTestHooks

/// A hook that will be executed before a request is handled by a `BuiltInBuildSystem`.
/// A hook that will be executed before a request is handled by a `BuiltInBuildServer`.
///
/// This allows requests to be artificially delayed.
package var preHandleRequest: (@Sendable (any RequestType) async -> Void)?

/// When running SourceKit-LSP in-process, allows the creator of `SourceKitLSPServer` to create a message handler that
/// handles BSP requests instead of SourceKit-LSP creating build systems as needed.
/// handles BSP requests instead of SourceKit-LSP creating build server as needed.
package var injectBuildServer:
(@Sendable (_ projectRoot: URL, _ connectionToSourceKitLSP: any Connection) async -> any Connection)?

Expand Down
Loading