Skip to content

Commit 047c914

Browse files
authored
Merge pull request #1438 from ahoppen/6.0/merge-main-2024-06-06
Merge `main` into `release/6.0`
2 parents d71fdea + e656954 commit 047c914

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+838
-598
lines changed

.devcontainer/Readme.md

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* **Explanation**: <!-- A description of the issue being fixed or enhancement being made. This can be brief, but it should be clear. -->
2+
* **Scope**: <!-- An assessment of the impact/importance of the change. For example, is the change a source-breaking language change, etc. -->
3+
* **Issue**: <!-- The GitHub Issue link if the change fixes/implements an issue/enhancement -->
4+
* **Original PR**: <!-- Pull Request link from main branch -->
5+
* **Risk**: <!-- What is the (specific) risk to the release for taking this change? -->
6+
* **Testing**: <!-- What specific testing has been done or needs to be done to further validate any impact of this change? -->
7+
* **Reviewer**: <!-- One or more code owners for the impacted components should review the change. Technical review can be delegated by a code owner or otherwise requested as deemed appropriate or useful. -->

CONTRIBUTING.md

Lines changed: 164 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,166 @@
1-
By submitting a pull request, you represent that you have the right to license
2-
your contribution to Apple and the community, and agree by submitting the patch
3-
that your contributions are licensed under the [Swift
4-
license](https://swift.org/LICENSE.txt).
1+
# Contributing
52

6-
---
3+
This document contains notes about development and testing of SourceKit-LSP.
74

8-
Before submitting the pull request, please make sure you have [tested your
9-
changes](https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md)
10-
and that they follow the Swift project [guidelines for contributing
11-
code](https://swift.org/contributing/#contributing-code).
5+
## Building & Testing
6+
7+
SourceKit-LSP is a SwiftPM package, so you can build and test it using anything that supports packages - opening in Xcode, Visual Studio Code with [Swift for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang) installed, or through the command line using `swift build` and `swift test`. See below for extra instructions for Linux and Windows
8+
9+
SourceKit-LSP builds with the latest released Swift version and all its tests pass or, if unsupported by the latest Swift version, are skipped. Using the `main` development branch of SourceKit-LSP with an older Swift versions is not supported.
10+
11+
> [!TIP]
12+
> SourceKit-LSP’s logging is usually very useful to debug test failures. On macOS these logs are written to the system log by default. To redirect them to stderr, build SourceKit-LSP with the `SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER` environment variable set to `1`:
13+
> - In VS Code: Add the following to your `settings.json`:
14+
> ```json
15+
> "swift.swiftEnvironmentVariables": { "SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER": "1" },
16+
> ```
17+
> - In Xcode
18+
> 1. Product -> Scheme -> Edit Scheme…
19+
> 2. Select the Arguments tab in the Run section
20+
> 3. Add a `SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER` environment variable with value `1`
21+
> - On the command line: Set the `SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER` environment variable to `1` when running tests, e.g by running `SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER=1 swift test --parallel`
22+
23+
> [!TIP]
24+
> Other useful environment variables during test execution are:
25+
> - `SKIP_LONG_TESTS`: Skips tests that usually take longer than 1 second to execute. This significantly speeds up test time, especially with `swift test --parallel`
26+
> - `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.
27+
28+
### Linux
29+
30+
The following dependencies of SourceKit-LSP need to be installed on your system
31+
- libsqlite3-dev libncurses5-dev python3
32+
33+
You need to add `<path_to_swift_toolchain>/usr/lib/swift` and `<path_to_swift_toolchain>/usr/lib/swift/Block` C++ search paths to your `swift build` invocation that SourceKit-LSP’s dependencies build correctly. Assuming that your Swift toolchain is installed to `/`, the build command is
34+
35+
```sh
36+
$ swift build -Xcxx -I/usr/lib/swift -Xcxx -I/usr/lib/swift/Block
37+
```
38+
39+
### Windows
40+
41+
You must provide the following dependencies for SourceKit-LSP:
42+
- SQLite3 ninja
43+
44+
```cmd
45+
> swift build -Xcc -I<absolute path to SQLite header search path> -Xlinker -L<absolute path to SQLite library search path> -Xcc -I%SDKROOT%\usr\include -Xcc -I%SDKROOT%\usr\include\Block
46+
```
47+
48+
The header and library search paths must be passed to the build by absolute path. This allows the clang importer and linker to find the dependencies.
49+
50+
Additionally, as SourceKit-LSP depends on libdispatch and the Blocks runtime, which are part of the SDK, but not in the default search path, need to be explicitly added.
51+
52+
### Devcontainer
53+
54+
You can develop SourceKit-LSP inside a devcontainer, which is essentially a Linux container that has all of SourceKit-LSP’s dependencies pre-installed. The [official tutorial](https://code.visualstudio.com/docs/devcontainers/tutorial) contains information of how to set up devcontainers in VS Code.
55+
56+
Recommended Docker settings for macOS are:
57+
- General
58+
- "Choose file sharing implementation for your containers": VirtioFS (better IO performance)
59+
- Resources
60+
- CPUs: Allow docker to use most or all of your CPUs
61+
- Memory: Allow docker to use most or all of your memory
62+
63+
## Using a locally-built sourcekit-lsp in an editor
64+
65+
If you want test your changes to SourceKit-LSP inside your editor, you can point it to your locally-built `sourcekit-lsp` executable. The exact steps vary by editor. For VS Code, you can add the following to your `settings.json`.
66+
67+
```json
68+
"swift.sourcekit-lsp.serverPath": "/path/to/sourcekit-lsp/.build/arm64-apple-macosx/debug/sourcekit-lsp",
69+
```
70+
71+
> [!TIP]
72+
> The easiest way to debug SourceKit-LSP is usually to write a test case that reproduces the behavior and then debug that. If that’s not possible, you can attach LLDB to the sourcekit-lsp launched by your and set breakpoints to debug. To do so on the command line, run
73+
> ```bash
74+
> $ lldb --wait-for --attach-name sourcekit-lsp
75+
> ```
76+
>
77+
> If you are developing SourceKit-LSP in Xcode, go to Debug -> Attach to Process by PID or Name.
78+
79+
## Selecting a Toolchain
80+
81+
When SourceKit-LSP is installed as part of a toolchain, it finds the Swift version to use relative to itself. When building SourceKit-LSP locally, it picks a default toolchain on your system, which usually corresponds to the toolchain that is used if you invoke `swift` without any specified path.
82+
83+
To adjust the toolchain that should be used by SourceKit-LSP (eg. because you want to use new `sourcekitd` features that are only available in a Swift open source toolchain snapshot but not your default toolchain), set the `SOURCEKIT_TOOLCHAIN_PATH` environment variable to your toolchain when running SourceKit-LSP.
84+
85+
## Logging
86+
87+
SourceKit-LSP has extensive logging to the system log on macOS and to `/var/logs/sourcekit-lsp` or stderr on other platforms.
88+
89+
To show the logs on macOS, run
90+
```sh
91+
log show --last 1h --predicate 'subsystem CONTAINS "org.swift.sourcekit-lsp"' --info --debug
92+
```
93+
Or to stream the logs as they are produced:
94+
```
95+
log stream --predicate 'subsystem CONTAINS "org.swift.sourcekit-lsp"' --level debug
96+
```
97+
98+
SourceKit-LSP masks data that may contain private information such as source file names and contents by default. To enable logging of this information, run
99+
100+
```sh
101+
sudo log config --subsystem org.swift.sourcekit-lsp --mode private_data:on
102+
```
103+
104+
To enable more verbose logging on non-macOS platforms, launch sourcekit-lsp with the `SOURCEKITLSP_LOG_LEVEL` environment variable set to `debug`.
105+
106+
107+
## Formatting
108+
109+
SourceKit-LSP is formatted using [swift-format](http://github.com/apple/swift-format) to ensure a consistent style.
110+
111+
To format your changes run the formatter using the following command
112+
```bash
113+
swift package format-source-code
114+
```
115+
116+
If you are developing SourceKit-LSP in VS Code, you can also run the *Run swift-format* task from *Tasks: Run tasks* in the command palette.
117+
118+
## Authoring commits
119+
120+
Prefer to squash the commits of your PR (*pull request*) and avoid adding commits like “Address review comments”. This creates a clearer git history, which doesn’t need to record the history of how the PR evolved.
121+
122+
We prefer to not squash commits when merging a PR because, especially for larger PRs, it sometimes makes sense to split the PR into multiple self-contained chunks of changes. For example, a PR might do a refactoring first before adding a new feature or fixing a bug. This separation is useful for two reasons:
123+
- During review, the commits can be reviewed individually, making each review chunk smaller
124+
- In case this PR introduced a bug that is identified later, it is possible to check if it resulted from the refactoring or the actual change, thereby making it easier find the lines that introduce the issue.
125+
126+
## Opening a PR
127+
128+
To submit a PR you don't need permissions on this repo, instead you can fork the repo and create a PR through your forked version.
129+
130+
For more information and instructions, read the GitHub docs on [forking a repo](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo).
131+
132+
Once you've pushed your branch, you should see an option on this repository's page to create a PR from a branch in your fork.
133+
134+
## Opening a PR for Release Branch
135+
136+
In order for a pull request to be considered for inclusion in a release branch (e.g. `release/6.0`) after it has been cut, it must meet the following requirements:
137+
138+
1. The title of the PR should start with the tag `[{swift version number}]`. For example, `[6.0]` for the Swift 6.0 release branch.
139+
140+
1. The PR description must include the following information:
141+
142+
```md
143+
* **Explanation**: A description of the issue being fixed or enhancement being made. This can be brief, but it should be clear.
144+
* **Scope**: An assessment of the impact/importance of the change. For example, is the change a source-breaking language change, etc.
145+
* **Issue**: The GitHub Issue link if the change fixes/implements an issue/enhancement.
146+
* **Original PR**: Pull Request link from the `main` branch.
147+
* **Risk**: What is the (specific) risk to the release for taking this change?
148+
* **Testing**: What specific testing has been done or needs to be done to further validate any impact of this change?
149+
* **Reviewer**: One or more code owners for the impacted components should review the change. Technical review can be delegated by a code owner or otherwise requested as deemed appropriate or useful.
150+
```
151+
152+
> [!TIP]
153+
> The PR description can be generated using the [release_branch.md](https://github.com/apple/sourcekit-lsp/blob/main/.github/PULL_REQUEST_TEMPLATE/release_branch.md) [pull request template](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/about-issue-and-pull-request-templates). To use this template when creating a PR, you need to add the query parameter:
154+
> ```
155+
> ?expand=1&template=release_branch.md
156+
> ```
157+
> to the PR URL, as described in the [GitHub documentation on using query parameters to create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/using-query-parameters-to-create-a-pull-request).
158+
> This is necessary because GitHub does not currently provide a UI to choose a PR template.
159+
160+
All changes going into a release branch must go through pull requests that are approved and merged by the corresponding release manager.
161+
162+
## Review and CI Testing
163+
164+
After you opened your PR, a maintainer will review it and test your changes in CI (*Continuous Integration*) by adding a `@swift-ci Please test` comment on the pull request. Once your PR is approved and CI has passed, the maintainer will merge your pull request.
165+
166+
Only contributors with [commit access](https://www.swift.org/contributing/#commit-access) are able to approve pull requests and trigger CI.

Documentation/Background Indexing.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Background Indexing
2+
3+
Background indexing in SourceKit-LSP is available as an experimental feature. This guide shows how to set up background indexing and which caveats to expect.
4+
5+
> [!WARNING]
6+
> Background indexing is still an experimental feature and still has some non-trivial limitations and bugs (see the known issues).
7+
8+
## Set Up
9+
10+
Background indexing is still under active, rapid development, so please build SourceKit-LSP from the `main` branch using the following commands. Things are changing rapidly, so rebuilding daily is not a bad practice.
11+
12+
```bash
13+
$ git clone https://github.com/apple/sourcekit-lsp.git
14+
$ cd sourcekit-lsp
15+
$ swift package update
16+
$ swift build -c release
17+
```
18+
19+
Next, point your editor to use the just-built copy of SourceKit-LSP and enable background indexing by passing `--experimental-feature background-indexing` to sourcekit-lsp. In VS Code, this can be done by adding the following to your settings.json
20+
```json
21+
"swift.sourcekit-lsp.serverPath": "/path/to/sourcekit-lsp/.build/release/sourcekit-lsp",
22+
"swift.sourcekit-lsp.serverArguments": [ "--experimental-feature", "background-indexing" ],
23+
```
24+
25+
## Known issues
26+
27+
- The only supported toolchain for background indexing are currently [Swift 6.0 nightly toolchain snapshots](https://www.swift.org/download/#swift-60-development). Older toolchains are not supported and the nightly toolchains from `main` are having issues because building a target non-deterministically builds for tools or the destination [#1288](https://github.com/apple/sourcekit-lsp/pull/1288#issuecomment-2111400459) [rdar://128100158](rdar://128100158)
28+
- Not really a background indexing related issue but Swift nightly toolchain snapshots are crashing on macOS 14.4 and 14.5 (swift#73327)[https://github.com/apple/swift/issues/73327]
29+
- Workaround: Run the toolchains on an older version of macOS, if possible
30+
- Background Indexing is only supported for SwiftPM projects [#1269](https://github.com/apple/sourcekit-lsp/issues/1269), [#1271](https://github.com/apple/sourcekit-lsp/issues/1271)
31+
- If a module or one of its dependencies has a compilation error, it cannot be properly prepared for indexing because we are running a regular `swift build` to generate its modules [#1254](https://github.com/apple/sourcekit-lsp/issues/1254) rdar://128683404
32+
- Workaround: Ensure that your files dependencies are in a buildable state to get an up-to-date index and proper cross-module functionality
33+
- If you change a function in a way that changes its USR but keeps it API compatible (such as adding a defaulted parameter), references to it will be lost and not re-indexed automatically [#1264](https://github.com/apple/sourcekit-lsp/issues/1264)
34+
- Workaround: Make some edit to the files that had references to re-index them
35+
- The index build is currently completely separate from the command line build generated using `swift build`. Building *does not* update the index (break your habits of always building!) [#1270](https://github.com/apple/sourcekit-lsp/issues/1270)
36+
- The initial indexing might take 2-3x more time than a regular build [#1254](https://github.com/apple/sourcekit-lsp/issues/1254), [#1262](https://github.com/apple/sourcekit-lsp/issues/1262), [#1268](https://github.com/apple/sourcekit-lsp/issues/1268)
37+
- Spurious re-indexing of ~10-20 source files when `swift build` writes a header to the build directory [rdar://128573306](rdar://128573306)
38+
39+
## Filing issues
40+
41+
If you hit any issues that are not mentioned above, please [file a GitHub issue](https://github.com/apple/sourcekit-lsp/issues/new/choose) and attach the following information, if possible:
42+
- A diagnostic bundle generated by running `path/to/sourcekit-lsp diagnose --toolchain path/to/the/toolchain/you/are/using`
43+
- Your project including the `.index-build` folder.

Documentation/Client_Development.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)