Skip to content

Commit 77e66bd

Browse files
authored
Merge pull request #1603 from ahoppen/fix-warnings
Fix build warnings
2 parents 6901514 + ae660e0 commit 77e66bd

22 files changed

+40
-78
lines changed

Sources/BuildSystemIntegration/BuildServerBuildSystem.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import BuildServerProtocol
14+
import Foundation
1415
import LanguageServerProtocol
1516
import LanguageServerProtocolJSONRPC
1617
import SKLogging
@@ -26,13 +27,6 @@ import var TSCBasic.localFileSystem
2627
import func TSCBasic.lookupExecutablePath
2728
import func TSCBasic.resolveSymlinks
2829

29-
#if canImport(Darwin)
30-
import Foundation
31-
#else
32-
// FIMXE: (async-workaround) @preconcurrency needed because Pipe is not marked as Sendable on Linux rdar://132378792
33-
@preconcurrency import Foundation
34-
#endif
35-
3630
enum BuildServerTestError: Error {
3731
case executableNotFound(String)
3832
}

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ package struct DiagnoseCommand: AsyncParsableCommand {
213213
#if os(macOS)
214214
reportProgress(.collectingLogMessages(progress: 0), message: "Collecting log messages")
215215
let outputFileUrl = bundlePath.appendingPathComponent("log.txt")
216-
FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil)
216+
guard FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil) else {
217+
throw ReductionError("Failed to create log.txt")
218+
}
217219
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
218220
var bytesCollected = 0
219221
// 50 MB is an average log size collected by sourcekit-lsp diagnose.
@@ -304,7 +306,9 @@ package struct DiagnoseCommand: AsyncParsableCommand {
304306
@MainActor
305307
private func addSwiftVersion(toBundle bundlePath: URL) async throws {
306308
let outputFileUrl = bundlePath.appendingPathComponent("swift-versions.txt")
307-
FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil)
309+
guard FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil) else {
310+
throw ReductionError("Failed to create file at \(outputFileUrl)")
311+
}
308312
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
309313

310314
let toolchains = try await toolchainRegistry.toolchains

Sources/Diagnose/IndexCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ fileprivate extension SourceKitLSPServer {
121121
}
122122
}
123123

124-
extension ExperimentalFeature: ExpressibleByArgument {}
124+
extension ExperimentalFeature: ArgumentParser.ExpressibleByArgument {}

Sources/Diagnose/MergeSwiftFiles.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ extension RequestInfo {
2323
progressUpdate: (_ progress: Double, _ message: String) -> Void
2424
) async throws -> RequestInfo? {
2525
let swiftFilePaths = compilerArgs.filter { $0.hasSuffix(".swift") }
26-
let mergedFile = try swiftFilePaths.map { try String(contentsOfFile: $0) }.joined(separator: "\n\n\n\n")
26+
let mergedFile = try swiftFilePaths.map { try String(contentsOfFile: $0, encoding: .utf8) }
27+
.joined(separator: "\n\n\n\n")
2728

2829
progressUpdate(0, "Merging all .swift files into a single file")
2930

Sources/Diagnose/ReduceCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ package struct ReduceCommand: AsyncParsableCommand {
7878

7979
let progressBar = PercentProgressAnimation(stream: stderrStreamConcurrencySafe, header: "Reducing sourcekitd issue")
8080

81-
let request = try String(contentsOfFile: sourcekitdRequestPath)
81+
let request = try String(contentsOfFile: sourcekitdRequestPath, encoding: .utf8)
8282
let requestInfo = try RequestInfo(request: request)
8383

8484
let executor = OutOfProcessSourceKitRequestExecutor(

Sources/Diagnose/RequestInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ package struct RequestInfo: Sendable {
104104

105105
self.requestTemplate = requestTemplate
106106

107-
fileContents = try String(contentsOf: URL(fileURLWithPath: sourceFilePath))
107+
fileContents = try String(contentsOf: URL(fileURLWithPath: sourceFilePath), encoding: .utf8)
108108
}
109109

110110
/// Create a `RequestInfo` that is used to reduce a `swift-frontend issue`
@@ -126,7 +126,7 @@ package struct RequestInfo: Sendable {
126126
guard let fileList = iterator.next() else {
127127
throw ReductionError("Expected file path after -filelist command line argument")
128128
}
129-
frontendArgsWithFilelistInlined += try String(contentsOfFile: fileList)
129+
frontendArgsWithFilelistInlined += try String(contentsOfFile: fileList, encoding: .utf8)
130130
.split(separator: "\n")
131131
.map { String($0) }
132132
default:

Sources/Diagnose/RunSourcekitdRequestCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ package struct RunSourceKitdRequestCommand: AsyncParsableCommand {
4242
package init() {}
4343

4444
package func run() async throws {
45-
var requestString = try String(contentsOf: URL(fileURLWithPath: sourcekitdRequestPath))
45+
var requestString = try String(contentsOf: URL(fileURLWithPath: sourcekitdRequestPath), encoding: .utf8)
4646

4747
let installPath = try AbsolutePath(validating: Bundle.main.bundlePath)
4848
let sourcekitdPath =

Sources/SKLogging/NonDarwinLogging.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import SwiftExtensions
1515
#if canImport(Darwin)
1616
import Foundation
1717
#else
18-
// FIMXE: (async-workaround) @preconcurrency needed because DateFormatter and stderr are not marked as Sendable on Linux
19-
// rdar://125578486, rdar://132378589
18+
// TODO: @preconcurrency needed because stderr is not sendable on Linux https://github.com/swiftlang/swift/issues/75601
2019
@preconcurrency import Foundation
2120
#endif
2221

Sources/SKLogging/SetGlobalLogFileHandler.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import RegexBuilder
1515
#if canImport(Darwin)
1616
import Foundation
1717
#else
18-
// FIMXE: (async-workaround) @preconcurrency needed because DateFormatter and stderr are not marked as Sendable on Linux
19-
// rdar://125578486, rdar://132378589
18+
// TODO: @preconcurrency needed because stderr is not sendable on Linux https://github.com/swiftlang/swift/issues/75601
2019
@preconcurrency import Foundation
2120
#endif
2221

Sources/SKSupport/DocumentURI+CustomLogStringConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ extension DocumentURI {
2121
return "<DocumentURI length=\(description.count) hash=\(description.hashForLogging)>"
2222
}
2323
}
24-
extension DocumentURI: CustomLogStringConvertible {}
24+
extension DocumentURI: SKLogging.CustomLogStringConvertible {}

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,10 @@ package actor SkipUnless {
471471
.appending(component: "swift-frontend")
472472
return try await withTestScratchDir { scratchDirectory in
473473
let input = scratchDirectory.appending(component: "Input.swift")
474-
FileManager.default.createFile(atPath: input.pathString, contents: nil)
474+
guard FileManager.default.createFile(atPath: input.pathString, contents: nil) else {
475+
struct FailedToCrateInputFileError: Error {}
476+
throw FailedToCrateInputFileError()
477+
}
475478
// If we can't compile for wasm, this fails complaining that it can't find the stdlib for wasm.
476479
let process = Process(
477480
args: swiftFrontend.pathString,

Sources/SKTestSupport/TestJSONRPCConnection.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ import SKSupport
1717
import SwiftExtensions
1818
import XCTest
1919

20-
#if canImport(Darwin)
2120
import class Foundation.Pipe
22-
#else
23-
// FIMXE: (async-workaround) @preconcurrency needed because Pipe is not marked as Sendable on Linux rdar://132378792
24-
@preconcurrency import class Foundation.Pipe
25-
#endif
2621

2722
package final class TestJSONRPCConnection: Sendable {
2823
package let clientToServer: Pipe = Pipe()
@@ -207,7 +202,7 @@ private let testMessageRegistry = MessageRegistry(
207202
notifications: [EchoNotification.self, ShowMessageNotification.self]
208203
)
209204

210-
extension String: ResponseType {}
205+
extension String: LanguageServerProtocol.ResponseType {}
211206

212207
package struct EchoRequest: RequestType {
213208
package static let method: String = "test_server/echo"

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import BuildSystemIntegration
14+
import Foundation
1415
import LanguageServerProtocol
1516
import LanguageServerProtocolJSONRPC
1617
import SKLogging
@@ -22,21 +23,10 @@ import ToolchainRegistry
2223

2324
import struct TSCBasic.AbsolutePath
2425

25-
#if canImport(Darwin)
26-
import Foundation
27-
#else
28-
// FIMXE: (async-workaround) @preconcurrency needed because Pipe is not marked as Sendable on Linux
29-
@preconcurrency import Foundation
30-
#endif
31-
3226
#if os(Windows)
3327
import WinSDK
3428
#endif
3529

36-
#if !canImport(Darwin)
37-
extension Process: @unchecked Sendable {}
38-
#endif
39-
4030
/// A thin wrapper over a connection to a clangd server providing build setting handling.
4131
///
4232
/// In addition, it also intercepts notifications and replies from clangd in order to do things

Sources/SourceKitLSP/DocumentSnapshot+FromFileContents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package extension DocumentSnapshot {
2929
///
3030
/// Throws an error if the file could not be read.
3131
init(withContentsFromDisk url: URL, language: Language) throws {
32-
let contents = try String(contentsOf: url)
32+
let contents = try String(contentsOf: url, encoding: .utf8)
3333
self.init(uri: DocumentURI(url), language: language, version: 0, lineTable: LineTable(contents))
3434
}
3535
}

Sources/SourceKitLSP/IndexStoreDB+MainFilesProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ extension UncheckedIndex {
3434
}
3535
}
3636

37-
extension UncheckedIndex: MainFilesProvider {}
37+
extension UncheckedIndex: BuildSystemIntegration.MainFilesProvider {}

Sources/SourceKitLSP/Swift/MacroExpansion.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ extension SwiftLanguageService {
180180
}
181181

182182
func expandMacro(macroExpansionURLData: MacroExpansionReferenceDocumentURLData) async throws -> String {
183-
guard let sourceKitLSPServer = self.sourceKitLSPServer else {
184-
// `SourceKitLSPServer` has been destructed. We are tearing down the
185-
// language server. Nothing left to do.
186-
throw ResponseError.unknown("Connection to the editor closed")
187-
}
188-
189183
let expandMacroCommand = ExpandMacroCommand(
190184
positionRange: macroExpansionURLData.selectionRange,
191185
textDocument: TextDocumentIdentifier(macroExpansionURLData.primaryFile)

Sources/SourceKitLSP/Swift/MacroExpansionReferenceDocumentURLData.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ package struct MacroExpansionReferenceDocumentURLData {
5959
}
6060

6161
package init(displayName: String, queryItems: [URLQueryItem]) throws {
62-
guard let primaryFilePath = queryItems.last { $0.name == Parameters.primaryFilePath }?.value,
63-
let fromLine = Int(queryItems.last { $0.name == Parameters.fromLine }?.value ?? ""),
64-
let fromColumn = Int(queryItems.last { $0.name == Parameters.fromColumn }?.value ?? ""),
65-
let toLine = Int(queryItems.last { $0.name == Parameters.toLine }?.value ?? ""),
66-
let toColumn = Int(queryItems.last { $0.name == Parameters.toColumn }?.value ?? ""),
67-
let bufferName = queryItems.last { $0.name == Parameters.bufferName }?.value
62+
guard let primaryFilePath = queryItems.last(where: { $0.name == Parameters.primaryFilePath })?.value,
63+
let fromLine = Int(queryItems.last(where: { $0.name == Parameters.fromLine })?.value ?? ""),
64+
let fromColumn = Int(queryItems.last(where: { $0.name == Parameters.fromColumn })?.value ?? ""),
65+
let toLine = Int(queryItems.last(where: { $0.name == Parameters.toLine })?.value ?? ""),
66+
let toColumn = Int(queryItems.last(where: { $0.name == Parameters.toColumn })?.value ?? ""),
67+
let bufferName = queryItems.last(where: { $0.name == Parameters.bufferName })?.value
6868
else {
6969
throw ReferenceDocumentURLError(description: "Invalid queryItems for macro expansion reference document url")
7070
}

Sources/SourceKitLSP/Swift/ReferenceDocumentURL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ package enum ReferenceDocumentURL {
7878
throw ReferenceDocumentURLError(
7979
description: "Bad URL for reference document: \(url)"
8080
)
81-
default:
81+
case let documentType?:
8282
throw ReferenceDocumentURLError(
8383
description: "Invalid document type in URL for reference document: \(documentType)"
8484
)

Sources/sourcekit-lsp/SourceKitLSP.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import BuildSystemIntegration
1515
import Csourcekitd // Not needed here, but fixes debugging...
1616
import Diagnose
1717
import Dispatch
18+
import Foundation
1819
import LanguageServerProtocol
1920
import LanguageServerProtocolJSONRPC
2021
import SKLogging
@@ -28,13 +29,6 @@ import struct TSCBasic.AbsolutePath
2829
import struct TSCBasic.RelativePath
2930
import var TSCBasic.localFileSystem
3031

31-
#if canImport(Darwin)
32-
import Foundation
33-
#else
34-
// FIMXE: (async-workaround) @preconcurrency needed because FileHandle is not marked as Sendable on Linux rdar://132378985
35-
@preconcurrency import Foundation
36-
#endif
37-
3832
extension AbsolutePath {
3933
public init?(argument: String) {
4034
let path: AbsolutePath?
@@ -90,11 +84,11 @@ extension PathPrefixMapping {
9084
)
9185
}
9286
}
93-
extension PathPrefixMapping: ExpressibleByArgument {}
87+
extension PathPrefixMapping: ArgumentParser.ExpressibleByArgument {}
9488

95-
extension SKOptions.BuildConfiguration: ExpressibleByArgument {}
89+
extension SKOptions.BuildConfiguration: ArgumentParser.ExpressibleByArgument {}
9690

97-
extension SKOptions.WorkspaceType: ExpressibleByArgument {}
91+
extension SKOptions.WorkspaceType: ArgumentParser.ExpressibleByArgument {}
9892

9993
@main
10094
struct SourceKitLSP: AsyncParsableCommand {

Tests/BuildSystemIntegrationTests/BuildServerBuildSystemTests.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@
1212

1313
import BuildServerProtocol
1414
import BuildSystemIntegration
15+
import Foundation
1516
import ISDBTestSupport
1617
import LanguageServerProtocol
1718
import SKTestSupport
1819
import TSCBasic
1920
import XCTest
2021

21-
#if canImport(Darwin)
22-
import Foundation
23-
#else
24-
// FIMXE: (async-workaround) @preconcurrency needed because Pipe is not marked as Sendable on Linux rdar://132378792
25-
@preconcurrency import Foundation
26-
#endif
27-
2822
/// The path to the INPUTS directory of shared test projects.
2923
private let skTestSupportInputsDirectory: URL = {
3024
#if os(macOS)

Tests/LanguageServerProtocolJSONRPCTests/ConnectionTests.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ import LanguageServerProtocol
1515
import SKTestSupport
1616
import XCTest
1717

18-
#if canImport(Darwin)
1918
import class Foundation.Pipe
20-
#else
21-
// FIMXE: (async-workaround) @preconcurrency needed because Pipe is not marked as Sendable on Linux rdar://132378792
22-
@preconcurrency import class Foundation.Pipe
23-
#endif
2419

2520
#if os(Windows)
2621
import WinSDK

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ final class BackgroundIndexingTests: XCTestCase {
11991199
)
12001200
let packageResolvedURL = project.scratchDirectory.appendingPathComponent("Package.resolved")
12011201

1202-
let originalPackageResolvedContents = try String(contentsOf: packageResolvedURL)
1202+
let originalPackageResolvedContents = try String(contentsOf: packageResolvedURL, encoding: .utf8)
12031203

12041204
// First check our setup to see that we get the expected hover response before changing the dependency project.
12051205
let (uri, positions) = try project.openDocument("Test.swift")
@@ -1234,7 +1234,7 @@ final class BackgroundIndexingTests: XCTestCase {
12341234
])
12351235
)
12361236
try await project.testClient.send(PollIndexRequest())
1237-
XCTAssertEqual(try String(contentsOf: packageResolvedURL), originalPackageResolvedContents)
1237+
XCTAssertEqual(try String(contentsOf: packageResolvedURL, encoding: .utf8), originalPackageResolvedContents)
12381238

12391239
// Simulate a package update which goes as follows:
12401240
// - The user runs `swift package update`
@@ -1248,7 +1248,7 @@ final class BackgroundIndexingTests: XCTestCase {
12481248
],
12491249
workingDirectory: nil
12501250
)
1251-
XCTAssertNotEqual(try String(contentsOf: packageResolvedURL), originalPackageResolvedContents)
1251+
XCTAssertNotEqual(try String(contentsOf: packageResolvedURL, encoding: .utf8), originalPackageResolvedContents)
12521252
project.testClient.send(
12531253
DidChangeWatchedFilesNotification(changes: [
12541254
FileEvent(uri: DocumentURI(project.scratchDirectory.appendingPathComponent("Package.resolved")), type: .changed)

0 commit comments

Comments
 (0)