Skip to content

Merge main into release/6.2 #2162

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

Merged
merged 21 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
69ab356
Log contextual requests that affect sourcekitd’s global state
ahoppen Mar 27, 2025
da90f34
Add contextual request support to `sourcekit-lsp diagnose`
ahoppen Mar 27, 2025
d63419d
Address review comments
ahoppen May 12, 2025
385f8ae
Resolve paths passed in the SwiftPM configuration to the project root
bnbarham May 13, 2025
6e09a21
Log the path that SourceKit-LSP was launched from
ahoppen May 7, 2025
47a940d
Fix race condition that causes task cancellation to be missed in `Tas…
ahoppen May 13, 2025
ba1fb5d
Do not schedule any new tasks in `TaskScheduler` if it has been shut …
ahoppen May 13, 2025
8797f9c
Fix Package.swift warnings
Wilfred May 13, 2025
f3153ba
Merge pull request #2140 from ahoppen/log-launch-path
ahoppen May 13, 2025
a78bc5e
Merge pull request #2152 from ahoppen/cancellation-missed
ahoppen May 14, 2025
be5ae8c
Merge pull request #2153 from ahoppen/check-shutdown
ahoppen May 14, 2025
188e174
Merge pull request #2094 from ahoppen/contextual-sourcekitd-request
ahoppen May 14, 2025
f65bb76
Add more code owners
bnbarham May 14, 2025
8e8016e
Merge pull request #2150 from bnbarham/relative-swiftpm-paths
bnbarham May 14, 2025
a909439
Pass `cancelOnSubsequentRequest: 0` to all requests that support it
ahoppen May 14, 2025
66b20b9
Merge pull request #2159 from bnbarham/update-codeowners
ahoppen May 15, 2025
8a908f2
Pass `hostToolchainBinDir` to `SwiftSDKBundleStore` (#2157)
MaxDesiatov May 15, 2025
efe4836
Merge pull request #2158 from ahoppen/no-cancel-on-subsequent-request
ahoppen May 19, 2025
c6ed68a
Merge pull request #2154 from Wilfred/fix_package_warnings
bnbarham May 19, 2025
020ca39
Revert "Merge pull request #2159 from bnbarham/update-codeowners"
bnbarham May 19, 2025
a0a8f1e
Revert "Merge pull request #2094 from ahoppen/contextual-sourcekitd-r…
bnbarham May 20, 2025
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
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ var targets: [Target] = [
.product(name: "SwiftDocC", package: "swift-docc"),
.product(name: "SymbolKit", package: "swift-docc-symbolkit"),
],
exclude: ["CMakeLists.txt"],
exclude: [],
swiftSettings: globalSwiftSettings
),

Expand Down Expand Up @@ -807,7 +807,7 @@ var dependencies: [Package.Dependency] {
.package(url: "https://github.com/swiftlang/swift-docc.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/swiftlang/swift-docc-symbolkit.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/swiftlang/swift-markdown.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-tools-support-core.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/swiftlang/swift-tools-support-core.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.4.0"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
Expand Down
26 changes: 13 additions & 13 deletions Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,25 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
throw Error.cannotDetermineHostToolchain
}

var absProjectRoot = try AbsolutePath(validating: projectRoot.filePath)
let hostSDK = try SwiftSDK.hostSwiftSDK(AbsolutePath(validating: destinationToolchainBinDir.filePath))
let hostSwiftPMToolchain = try UserToolchain(swiftSDK: hostSDK)

let destinationSDK = try SwiftSDK.deriveTargetSwiftSDK(
hostSwiftSDK: hostSDK,
hostTriple: hostSwiftPMToolchain.targetTriple,
customToolsets: options.swiftPMOrDefault.toolsets?.map { try AbsolutePath(validating: $0) } ?? [],
customToolsets: options.swiftPMOrDefault.toolsets?.map {
try AbsolutePath(validating: $0, relativeTo: absProjectRoot)
} ?? [],
customCompileTriple: options.swiftPMOrDefault.triple.map { try Triple($0) },
swiftSDKSelector: options.swiftPMOrDefault.swiftSDK,
store: SwiftSDKBundleStore(
swiftSDKsDirectory: localFileSystem.getSharedSwiftSDKsDirectory(
explicitDirectory: options.swiftPMOrDefault.swiftSDKsDirectory.map { try AbsolutePath(validating: $0) }
explicitDirectory: options.swiftPMOrDefault.swiftSDKsDirectory.map {
try AbsolutePath(validating: $0, relativeTo: absProjectRoot)
}
),
hostToolchainBinDir: hostSwiftPMToolchain.swiftCompilerPath.parentDirectory,
fileSystem: localFileSystem,
observabilityScope: observabilitySystem.topScope.makeChildScope(description: "SwiftPM Bundle Store"),
outputHandler: { _ in }
Expand All @@ -227,20 +233,14 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
let destinationSwiftPMToolchain = try UserToolchain(swiftSDK: destinationSDK)

var location = try Workspace.Location(
forRootPackage: try AbsolutePath(validating: projectRoot.filePath),
forRootPackage: absProjectRoot,
fileSystem: localFileSystem
)

if options.backgroundIndexingOrDefault {
location.scratchDirectory = try AbsolutePath(
validating: projectRoot.appendingPathComponent(".build").appendingPathComponent("index-build").filePath
)
} else if let scratchDirectory = options.swiftPMOrDefault.scratchPath,
let scratchDirectoryPath = try? AbsolutePath(
validating: scratchDirectory,
relativeTo: AbsolutePath(validating: projectRoot.filePath)
)
{
location.scratchDirectory = scratchDirectoryPath
location.scratchDirectory = absProjectRoot.appending(components: ".build", "index-build")
} else if let scratchDirectory = options.swiftPMOrDefault.scratchPath {
location.scratchDirectory = try AbsolutePath(validating: scratchDirectory, relativeTo: absProjectRoot)
}

var configuration = WorkspaceConfiguration.default
Expand Down
4 changes: 1 addition & 3 deletions Sources/SemanticIndex/PreparationTaskDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ package struct PreparationTaskDescription: IndexTaskDescription {
do {
try await buildSystemManager.prepare(targets: Set(targetsToPrepare))
} catch {
logger.error(
"Preparation failed: \(error.forLogging)"
)
logger.error("Preparation failed: \(error.forLogging)")
}
await hooks.preparationTaskDidFinish?(self)
if !Task.isCancelled {
Expand Down
11 changes: 11 additions & 0 deletions Sources/SemanticIndex/TaskScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ package actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
_isExecuting.value = true
executionTask = task
executionTaskCreatedContinuation.yield(task)
if self.resultTaskCancelled.value {
// The queued task might have been cancelled after the execution ask was started but before the task was yielded
// to `executionTaskCreatedContinuation`. In that case the result task will simply cancel the await on the
// `executionTaskCreatedStream` and hence not call `valuePropagatingCancellation` on the execution task. This
// means that the queued task cancellation wouldn't be propagated to the execution task. To address this, check if
// `resultTaskCancelled` was set and, if so, explicitly cancel the execution task here.
task.cancel()
}
await executionStateChangedCallback?(self, .executing)
return await task.value
}
Expand Down Expand Up @@ -513,6 +521,9 @@ package actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
///
/// This will continue calling itself until the queue is empty.
private func poke() {
if isShutDown {
return
}
pendingTasks.sort(by: { $0.priority > $1.priority })
for task in pendingTasks {
guard
Expand Down
1 change: 1 addition & 0 deletions Sources/SourceKitLSP/Swift/MacroExpansion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ actor MacroExpansionManager {
let length = snapshot.utf8OffsetRange(of: range).count

let skreq = swiftLanguageService.sourcekitd.dictionary([
keys.cancelOnSubsequentRequest: 0,
keys.request: swiftLanguageService.requests.semanticRefactoring,
// Preferred name for e.g. an extracted variable.
// Empty string means sourcekitd chooses a name automatically.
Expand Down
1 change: 1 addition & 0 deletions Sources/SourceKitLSP/Swift/RefactoringResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ extension SwiftLanguageService {
let utf8Column = snapshot.lineTable.utf8ColumnAt(line: line, utf16Column: utf16Column)

let skreq = sourcekitd.dictionary([
keys.cancelOnSubsequentRequest: 0,
keys.request: self.requests.semanticRefactoring,
// Preferred name for e.g. an extracted variable.
// Empty string means sourcekitd chooses a name automatically.
Expand Down
1 change: 1 addition & 0 deletions Sources/SourceKitLSP/Swift/VariableTypeInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extension SwiftLanguageService {
let snapshot = try await self.latestSnapshot(for: uri)

let skreq = sourcekitd.dictionary([
keys.cancelOnSubsequentRequest: 0,
keys.request: requests.collectVariableType,
keys.sourceFile: snapshot.uri.sourcekitdSourceFile,
keys.primaryFile: snapshot.uri.primaryFile?.pseudoPath,
Expand Down
2 changes: 2 additions & 0 deletions Sources/sourcekit-lsp/SourceKitLSP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ struct SourceKitLSP: AsyncParsableCommand {
fatalError("failed to redirect stdout -> stderr: \(strerror(errno)!)")
}

logger.log("sourcekit-lsp launched from \(ProcessInfo.processInfo.arguments.first ?? "<nil>")")

let globalConfigurationOptions = globalConfigurationOptions
if let logLevelStr = globalConfigurationOptions.loggingOrDefault.level,
let logLevel = NonDarwinLogLevel(logLevelStr)
Expand Down