Skip to content

Commit e9ce0d3

Browse files
authored
Merge branch 'main' into maxd/bump-argument-parser
2 parents 4fbbfbf + cba6ca2 commit e9ce0d3

File tree

279 files changed

+23583
-5799
lines changed

Some content is hidden

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

279 files changed

+23583
-5799
lines changed

.devcontainer/default/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM swiftlang/swift:nightly-main-jammy
2+
3+
RUN \
4+
# Disable apt interactive prompts for this RUN command
5+
export DEBIAN_FRONTEND="noninteractive" && \
6+
# Update apt package list
7+
apt-get update && \
8+
# Install sourcekit-lsp dependencies
9+
apt-get install -y libsqlite3-dev libncurses5-dev python3
10+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Reference: https://containers.dev/implementors/json_reference/
2+
{
3+
"name": "SourceKit-LSP",
4+
"dockerFile": "Dockerfile",
5+
6+
// Allow the processes in the container to attach a debugger
7+
"capAdd": [ "SYS_PTRACE" ],
8+
"securityOpt": [ "seccomp=unconfined" ],
9+
10+
"mounts": [
11+
// Use a named volume for the build products for optimal performance (https://code.visualstudio.com/remote/advancedcontainers/improve-performance#_use-a-targeted-named-volume)
12+
"source=${localWorkspaceFolderBasename}-build,target=${containerWorkspaceFolder}/.build,type=volume",
13+
// Do the same for experimental background indexing
14+
"source=${localWorkspaceFolderBasename}-index-build,target=${containerWorkspaceFolder}/.index-build,type=volume"
15+
],
16+
"customizations": {
17+
"vscode": {
18+
"extensions": [
19+
"sswg.swift-lang"
20+
],
21+
"settings": {
22+
"lldb.library": "/usr/lib/liblldb.so",
23+
"swift.buildArguments": [
24+
"-Xcxx",
25+
"-I/usr/lib/swift",
26+
"-Xcxx",
27+
"-I/usr/lib/swift/Block"
28+
]
29+
}
30+
}
31+
}
32+
}

CODEOWNERS renamed to .github/CODEOWNERS

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88
# Order is important. The last matching pattern has the most precedence.
99

1010
# Owner of anything in SourceKit-LSP not owned by anyone else.
11-
# N: Ben Langmuir
12-
13-
# N: Alex Hoppen
14-
15-
* @benlangmuir @ahoppen
11+
* @ahoppen
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Bug Report
2+
description: Something isn't working as expected
3+
labels: [bug]
4+
body:
5+
- type: input
6+
id: version
7+
attributes:
8+
label: Swift version
9+
description: Which version of Swift are you using? If you are unsure, insert the output of `path/to/swift --version`
10+
placeholder: Eg. swiftlang-5.10.0.13, swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a
11+
- type: input
12+
id: platform
13+
attributes:
14+
label: Platform
15+
description: What operating system are you seeing the issue on?
16+
placeholder: Eg. Ubuntu 22.04, Windows 11, macOS 14
17+
- type: input
18+
id: editor
19+
attributes:
20+
label: Editor
21+
description: Which text editor are you using (and LSP extension/plugin if applicable)?
22+
placeholder: Eg. Visual Studio Code with Swift extension 1.9.0, Neovim
23+
- type: dropdown
24+
id: reproduces-with-swift-6
25+
attributes:
26+
label: Does the issue reproduce with Swift 6?
27+
description: |
28+
Does the issue also reproduce using a [recent Swift 6 Development Snapshot](https://www.swift.org/download/#swift-60-development)?
29+
30+
We have made significant changes to SourceKit-LSP in Swift 6 and the issue might have already been fixed. If you didn’t try, that is fine.
31+
options:
32+
- "Yes"
33+
- "No"
34+
- I didn’t try
35+
- type: textarea
36+
id: description
37+
attributes:
38+
label: Description
39+
description: |
40+
A short description of the incorrect behavior.
41+
If you think this issue has been recently introduced and did not occur in an earlier version, please note that. If possible, include the last version that the behavior was correct in addition to your current version.
42+
- type: textarea
43+
id: steps-to-reproduce
44+
attributes:
45+
label: Steps to Reproduce
46+
description: If you have steps that reproduce the issue, please add them here. If you can share a project that reproduces the issue, please attach it.
47+
- type: textarea
48+
id: logging
49+
attributes:
50+
label: Logging
51+
description: |
52+
If you are using SourceKit-LSP from Swift 6, running `sourcekit-lsp diagnose` in terminal and attaching the generated bundle helps us diagnose the issue.
53+
The generated bundle may contain paths to files on disk as well as portions of your source code. This greatly helps in reproducing issues, but you should only attach it if you feel comfortable doing so.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Feature Request
2+
description: A suggestion for a new feature
3+
labels: [enhancement]
4+
body:
5+
- type: textarea
6+
id: description
7+
attributes:
8+
label: Description
9+
description: |
10+
A description of your proposed feature.
11+
Examples that show what's missing, or what new capabilities will be possible, are very helpful!
12+
If this feature unlocks new use-cases please describe them.
13+
Provide links to existing issues or external references/discussions, if appropriate.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See https://swift.org/LICENSE.txt for license information
7+
# See https://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
contact_links:
10+
- name: Discussion Forum
11+
url: https://forums.swift.org/c/development/sourcekit-lsp
12+
about: Ask and answer questions about SourceKit-LSP

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
default.profraw
33
Package.resolved
44
/.build
5+
/.*-build
56
/Packages
67
/*.xcodeproj
78
/*.sublime-project

.vscode/tasks.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"disableTaskQueue": true,
1111
"group": "test",
1212
"label": "Run all tests (parallel)",
13+
"options": {
14+
"env": {
15+
"SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER": "1"
16+
}
17+
},
1318
"problemMatcher": [
1419
"$swiftc"
1520
],
@@ -30,7 +35,8 @@
3035
"label": "Run fast tests (parallel)",
3136
"options": {
3237
"env": {
33-
"SKIP_LONG_TESTS": "1"
38+
"SKIP_LONG_TESTS": "1",
39+
"SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER": "1"
3440
}
3541
},
3642
"problemMatcher": [

CODE_OF_CONDUCT.md

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

CONTRIBUTING.md

Lines changed: 161 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,163 @@
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+
> [!NOTE]
72+
> VS Code will note that that the `swift.sourcekit-lsp.serverPath` setting is deprecated. That’s because mixing and matching versions of sourcekit-lsp and Swift toolchains is generally not supported, so the settings is reserved for developers of SourceKit-LSP, which includes you. You can ignore this warning, If you have the `swift.path` setting to a recent [Swift Development Snapshot](https://www.swift.org/install).
73+
74+
> [!TIP]
75+
> 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
76+
> ```bash
77+
> $ lldb --wait-for --attach-name sourcekit-lsp
78+
> ```
79+
>
80+
> If you are developing SourceKit-LSP in Xcode, go to Debug -> Attach to Process by PID or Name.
81+
82+
## Selecting a Toolchain
83+
84+
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.
85+
86+
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.
87+
88+
## Logging
89+
90+
SourceKit-LSP has extensive logging to the system log on macOS and to `/var/logs/sourcekit-lsp` or stderr on other platforms.
91+
92+
To show the logs on macOS, run
93+
```sh
94+
log show --last 1h --predicate 'subsystem CONTAINS "org.swift.sourcekit-lsp"' --info --debug
95+
```
96+
Or to stream the logs as they are produced:
97+
```
98+
log stream --predicate 'subsystem CONTAINS "org.swift.sourcekit-lsp"' --level debug
99+
```
100+
101+
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
102+
103+
```sh
104+
sudo log config --subsystem org.swift.sourcekit-lsp --mode private_data:on
105+
```
106+
107+
To enable more verbose logging on non-macOS platforms, launch sourcekit-lsp with the `SOURCEKITLSP_LOG_LEVEL` environment variable set to `debug`.
108+
109+
110+
## Formatting
111+
112+
SourceKit-LSP is formatted using [swift-format](http://github.com/swiftlang/swift-format) to ensure a consistent style.
113+
114+
To format your changes run the formatter using the following command
115+
```bash
116+
swift package format-source-code
117+
```
118+
119+
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.
120+
121+
## Authoring commits
122+
123+
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.
124+
125+
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:
126+
- During review, the commits can be reviewed individually, making each review chunk smaller
127+
- 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.
128+
129+
## Opening a PR
130+
131+
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.
132+
133+
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).
134+
135+
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.
136+
137+
> [!TIP]
138+
> If you are stuck, it’s encouraged to submit a PR that describes the issue you’re having, e.g. if there are tests that are failing, build failures you can’t resolve, or if you have architectural questions. We’re happy to work with you to resolve those issues.
139+
140+
## Opening a PR for Release Branch
141+
142+
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:
143+
144+
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.
145+
146+
1. [This][form] should be filled out in the description of the PR.
147+
To use this template when creating a PR, append the `template=release.md`
148+
query parameter to the current URL and refresh.
149+
For example:
150+
```diff
151+
-https://github.com/swiftlang/sourcekit-lsp/compare/main...my-branch?quick_pull=1
152+
+https://github.com/swiftlang/sourcekit-lsp/compare/main...my-branch?quick_pull=1&template=release.md
153+
```
154+
155+
All changes going into a release branch must go through pull requests that are approved and merged by the corresponding release manager.
156+
157+
[form]: https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1
158+
159+
## Review and CI Testing
160+
161+
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.
162+
163+
Only contributors with [commit access](https://www.swift.org/contributing/#commit-access) are able to approve pull requests and trigger CI.

0 commit comments

Comments
 (0)