Skip to content
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.0
// swift-tools-version: 6.1

import Foundation
import PackageDescription
Expand Down
2 changes: 1 addition & 1 deletion Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package import LanguageServerProtocol
import LanguageServerProtocolExtensions
@preconcurrency import PackageGraph
import PackageLoading
import PackageModel
@preconcurrency import PackageModel
import SKLogging
package import SKOptions
@preconcurrency package import SPMBuildCore
Expand Down
6 changes: 0 additions & 6 deletions Sources/SKLogging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ package typealias LogLevel = os.OSLogType
package typealias Logger = os.Logger
package typealias Signposter = OSSignposter

#if compiler(<5.11)
extension OSSignposter: @unchecked Sendable {}
extension OSSignpostID: @unchecked Sendable {}
extension OSSignpostIntervalState: @unchecked Sendable {}
#else
extension OSSignposter: @retroactive @unchecked Sendable {}
extension OSSignpostID: @retroactive @unchecked Sendable {}
extension OSSignpostIntervalState: @retroactive @unchecked Sendable {}
#endif

extension os.Logger {
package func makeSignposter() -> Signposter {
Expand Down
24 changes: 0 additions & 24 deletions Sources/SKTestSupport/SkipUnless.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,30 +353,6 @@ package actor SkipUnless {
return .featureSupported
}
}

/// Checks that swift-format supports running as `swift-format format -` to indicate that the source file should be
/// read from stdin, ie. that swift-format contains https://github.com/swiftlang/swift-format/pull/914.
package static func swiftFormatSupportsDashToIndicateReadingFromStdin(
file: StaticString = #filePath,
line: UInt = #line
) async throws {
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 1), file: file, line: line) {
guard let swiftFormatPath = await ToolchainRegistry.forTesting.default?.swiftFormat else {
throw GenericError("Could not find swift-format")
}
let process = TSCBasic.Process(arguments: [try swiftFormatPath.filePath, "format", "-"])
let writeStream = try process.launch()
writeStream.send("let x = 1")
try writeStream.close()
let result = try await process.waitUntilExitStoppingProcessOnTaskCancellation()
let output = try result.utf8Output()
switch output {
case "": return false
case "let x = 1\n": return true
default: throw GenericError("Received unexpected formatting output: '\(output)'")
}
}
}
}

// MARK: - Parsing Swift compiler version
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKTestSupport/TestSourceKitLSPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ package final class TestSourceKitLSPClient: MessageHandler, Sendable {
.failure(ResponseError.unknown("\(R.method) request timed out after \(defaultTimeoutDuration)"))
)
}
await server.handle(notification: CancelRequestNotification(id: requestID))
server.handle(CancelRequestNotification(id: requestID))
}
server.handle(request, id: requestID) { result in
if replyOutstanding.takeValue() ?? false {
Expand Down
40 changes: 0 additions & 40 deletions Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,46 +309,6 @@ final class SwiftPMBuildSystemTests: XCTestCase {
}
}

func testDefaultSDKs() async throws {
try await withTestScratchDir { tempDir in
try FileManager.default.createFiles(
root: tempDir,
files: [
"pkg/Sources/lib/a.swift": "",
"pkg/Package.swift": """
// swift-tools-version:6.0
import PackageDescription
let package = Package(
name: "a",
targets: [.target(name: "lib")]
)
""",
]
)
let tr = ToolchainRegistry.forTesting

let options = SourceKitLSPOptions.SwiftPMOptions(
swiftSDKsDirectory: "/tmp/non_existent_sdks_dir",
triple: "wasm32-unknown-wasi"
)

let packageRoot = tempDir.appendingPathComponent("pkg")
let swiftpmBuildSystem = try await SwiftPMBuildSystem(
projectRoot: packageRoot,
toolchainRegistry: tr,
options: SourceKitLSPOptions(swiftPM: options),
connectionToSourceKitLSP: LocalConnection(receiverName: "Dummy"),
testHooks: SwiftPMTestHooks()
)
let path = await swiftpmBuildSystem.destinationBuildParameters.toolchain.sdkRootPath
XCTAssertEqual(
path?.components.suffix(3),
["usr", "share", "wasi-sysroot"],
"SwiftPMBuildSystem should share default SDK derivation logic with libSwiftPM"
)
}
}

func testManifestArgs() async throws {
try await withTestScratchDir { tempDir in
try FileManager.default.createFiles(
Expand Down
16 changes: 0 additions & 16 deletions Tests/SourceKitLSPTests/FormattingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import class TSCBasic.Process

final class FormattingTests: XCTestCase {
func testFormatting() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down Expand Up @@ -57,8 +55,6 @@ final class FormattingTests: XCTestCase {
}

func testFormattingNoEdits() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand All @@ -84,8 +80,6 @@ final class FormattingTests: XCTestCase {
}

func testConfigFileOnDisk() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
let project = try await MultiFileTestProject(files: [
".swift-format": """
Expand Down Expand Up @@ -120,8 +114,6 @@ final class FormattingTests: XCTestCase {
}

func testConfigFileInParentDirectory() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
let project = try await MultiFileTestProject(files: [
".swift-format": """
Expand Down Expand Up @@ -156,8 +148,6 @@ final class FormattingTests: XCTestCase {
}

func testConfigFileInNestedDirectory() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
let project = try await MultiFileTestProject(files: [
".swift-format": """
Expand Down Expand Up @@ -200,8 +190,6 @@ final class FormattingTests: XCTestCase {
}

func testInvalidConfigurationFile() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
// The swift-format default is 2 spaces.
let project = try await MultiFileTestProject(files: [
Expand All @@ -226,8 +214,6 @@ final class FormattingTests: XCTestCase {
}

func testInsertAndRemove() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down Expand Up @@ -259,8 +245,6 @@ final class FormattingTests: XCTestCase {
}

func testMultiLineStringInsertion() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down
6 changes: 0 additions & 6 deletions Tests/SourceKitLSPTests/OnTypeFormattingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import XCTest

final class OnTypeFormattingTests: XCTestCase {
func testOnlyFormatsSpecifiedLine() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down Expand Up @@ -53,8 +51,6 @@ final class OnTypeFormattingTests: XCTestCase {
}

func testFormatsFullLineAndDoesNotFormatNextLine() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down Expand Up @@ -92,8 +88,6 @@ final class OnTypeFormattingTests: XCTestCase {
/// Otherwise could mess up writing code. You'd write {} and try to go into the braces to write more code,
/// only for on-type formatting to immediately close the braces again.
func testDoesNothingWhenInAnEmptyLine() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down
52 changes: 24 additions & 28 deletions Tests/SourceKitLSPTests/PullDiagnosticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,37 +329,34 @@ final class PullDiagnosticsTests: XCTestCase {
}

func testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled() async throws {
let diagnosticRequestCancelled = MultiEntrySemaphore(name: "diagnostic request cancelled")
let packageLoadingDidFinish = self.expectation(description: "Package loading did finish")
var testHooks = Hooks()
testHooks.buildSystemHooks.swiftPMTestHooks.reloadPackageDidFinish = {
packageLoadingDidFinish.fulfill()
}
testHooks.indexHooks.preparationTaskDidStart = { _ in
await diagnosticRequestCancelled.waitOrXCTFail()
// Poll until the `CancelRequestNotification` has been propagated to the request handling.
// We can't use `repeatUntilExpectedResult` here because that throws a `CancellationError` when the preparation is
// cancelled.
for _ in 0..<Int(defaultTimeout * 100) {
if Task.isCancelled {
break
}
#if os(Windows)
Sleep(10 /*ms*/)
#else
usleep(10_000 /*µs*/)
#endif
}
}
// Use an example that is slow to type check to ensure that we don't get a diagnostic response from sourcekitd
// before the request cancellation gets handled.
let project = try await SwiftPMTestProject(
files: [
"Lib.swift": "let x: String = 1"
"Lib.swift": """
struct A: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
struct B: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
struct C: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }

func + (lhs: A, rhs: B) -> A { fatalError() }
func + (lhs: B, rhs: C) -> A { fatalError() }
func + (lhs: C, rhs: A) -> A { fatalError() }

func + (lhs: B, rhs: A) -> B { fatalError() }
func + (lhs: C, rhs: B) -> B { fatalError() }
func + (lhs: A, rhs: C) -> B { fatalError() }

func + (lhs: C, rhs: B) -> C { fatalError() }
func + (lhs: B, rhs: C) -> C { fatalError() }
func + (lhs: A, rhs: A) -> C { fatalError() }

func slow() {
let x: C = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
}
"""
],
hooks: testHooks,
enableBackgroundIndexing: true,
pollIndex: false
enableBackgroundIndexing: false
)
try await fulfillmentOfOrThrow(packageLoadingDidFinish)
let (uri, _) = try project.openDocument("Lib.swift")

let diagnosticResponseReceived = self.expectation(description: "Received diagnostic response")
Expand All @@ -370,7 +367,6 @@ final class PullDiagnosticsTests: XCTestCase {
diagnosticResponseReceived.fulfill()
}
project.testClient.send(CancelRequestNotification(id: requestID))
diagnosticRequestCancelled.signal()
try await fulfillmentOfOrThrow(diagnosticResponseReceived)
}

Expand Down
6 changes: 0 additions & 6 deletions Tests/SourceKitLSPTests/RangeFormattingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import XCTest

final class RangeFormattingTests: XCTestCase {
func testOnlyFormatsSpecifiedLines() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down Expand Up @@ -52,8 +50,6 @@ final class RangeFormattingTests: XCTestCase {
}

func testOnlyFormatsSpecifiedColumns() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down Expand Up @@ -86,8 +82,6 @@ final class RangeFormattingTests: XCTestCase {
}

func testFormatsMultipleLines() async throws {
try await SkipUnless.swiftFormatSupportsDashToIndicateReadingFromStdin()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)

Expand Down