Skip to content

Dummy PR to review BSP migration changes #1679

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

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
fd0573e
Rename `BuildSystem` to `BuiltInBuildSystem`
ahoppen Aug 23, 2024
b4d04ce
Introduce a `BuiltInBuildSystemAdapter` that can be used to transitio…
ahoppen Sep 9, 2024
e38d37e
Use `workspace/didChangeWatchedFiles` from BSP to communicate file ch…
ahoppen Sep 6, 2024
63c5ca4
Use `BuildTargetIdentifier` from BSP instead of `ConfiguredTarget`
ahoppen Aug 23, 2024
b490a6f
Use `buildTarget/inverseSources` from BSP to get targets of a source …
ahoppen Aug 23, 2024
6a9dcd2
Split determining which build system to use for a workspace and the w…
ahoppen Aug 23, 2024
027f3ee
Push creation of `BuiltInBuildSystem` into the workspace
ahoppen Aug 24, 2024
9f40880
Create `BuiltInBuildSystem` in `BuildSystemManager`
ahoppen Aug 24, 2024
ea21175
Create `BuildSystem` in `BuiltInBuildSystemAdapter`
ahoppen Aug 24, 2024
851feba
Merge pull request #1649 from ahoppen/bsp-preparation
ahoppen Sep 10, 2024
9473aeb
Merge pull request #1653 from ahoppen/build-system-creation
ahoppen Sep 10, 2024
9e98c48
Fix retain cycle between `BuiltInBuildSystemAdapter` and `BuiltInBuil…
ahoppen Sep 10, 2024
f9e468f
Use BSP requests to get build settings of a source file
ahoppen Aug 23, 2024
a4edcea
Merge pull request #1654 from ahoppen/fix-leak
ahoppen Sep 10, 2024
b9370cf
Allow overriding the timeout duration for tests
ahoppen Sep 10, 2024
5d1eb73
Revert "Add an extra percent encoding layer when encoding DocumentURI…
ahoppen Sep 10, 2024
57055d4
Make `Workspace` the delegate of a `BuildSystemManager`
ahoppen Sep 10, 2024
e083124
Merge pull request #1655 from ahoppen/bsp-settings
ahoppen Sep 10, 2024
37f7540
Merge pull request #1656 from ahoppen/workspace-delegate
ahoppen Sep 11, 2024
bf8ff8b
Merge pull request #1657 from ahoppen/custom-timeout
ahoppen Sep 11, 2024
236f566
Instead of having `FileHandlingCapability` for a source file, check i…
ahoppen Aug 24, 2024
7e3f453
Remove `registerForChangeNotifications`
ahoppen Aug 24, 2024
3a11898
Migrate `BuildSystem.prepare` to a BSP request
ahoppen Aug 24, 2024
cf47f2c
Merge pull request #1659 from ahoppen/more-bsp
ahoppen Sep 11, 2024
c5ba967
Migrate getting the list of all source files to BSP
ahoppen Sep 11, 2024
35899ab
Merge pull request #1658 from ahoppen/revert-uri-hack
ahoppen Sep 11, 2024
dd50183
Merge pull request #1660 from ahoppen/source-files-bsp
ahoppen Sep 12, 2024
9d94fe3
Migrate `defaultLanguage(for:)` to BSP
ahoppen Sep 11, 2024
022a6de
Handle `filesDependenciesUpdated` in `BuildSystemManager` instead of …
ahoppen Sep 11, 2024
9006ab6
Use the `InitializeRequest` from BSP to communicate some static optio…
ahoppen Aug 24, 2024
367b19a
Merge pull request #1663 from ahoppen/language-dependencies-initialize
ahoppen Sep 12, 2024
897cd5e
Implicitly trigger build graph generation when creating a `SwiftPMBui…
ahoppen Aug 24, 2024
bb96ff4
Migrate `targets(dependingOn:)` to BSP
ahoppen Sep 12, 2024
cc11fe1
Implement `topologicalSort` inside `BuildSystemManager` using depende…
ahoppen Aug 25, 2024
f5245bf
Merge pull request #1664 from ahoppen/buildgraph-generation-targets
ahoppen Sep 13, 2024
d8161b3
Cache build targets by ID and associated depths
ahoppen Sep 13, 2024
12923b6
Implement `toolchain(for:)` using BSP
ahoppen Aug 25, 2024
fac21f5
Implement `waitForUpToDateBuildGraph` using BSP
ahoppen Aug 25, 2024
a96c091
Implement `addSourceFilesDidChangeCallback` in `BuildSystemManager`
ahoppen Sep 13, 2024
fffc783
Skip `testWasm` in CI if toolchain cannot compile for wasm
ahoppen Sep 13, 2024
f07a30e
Merge pull request #1665 from ahoppen/another-asp
ahoppen Sep 13, 2024
fe1363c
Merge pull request #1666 from ahoppen/skip-was
ahoppen Sep 14, 2024
57e933d
Move Atomics from SKSupport to SwiftExtensions
ahoppen Sep 15, 2024
3d95375
Use a `LocalConnection` to communicate between `BuildSystemManager` a…
ahoppen Aug 25, 2024
66f24e3
Introduce `buildSystemTestHooks`
ahoppen Aug 25, 2024
6cc2cc4
Implement `reloadPackageStatusCallback` using BSP messages
ahoppen Aug 25, 2024
c93f193
Share message handling logic between `BuiltInBuildSystemAdapter` and …
ahoppen Sep 13, 2024
7d11825
Fix build issues on Windows
ahoppen Sep 16, 2024
9334bb7
Merge pull request #1668 from ahoppen/connection-based-bsp
ahoppen Sep 16, 2024
8ac405c
Make `BuildSystemManager.buildSystem` and `BuiltInBuildSystemAdapter.…
ahoppen Sep 13, 2024
d00722e
Use BSP to log messages from preparation in the build system
ahoppen Sep 13, 2024
f741b0d
Use more fine-grained dependency tracking to allow BSP requests to be…
ahoppen Sep 14, 2024
5ffc782
Add BSP messages to `bspRegistry`
ahoppen Sep 14, 2024
7028846
Log target name instead of the target's URI
ahoppen Sep 14, 2024
29cfda0
Refactor `sourceFiles` to return a dictionary from `DocumentURI` to `…
ahoppen Sep 14, 2024
8a10963
Remove double logging of BSP replies
ahoppen Sep 14, 2024
14e9631
Fix issue that created incorrect display name for BSP server
ahoppen Sep 14, 2024
5870ad9
Implement `InverseSourcesRequest` in `BuildSystemManager`
ahoppen Sep 14, 2024
79e1d2a
If we have a cached request for a superset of the targets, serve the …
ahoppen Sep 14, 2024
cb2924a
Remove `sourceFilesDidChange`
ahoppen Sep 14, 2024
765ea48
Remove `testSettingsChangedAfterUnregister`
ahoppen Sep 14, 2024
6762bb3
Remove resolved `FIXME`
ahoppen Sep 14, 2024
80afa15
Replace `FIXME` with `TODO`
ahoppen Sep 14, 2024
85b2f1f
Review `BuildServerProtocol` module for consistency
ahoppen Sep 15, 2024
2f388b9
Send shutdown request to build system from `BuildSystemManager`
ahoppen Sep 15, 2024
3a78b65
Share logic to infer language from file extension between `BuildSyste…
ahoppen Sep 15, 2024
9ee7c59
Minor cleanups
ahoppen Sep 15, 2024
a9578bb
Review `BuildSystemMessageDependencyTracker`
ahoppen Sep 15, 2024
0f56e5f
Simplify `FallbackBuildSystem` to a free function returning fallback …
ahoppen Sep 15, 2024
d155665
Review `BuildSystemManager`
ahoppen Sep 15, 2024
5996e56
Review `BuiltInBuildSystemAdapter`
ahoppen Sep 15, 2024
316790f
Review `BuiltInBuildSystem`
ahoppen Sep 15, 2024
bc9ee37
Review `QueueBasedMessageHandler`
ahoppen Sep 15, 2024
3753837
Review `CompilationDatabase.swift`
ahoppen Sep 15, 2024
0bdbb50
Review `CompilationDatabaseBuildSystem`
ahoppen Sep 15, 2024
db539b0
Review `TestBuildSystem.swift`
ahoppen Sep 15, 2024
2c2d9f9
Review `PrefixMessageWithTaskEmoji.swift`
ahoppen Sep 15, 2024
e15bdd7
Review `SwiftPMBuildSystem.swift`
ahoppen Sep 15, 2024
6e99e34
Merge pull request #1674 from ahoppen/bsp-cleanup
ahoppen Sep 16, 2024
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
163 changes: 163 additions & 0 deletions Contributor Documentation/BSP Extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# BSP Extensions

SourceKit-LSP extends the BSP protocol in the following ways.

## `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` */
indexDatabasePath?: string;

/** Whether the build server supports the `buildTarget/prepare` request */
supportsPreparation?: bool;
}
```

## `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 build Swift modules for all dependencies of this module so that all `import` statements in this module can be resolved.

The server communicates during the initialize handshake whether this method is supported or not by setting `supportsPreparation` 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;
}
```

## `window/workDoneProgress/create`

Request from the build server to SourceKit-LSP to create a work done progress.

Definition is the same as in LSP.

## `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.

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`

## `$/progress`

Notification from the build server to SourceKit-LSP to update a work done progress created using `window/workDoneProgress/create`.

Definition is the same as in LSP.
1 change: 1 addition & 0 deletions Documentation/Configuration File.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The structure of the file is currently not guaranteed to be stable. Options may
- `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`.
- `clangdOptions: string[]`: Extra command line arguments passed to `clangd` when launching it
- `index`: Dictionary with the following keys, defining options related to indexing
- `indexStorePath: string`: Directory in which a separate compilation stores the index store. By default, inferred from the build system.
Expand Down
1 change: 1 addition & 0 deletions Documentation/Environment Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ The following environment variables can be used to control some behavior in Sour
- `SKIP_LONG_TESTS`: Skip tests that typically take more than 1s to execute.
- `SOURCEKITLSP_KEEP_TEST_SCRATCH_DIR`: Does not delete the temporary files created during test execution. Allows inspection of the test projects after the test finishes.
- `SOURCEKIT_LSP_TEST_MODULE_CACHE`: Specifies where tests should store their shared module cache. Defaults to writing the module cache to a temporary directory. Intended so that CI systems can clean the module cache directory after running.
- `SOURCEKIT_LSP_TEST_TIMEOUT`: Override the timeout duration for tests, in seconds.
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ let package = Package(
.target(
name: "SKSupport",
dependencies: [
"CAtomics",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SourceKitD",
"SwiftExtensions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
Expand Down Expand Up @@ -377,6 +378,7 @@ let package = Package(

.target(
name: "SwiftExtensions",
dependencies: ["CAtomics"],
exclude: ["CMakeLists.txt"]
),

Expand Down
Loading