Skip to content

Build SourceKit-LSP in the Swift 6 language mode #1583

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 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 27 additions & 57 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
import Foundation
import PackageDescription

let strictConcurrencySettings: [SwiftSetting] = [
.enableUpcomingFeature("StrictConcurrency"),
.enableUpcomingFeature("RegionBasedIsolation"),
.enableUpcomingFeature("InferSendableFromCaptures"),
]

let package = Package(
name: "SourceKitLSP",
platforms: [.macOS(.v13)],
Expand Down Expand Up @@ -40,7 +34,6 @@ let package = Package(
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings,
linkerSettings: sourcekitLSPLinkSettings
),

Expand All @@ -52,8 +45,7 @@ let package = Package(
dependencies: [
"LanguageServerProtocol"
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

// MARK: CAtomics
Expand Down Expand Up @@ -94,8 +86,7 @@ let package = Package(
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
Expand All @@ -108,8 +99,7 @@ let package = Package(
"SKCore",
"SKTestSupport",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: InProcessClient
Expand All @@ -122,26 +112,23 @@ let package = Package(
"SKCore",
"SourceKitLSP",
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

// MARK: LanguageServerProtocol
// The core LSP types, suitable for any LSP implementation.
.target(
name: "LanguageServerProtocol",
dependencies: [],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
name: "LanguageServerProtocolTests",
dependencies: [
"LanguageServerProtocol",
"LSPTestSupport",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: LanguageServerProtocolJSONRPC
Expand All @@ -153,17 +140,15 @@ let package = Package(
"LanguageServerProtocol",
"LSPLogging",
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
name: "LanguageServerProtocolJSONRPCTests",
dependencies: [
"LanguageServerProtocolJSONRPC",
"LSPTestSupport",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: LSPLogging
Expand All @@ -176,16 +161,15 @@ let package = Package(
.product(name: "Crypto", package: "swift-crypto"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: lspLoggingSwiftSettings + strictConcurrencySettings
swiftSettings: lspLoggingSwiftSettings
),

.testTarget(
name: "LSPLoggingTests",
dependencies: [
"LSPLogging",
"SKTestSupport",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: LSPTestSupport
Expand All @@ -198,8 +182,7 @@ let package = Package(
"LanguageServerProtocolJSONRPC",
"SKSupport",
"SwiftExtensions",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: SemanticIndex
Expand All @@ -213,8 +196,7 @@ let package = Package(
"SwiftExtensions",
.product(name: "IndexStoreDB", package: "indexstore-db"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
Expand All @@ -223,8 +205,7 @@ let package = Package(
"LSPLogging",
"SemanticIndex",
"SKTestSupport",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: SKCore
Expand All @@ -244,17 +225,15 @@ let package = Package(
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
name: "SKCoreTests",
dependencies: [
"SKCore",
"SKTestSupport",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: SKSupport
Expand All @@ -270,8 +249,7 @@ let package = Package(
"SwiftExtensions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
Expand All @@ -281,8 +259,7 @@ let package = Package(
"SKSupport",
"SKTestSupport",
"SwiftExtensions",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: SKSwiftPMWorkspace
Expand All @@ -298,8 +275,7 @@ let package = Package(
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
Expand All @@ -313,8 +289,7 @@ let package = Package(
"SourceKitLSP",
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: SKTestSupport
Expand All @@ -333,8 +308,7 @@ let package = Package(
.product(name: "ISDBTestSupport", package: "indexstore-db"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
resources: [.copy("INPUTS")],
swiftSettings: strictConcurrencySettings
resources: [.copy("INPUTS")]
),

// MARK: SourceKitD
Expand All @@ -348,8 +322,7 @@ let package = Package(
"SwiftExtensions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"]
),

.testTarget(
Expand All @@ -359,8 +332,7 @@ let package = Package(
"SKCore",
"SKTestSupport",
"SwiftExtensions",
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: SourceKitLSP
Expand Down Expand Up @@ -390,8 +362,7 @@ let package = Package(
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),

.testTarget(
Expand All @@ -416,18 +387,17 @@ let package = Package(
// be used by test cases that test macros (see `SwiftPMTestProject.macroPackageManifest`).
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
],
swiftSettings: strictConcurrencySettings
]
),

// MARK: SwiftExtensions

.target(
name: "SwiftExtensions",
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
exclude: ["CMakeLists.txt"]
),
]
],
swiftLanguageVersions: [.v5, .version("6")]
)

// MARK: - Parse build arguments
Expand Down
4 changes: 0 additions & 4 deletions Sources/Diagnose/IndexCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,4 @@ fileprivate extension SourceKitLSPServer {
}
}

#if compiler(>=6)
extension ExperimentalFeature: @retroactive ExpressibleByArgument {}
#else
extension ExperimentalFeature: ExpressibleByArgument {}
#endif
9 changes: 7 additions & 2 deletions Sources/Diagnose/StderrStreamConcurrencySafe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
//
//===----------------------------------------------------------------------===//

import TSCLibc

import class TSCBasic.LocalFileOutputByteStream
import class TSCBasic.ThreadSafeOutputByteStream

#if canImport(Darwin)
import TSCLibc
#else
// FIXME: (async-workaround) @preconcurrency needed because stderr is not sendable on Linux rdar://125578486
@preconcurrency import TSCLibc
#endif

// A version of `stderrStream` from `TSCBasic` that is a `let` and can thus be used from Swift 6.
let stderrStreamConcurrencySafe: ThreadSafeOutputByteStream = try! ThreadSafeOutputByteStream(
LocalFileOutputByteStream(
Expand Down
9 changes: 8 additions & 1 deletion Sources/LSPLogging/NonDarwinLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import SwiftExtensions

#if canImport(Darwin)
import Foundation
#else
// FIMXE: (async-workaround) @preconcurrency needed because DateFormatter and stderr are not marked as Sendable on Linux
// rdar://125578486, rdar://132378589
@preconcurrency import Foundation
#endif

// MARK: - Log settings

package enum LogConfig {
Expand Down
9 changes: 8 additions & 1 deletion Sources/LSPLogging/SetGlobalLogFileHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import RegexBuilder

#if canImport(Darwin)
import Foundation
#else
// FIMXE: (async-workaround) @preconcurrency needed because DateFormatter and stderr are not marked as Sendable on Linux
// rdar://125578486, rdar://132378589
@preconcurrency import Foundation
#endif

#if os(Windows)
import WinSDK
#endif
Expand Down
54 changes: 26 additions & 28 deletions Sources/LSPTestSupport/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,34 @@ package func unwrap<T>(
return try XCTUnwrap(expression, file: file, line: line)
}

extension XCTestCase {
private struct ExpectationNotFulfilledError: Error, CustomStringConvertible {
var expecatations: [XCTestExpectation]
private struct ExpectationNotFulfilledError: Error, CustomStringConvertible {
var expecatations: [XCTestExpectation]

var description: String {
return """
One of the expectation was not fulfilled within timeout: \
\(expecatations.map(\.description).joined(separator: ", "))
"""
}
var description: String {
return """
One of the expectation was not fulfilled within timeout: \
\(expecatations.map(\.description).joined(separator: ", "))
"""
}
}

/// Wait for the given expectations to be fulfilled. If the expectations aren't
/// fulfilled within `timeout`, throw an error, aborting the test execution.
package func fulfillmentOfOrThrow(
_ expectations: [XCTestExpectation],
timeout: TimeInterval = defaultTimeout,
enforceOrder enforceOrderOfFulfillment: Bool = false
) async throws {
// `XCTWaiter.fulfillment` was introduced in the macOS 13.3 SDK but marked as being available on macOS 10.15.
// At the same time that XCTWaiter.fulfillment was introduced `XCTWaiter.wait` was deprecated in async contexts.
// This means that we can't write code that compiles without warnings with both the macOS 13.3 and any previous SDK.
// Accepting the warning here when compiling with macOS 13.3 or later is the only thing that I know of that we can do here.
let started = await XCTWaiter.fulfillment(
of: expectations,
timeout: timeout,
enforceOrder: enforceOrderOfFulfillment
)
if started != .completed {
throw ExpectationNotFulfilledError(expecatations: expectations)
}
/// Wait for the given expectations to be fulfilled. If the expectations aren't
/// fulfilled within `timeout`, throw an error, aborting the test execution.
package nonisolated func fulfillmentOfOrThrow(
_ expectations: [XCTestExpectation],
timeout: TimeInterval = defaultTimeout,
enforceOrder enforceOrderOfFulfillment: Bool = false
) async throws {
// `XCTWaiter.fulfillment` was introduced in the macOS 13.3 SDK but marked as being available on macOS 10.15.
// At the same time that XCTWaiter.fulfillment was introduced `XCTWaiter.wait` was deprecated in async contexts.
// This means that we can't write code that compiles without warnings with both the macOS 13.3 and any previous SDK.
// Accepting the warning here when compiling with macOS 13.3 or later is the only thing that I know of that we can do here.
let started = await XCTWaiter.fulfillment(
of: expectations,
timeout: timeout,
enforceOrder: enforceOrderOfFulfillment
)
if started != .completed {
throw ExpectationNotFulfilledError(expecatations: expectations)
}
}
Loading