Skip to content

Commit 0ebe641

Browse files
committed
Merge commit 'a111b4748be9fbc893abb8a6c4871bb59dabbde0' into 6.0/merge-main-2024-06-22
2 parents c557f16 + a111b47 commit 0ebe641

31 files changed

+299
-148
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ If you want test your changes to SourceKit-LSP inside your editor, you can point
6868
"swift.sourcekit-lsp.serverPath": "/path/to/sourcekit-lsp/.build/arm64-apple-macosx/debug/sourcekit-lsp",
6969
```
7070

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+
7174
> [!TIP]
7275
> 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
7376
> ```bash

Documentation/Enable Experimental Background Indexing.md

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,23 @@
22

33
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.
44

5-
> [!WARNING]
6-
> Background indexing is still an experimental feature and still has some non-trivial limitations and bugs (see the known issues).
7-
85
## Set Up
96

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-
Background indexing requires a Swift 6 toolchain. You can download Swift 6 nightly toolchains from https://www.swift.org/download/#swift-60-development.
7+
1. Install a `main` or `release/6.0` Swift Development Snapshot from https://www.swift.org/install.
8+
2. Point your editor to the newly installed toolchain.
9+
- In VS Code on macOS this can be done by adding the following to your `settings.json`: `"swift.path": "/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin"`
10+
- In VS Code on other platforms, you need to set the `swift.path` to the `usr/bin` directory of your toolchain’s install location.
11+
- Other editors likely also have a way to pick the Swift toolchain, the exact steps vary by your setup.
12+
3. Enable the experimental `background-indexing` feature.
13+
- In VS Code, add the following to your `settings.json`: `"swift.sourcekit-lsp.serverArguments": [ "--experimental-feature", "background-indexing" ]`
14+
- In other editors, change the invocation that launches `sourcekit-lsp` to pass the `--experimental-feature background-indexing` command line arguments. The exact steps vary by your setup.
2615

2716
## Known issues
2817

29-
- 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]
30-
- Workaround: Run the toolchains on an older version of macOS, if possible
3118
- 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)
3219
- 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
33-
- Workaround: Ensure that your files dependencies are in a buildable state to get an up-to-date index and proper cross-module functionality
20+
- Workaround 1: Ensure that your files dependencies are in a buildable state to get an up-to-date index and proper cross-module functionality
21+
- Workaround 2: Enable the `swiftpm-prepare-for-indexing` experimental feature, which continues to build Swift module even in the presence of errors.
3422
- 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)
3523
- Workaround: Make some edit to the files that had references to re-index them
3624
- 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)
@@ -40,5 +28,5 @@ Background indexing requires a Swift 6 toolchain. You can download Swift 6 night
4028
## Filing issues
4129

4230
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:
43-
- A diagnostic bundle generated by running `path/to/sourcekit-lsp diagnose --toolchain path/to/the/toolchain/you/are/using`
44-
- Your project including the `.index-build` folder.
31+
- A diagnostic bundle generated by running `path/to/sourcekit-lsp diagnose`.
32+
- Your project including the `.index-build` folder, if possible.

Package.swift

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version: 5.8
22

33
import Foundation
44
import PackageDescription
55

6+
let strictConcurrencySettings: [SwiftSetting] = [
7+
.enableUpcomingFeature("StrictConcurrency"),
8+
.enableUpcomingFeature("RegionBasedIsolation"),
9+
.enableUpcomingFeature("InferSendableFromCaptures"),
10+
]
11+
612
let package = Package(
713
name: "SourceKitLSP",
814
platforms: [.macOS(.v13)],
@@ -34,6 +40,7 @@ let package = Package(
3440
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
3541
],
3642
exclude: ["CMakeLists.txt"],
43+
swiftSettings: strictConcurrencySettings,
3744
linkerSettings: sourcekitLSPLinkSettings
3845
),
3946

@@ -46,7 +53,7 @@ let package = Package(
4653
"LanguageServerProtocol"
4754
],
4855
exclude: ["CMakeLists.txt"],
49-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
56+
swiftSettings: strictConcurrencySettings
5057
),
5158

5259
// MARK: CAtomics
@@ -87,7 +94,8 @@ let package = Package(
8794
.product(name: "SwiftParser", package: "swift-syntax"),
8895
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
8996
],
90-
exclude: ["CMakeLists.txt"]
97+
exclude: ["CMakeLists.txt"],
98+
swiftSettings: strictConcurrencySettings
9199
),
92100

93101
.testTarget(
@@ -100,7 +108,8 @@ let package = Package(
100108
"SKCore",
101109
"SKTestSupport",
102110
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
103-
]
111+
],
112+
swiftSettings: strictConcurrencySettings
104113
),
105114

106115
// MARK: InProcessClient
@@ -113,7 +122,8 @@ let package = Package(
113122
"SKCore",
114123
"SourceKitLSP",
115124
],
116-
exclude: ["CMakeLists.txt"]
125+
exclude: ["CMakeLists.txt"],
126+
swiftSettings: strictConcurrencySettings
117127
),
118128

119129
// MARK: LanguageServerProtocol
@@ -122,15 +132,16 @@ let package = Package(
122132
name: "LanguageServerProtocol",
123133
dependencies: [],
124134
exclude: ["CMakeLists.txt"],
125-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
135+
swiftSettings: strictConcurrencySettings
126136
),
127137

128138
.testTarget(
129139
name: "LanguageServerProtocolTests",
130140
dependencies: [
131141
"LanguageServerProtocol",
132142
"LSPTestSupport",
133-
]
143+
],
144+
swiftSettings: strictConcurrencySettings
134145
),
135146

136147
// MARK: LanguageServerProtocolJSONRPC
@@ -143,15 +154,16 @@ let package = Package(
143154
"LSPLogging",
144155
],
145156
exclude: ["CMakeLists.txt"],
146-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
157+
swiftSettings: strictConcurrencySettings
147158
),
148159

149160
.testTarget(
150161
name: "LanguageServerProtocolJSONRPCTests",
151162
dependencies: [
152163
"LanguageServerProtocolJSONRPC",
153164
"LSPTestSupport",
154-
]
165+
],
166+
swiftSettings: strictConcurrencySettings
155167
),
156168

157169
// MARK: LSPLogging
@@ -164,15 +176,16 @@ let package = Package(
164176
.product(name: "Crypto", package: "swift-crypto"),
165177
],
166178
exclude: ["CMakeLists.txt"],
167-
swiftSettings: lspLoggingSwiftSettings + [.enableExperimentalFeature("StrictConcurrency")]
179+
swiftSettings: lspLoggingSwiftSettings + strictConcurrencySettings
168180
),
169181

170182
.testTarget(
171183
name: "LSPLoggingTests",
172184
dependencies: [
173185
"LSPLogging",
174186
"SKTestSupport",
175-
]
187+
],
188+
swiftSettings: strictConcurrencySettings
176189
),
177190

178191
// MARK: LSPTestSupport
@@ -185,7 +198,8 @@ let package = Package(
185198
"LanguageServerProtocolJSONRPC",
186199
"SKSupport",
187200
"SwiftExtensions",
188-
]
201+
],
202+
swiftSettings: strictConcurrencySettings
189203
),
190204

191205
// MARK: SemanticIndex
@@ -199,14 +213,16 @@ let package = Package(
199213
"SwiftExtensions",
200214
.product(name: "IndexStoreDB", package: "indexstore-db"),
201215
],
202-
exclude: ["CMakeLists.txt"]
216+
exclude: ["CMakeLists.txt"],
217+
swiftSettings: strictConcurrencySettings
203218
),
204219

205220
.testTarget(
206221
name: "SemanticIndexTests",
207222
dependencies: [
208223
"SemanticIndex"
209-
]
224+
],
225+
swiftSettings: strictConcurrencySettings
210226
),
211227

212228
// MARK: SKCore
@@ -227,15 +243,16 @@ let package = Package(
227243
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
228244
],
229245
exclude: ["CMakeLists.txt"],
230-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
246+
swiftSettings: strictConcurrencySettings
231247
),
232248

233249
.testTarget(
234250
name: "SKCoreTests",
235251
dependencies: [
236252
"SKCore",
237253
"SKTestSupport",
238-
]
254+
],
255+
swiftSettings: strictConcurrencySettings
239256
),
240257

241258
// MARK: SKSupport
@@ -252,7 +269,7 @@ let package = Package(
252269
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
253270
],
254271
exclude: ["CMakeLists.txt"],
255-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
272+
swiftSettings: strictConcurrencySettings
256273
),
257274

258275
.testTarget(
@@ -262,7 +279,8 @@ let package = Package(
262279
"SKSupport",
263280
"SKTestSupport",
264281
"SwiftExtensions",
265-
]
282+
],
283+
swiftSettings: strictConcurrencySettings
266284
),
267285

268286
// MARK: SKSwiftPMWorkspace
@@ -279,7 +297,7 @@ let package = Package(
279297
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
280298
],
281299
exclude: ["CMakeLists.txt"],
282-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
300+
swiftSettings: strictConcurrencySettings
283301
),
284302

285303
.testTarget(
@@ -293,7 +311,8 @@ let package = Package(
293311
"SourceKitLSP",
294312
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
295313
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
296-
]
314+
],
315+
swiftSettings: strictConcurrencySettings
297316
),
298317

299318
// MARK: SKTestSupport
@@ -312,9 +331,8 @@ let package = Package(
312331
.product(name: "ISDBTestSupport", package: "indexstore-db"),
313332
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
314333
],
315-
resources: [
316-
.copy("INPUTS")
317-
]
334+
resources: [.copy("INPUTS")],
335+
swiftSettings: strictConcurrencySettings
318336
),
319337

320338
// MARK: SourceKitD
@@ -330,7 +348,7 @@ let package = Package(
330348
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
331349
],
332350
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
333-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
351+
swiftSettings: strictConcurrencySettings
334352
),
335353

336354
.testTarget(
@@ -340,7 +358,8 @@ let package = Package(
340358
"SKCore",
341359
"SKTestSupport",
342360
"SwiftExtensions",
343-
]
361+
],
362+
swiftSettings: strictConcurrencySettings
344363
),
345364

346365
// MARK: SourceKitLSP
@@ -369,7 +388,8 @@ let package = Package(
369388
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
370389
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
371390
],
372-
exclude: ["CMakeLists.txt"]
391+
exclude: ["CMakeLists.txt"],
392+
swiftSettings: strictConcurrencySettings
373393
),
374394

375395
.testTarget(
@@ -393,14 +413,16 @@ let package = Package(
393413
// be used by test cases that test macros (see `SwiftPMTestProject.macroPackageManifest`).
394414
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
395415
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
396-
]
416+
],
417+
swiftSettings: strictConcurrencySettings
397418
),
398419

399420
// MARK: SwiftExtensions
400421

401422
.target(
402423
name: "SwiftExtensions",
403-
exclude: ["CMakeLists.txt"]
424+
exclude: ["CMakeLists.txt"],
425+
swiftSettings: strictConcurrencySettings
404426
),
405427
]
406428
)

Sources/Diagnose/CommandLineArgumentsReducer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fileprivate class CommandLineArgumentReducer {
6262
///
6363
/// If `simultaneousRemove` is set, the reducer will try to remove that many arguments at once. This is useful to
6464
/// quickly remove multiple arguments from the request.
65+
@MainActor
6566
private func reduce(initialRequestInfo: RequestInfo, simultaneousRemove: Int) async throws -> RequestInfo {
6667
guard initialRequestInfo.compilerArgs.count > simultaneousRemove else {
6768
// Trying to remove more command line arguments than we have. This isn't going to work.

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
226226
"--predicate", #"subsystem = "org.swift.sourcekit-lsp" AND process = "sourcekit-lsp""#,
227227
"--info",
228228
"--debug",
229+
"--signpost",
229230
],
230231
outputRedirection: .stream(
231232
stdout: { bytes in
@@ -368,7 +369,9 @@ public struct DiagnoseCommand: AsyncParsableCommand {
368369
if let bundleOutputPath = self.bundleOutputPath {
369370
URL(fileURLWithPath: bundleOutputPath)
370371
} else {
371-
FileManager.default.temporaryDirectory.appendingPathComponent("sourcekit-lsp-diagnose-\(date)")
372+
FileManager.default.temporaryDirectory
373+
.appendingPathComponent("sourcekit-lsp-diagnose")
374+
.appendingPathComponent("sourcekit-lsp-diagnose-\(date)")
372375
}
373376
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)
374377

Sources/Diagnose/IndexCommand.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import SwiftExtensions
2121

2222
import struct TSCBasic.AbsolutePath
2323
import class TSCBasic.Process
24-
import var TSCBasic.stderrStream
2524
import class TSCUtility.PercentProgressAnimation
2625

2726
private actor IndexLogMessageHandler: MessageHandler {

Sources/Diagnose/ReduceCommand.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SKCore
1616

1717
import struct TSCBasic.AbsolutePath
1818
import class TSCBasic.Process
19-
import var TSCBasic.stderrStream
2019
import class TSCUtility.PercentProgressAnimation
2120

2221
public struct ReduceCommand: AsyncParsableCommand {
@@ -77,7 +76,7 @@ public struct ReduceCommand: AsyncParsableCommand {
7776
throw ReductionError("Unable to find sourcekitd.framework")
7877
}
7978

80-
let progressBar = PercentProgressAnimation(stream: stderrStream, header: "Reducing sourcekitd issue")
79+
let progressBar = PercentProgressAnimation(stream: stderrStreamConcurrencySafe, header: "Reducing sourcekitd issue")
8180

8281
let request = try String(contentsOfFile: sourcekitdRequestPath)
8382
let requestInfo = try RequestInfo(request: request)

Sources/Diagnose/ReduceFrontendCommand.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SKCore
1616

1717
import struct TSCBasic.AbsolutePath
1818
import class TSCBasic.Process
19-
import var TSCBasic.stderrStream
2019
import class TSCUtility.PercentProgressAnimation
2120

2221
public struct ReduceFrontendCommand: AsyncParsableCommand {
@@ -86,7 +85,7 @@ public struct ReduceFrontendCommand: AsyncParsableCommand {
8685
}
8786

8887
let progressBar = PercentProgressAnimation(
89-
stream: stderrStream,
88+
stream: stderrStreamConcurrencySafe,
9089
header: "Reducing swift-frontend crash"
9190
)
9291

0 commit comments

Comments
 (0)