Skip to content

Commit 95538e7

Browse files
committed
Migrate appendingPathComponent to appending(component:)
`appending(component:)` is the more modern API and can take multiple path components at the same time.
1 parent 32e919c commit 95538e7

File tree

52 files changed

+332
-432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+332
-432
lines changed

SourceKitLSPDevUtils/Package.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// swift-tools-version: 6.0
1+
// swift-tools-version: 6.2
22

33
import Foundation
44
import PackageDescription
55

66
let package = Package(
77
name: "SourceKitLSPDevUtils",
8-
platforms: [.macOS(.v10_15)],
8+
platforms: [.macOS(.v14)],
99
products: [
1010
.executable(name: "sourcekit-lsp-dev-utils", targets: ["SourceKitLSPDevUtils"])
1111
],
@@ -24,7 +24,8 @@ let package = Package(
2424
.product(name: "SwiftParser", package: "swift-syntax"),
2525
]
2626
),
27-
]
27+
],
28+
swiftLanguageModes: [.v6]
2829
)
2930

3031
let dependencies: [(url: String, path: String, fromVersion: Version)] = [

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/ConfigSchemaGen.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ package struct ConfigSchemaGen {
3636
.deletingLastPathComponent()
3737
private static let sourceDir =
3838
projectRoot
39-
.appendingPathComponent("Sources")
40-
.appendingPathComponent("SKOptions")
39+
.appending(components: "Sources", "SKOptions")
4140
private static let configSchemaJSONPath =
4241
projectRoot
43-
.appendingPathComponent("config.schema.json")
42+
.appending(component: "config.schema.json")
4443
private static let configSchemaDocPath =
4544
projectRoot
46-
.appendingPathComponent("Documentation")
47-
.appendingPathComponent("Configuration File.md")
45+
.appending(components: "Documentation", "Configuration File.md")
4846

4947
/// Generates and writes the JSON schema and documentation for the SourceKit-LSP configuration file format.
5048
package static func generate() throws {

Sources/BuildServerIntegration/CompilationDatabase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ package struct CompilationDatabaseCompileCommand: Equatable, Codable {
8686
if filename.isAbsolutePath || !directory.isAbsolutePath {
8787
return DocumentURI(filePath: filename, isDirectory: false)
8888
} else {
89-
return DocumentURI(URL(fileURLWithPath: directory).appendingPathComponent(filename, isDirectory: false))
89+
return DocumentURI(URL(fileURLWithPath: directory).appending(component: filename, directoryHint: .notDirectory))
9090
}
9191
}
9292
}
@@ -127,7 +127,7 @@ package struct JSONCompilationDatabase: Equatable, Codable {
127127
///
128128
/// - Returns: `nil` if `compile_commands.json` was not found
129129
package init(directory: URL) throws {
130-
let path = directory.appendingPathComponent(JSONCompilationDatabaseBuildServer.dbName)
130+
let path = directory.appending(component: JSONCompilationDatabaseBuildServer.dbName)
131131
try self.init(file: path)
132132
}
133133

Sources/BuildServerIntegration/DetermineBuildServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ private func searchForCompilationDatabaseConfig(
4040
.compactMap { searchPath in
4141
let path = workspaceFolder.appending(searchPath)
4242

43-
let jsonPath = path.appendingPathComponent(JSONCompilationDatabaseBuildServer.dbName)
43+
let jsonPath = path.appending(component: JSONCompilationDatabaseBuildServer.dbName)
4444
if FileManager.default.isFile(at: jsonPath) {
4545
return BuildServerSpec(kind: .jsonCompilationDatabase, projectRoot: workspaceFolder, configPath: jsonPath)
4646
}
4747

48-
let fixedPath = path.appendingPathComponent(FixedCompilationDatabaseBuildServer.dbName)
48+
let fixedPath = path.appending(component: FixedCompilationDatabaseBuildServer.dbName)
4949
if FileManager.default.isFile(at: fixedPath) {
5050
return BuildServerSpec(kind: .fixedCompilationDatabase, projectRoot: workspaceFolder, configPath: fixedPath)
5151
}

Sources/BuildServerIntegration/ExternalBuildServerAdapter.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,34 +205,34 @@ actor ExternalBuildServerAdapter {
205205
private static func getConfigPath(for workspaceFolder: URL? = nil, onlyConsiderRoot: Bool = false) -> URL? {
206206
var buildServerConfigLocations: [URL?] = []
207207
if let workspaceFolder = workspaceFolder {
208-
buildServerConfigLocations.append(workspaceFolder.appendingPathComponent(".bsp"))
208+
buildServerConfigLocations.append(workspaceFolder.appending(component: ".bsp"))
209209
}
210210

211211
if !onlyConsiderRoot {
212212
#if os(Windows)
213213
if let localAppData = ProcessInfo.processInfo.environment["LOCALAPPDATA"] {
214-
buildServerConfigLocations.append(URL(fileURLWithPath: localAppData).appendingPathComponent("bsp"))
214+
buildServerConfigLocations.append(URL(fileURLWithPath: localAppData).appending(component: "bsp"))
215215
}
216216
if let programData = ProcessInfo.processInfo.environment["PROGRAMDATA"] {
217-
buildServerConfigLocations.append(URL(fileURLWithPath: programData).appendingPathComponent("bsp"))
217+
buildServerConfigLocations.append(URL(fileURLWithPath: programData).appending(component: "bsp"))
218218
}
219219
#else
220220
if let xdgDataHome = ProcessInfo.processInfo.environment["XDG_DATA_HOME"] {
221-
buildServerConfigLocations.append(URL(fileURLWithPath: xdgDataHome).appendingPathComponent("bsp"))
221+
buildServerConfigLocations.append(URL(fileURLWithPath: xdgDataHome).appending(component: "bsp"))
222222
}
223223

224224
if let libraryUrl = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first {
225-
buildServerConfigLocations.append(libraryUrl.appendingPathComponent("bsp"))
225+
buildServerConfigLocations.append(libraryUrl.appending(component: "bsp"))
226226
}
227227

228228
if let xdgDataDirs = ProcessInfo.processInfo.environment["XDG_DATA_DIRS"] {
229229
buildServerConfigLocations += xdgDataDirs.split(separator: ":").map { xdgDataDir in
230-
URL(fileURLWithPath: String(xdgDataDir)).appendingPathComponent("bsp")
230+
URL(fileURLWithPath: String(xdgDataDir)).appending(component: "bsp")
231231
}
232232
}
233233

234234
if let libraryUrl = FileManager.default.urls(for: .applicationSupportDirectory, in: .systemDomainMask).first {
235-
buildServerConfigLocations.append(libraryUrl.appendingPathComponent("bsp"))
235+
buildServerConfigLocations.append(libraryUrl.appending(component: "bsp"))
236236
}
237237
#endif
238238
}
@@ -255,7 +255,7 @@ actor ExternalBuildServerAdapter {
255255

256256
// Pre Swift 6.1 SourceKit-LSP looked for `buildServer.json` in the project root. Maintain this search location for
257257
// compatibility even though it's not a standard BSP search location.
258-
if let buildServerPath = workspaceFolder?.appendingPathComponent("buildServer.json"),
258+
if let buildServerPath = workspaceFolder?.appending(component: "buildServer.json"),
259259
FileManager.default.isFile(at: buildServerPath)
260260
{
261261
return buildServerPath

Sources/BuildServerIntegration/FixedCompilationDatabaseBuildServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ package actor FixedCompilationDatabaseBuildServer: BuiltInBuildServer {
5656
}
5757

5858
package var indexDatabasePath: URL? {
59-
indexStorePath?.deletingLastPathComponent().appendingPathComponent("IndexDatabase")
59+
indexStorePath?.deletingLastPathComponent().appending(component: "IndexDatabase")
6060
}
6161

6262
package nonisolated var supportsPreparationAndOutputPaths: Bool { false }

Sources/BuildServerIntegration/JSONCompilationDatabaseBuildServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ package actor JSONCompilationDatabaseBuildServer: BuiltInBuildServer {
9393
}
9494

9595
package var indexDatabasePath: URL? {
96-
indexStorePath?.deletingLastPathComponent().appendingPathComponent("IndexDatabase")
96+
indexStorePath?.deletingLastPathComponent().appending(component: "IndexDatabase")
9797
}
9898

9999
package nonisolated var supportsPreparationAndOutputPaths: Bool { false }

Sources/BuildServerIntegration/SwiftPMBuildServer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
144144
}
145145

146146
static package func searchForConfig(in path: URL, options: SourceKitLSPOptions) -> BuildServerSpec? {
147-
let packagePath = path.appendingPathComponent("Package.swift")
147+
let packagePath = path.appending(component: "Package.swift")
148148
if (try? String(contentsOf: packagePath, encoding: .utf8))?.contains("PackageDescription") ?? false {
149149
return BuildServerSpec(kind: .swiftPM, projectRoot: path, configPath: packagePath)
150150
}
@@ -494,7 +494,7 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
494494
}
495495

496496
package var indexDatabasePath: URL? {
497-
return buildPath.appendingPathComponent("index").appendingPathComponent("db")
497+
return buildPath.appending(components: "index", "db")
498498
}
499499

500500
private func indexUnitOutputPath(forSwiftFile uri: DocumentURI) -> String {
@@ -583,7 +583,7 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
583583
)
584584
}
585585
let packageManifest = SourceItem(
586-
uri: DocumentURI(projectRoot.appendingPathComponent("Package.swift")),
586+
uri: DocumentURI(projectRoot.appending(component: "Package.swift")),
587587
kind: .file,
588588
generated: false
589589
)

Sources/CompletionScoringTestSupport/RepeatableRandomNumberGenerator.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ private let skTestSupportInputsDirectory: URL = {
129129
#if os(macOS)
130130
var resources =
131131
productsDirectory
132-
.appendingPathComponent("SourceKitLSP_CompletionScoringTestSupport.bundle")
133-
.appendingPathComponent("Contents")
134-
.appendingPathComponent("Resources")
132+
.appending(components: "SourceKitLSP_CompletionScoringTestSupport.bundle", "Contents", "Resources")
135133
if !FileManager.default.fileExists(at: resources) {
136134
// Xcode and command-line swiftpm differ about the path.
137135
resources.deleteLastPathComponent()
@@ -140,18 +138,18 @@ private let skTestSupportInputsDirectory: URL = {
140138
#else
141139
let resources =
142140
productsDirectory
143-
.appendingPathComponent("SourceKitLSP_CompletionScoringTestSupport.resources")
141+
.appending(component: "SourceKitLSP_CompletionScoringTestSupport.resources")
144142
#endif
145143
guard FileManager.default.fileExists(at: resources) else {
146144
fatalError("missing resources \(resources)")
147145
}
148-
return resources.appendingPathComponent("INPUTS", isDirectory: true).standardizedFileURL
146+
return resources.appending(component: "INPUTS", directoryHint: .isDirectory).standardizedFileURL
149147
}()
150148

151149
func loadTestResource(name: String, withExtension ext: String) throws -> Data {
152150
let file =
153151
skTestSupportInputsDirectory
154-
.appendingPathComponent("\(name).\(ext)")
152+
.appending(component: "\(name).\(ext)")
155153
return try Data(contentsOf: file)
156154
}
157155

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
124124
try await reduce(
125125
requestInfo: requestInfo,
126126
toolchain: toolchain,
127-
bundlePath: bundlePath.appendingPathComponent("sourcekitd-crash"),
127+
bundlePath: bundlePath.appending(component: "sourcekitd-crash"),
128128
progressUpdate: { (progress, message) in
129129
reportProgress(
130130
.reproducingSourcekitdCrash(progress: progress),
@@ -192,7 +192,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
192192
}
193193
)
194194

195-
let bundleDirectory = bundlePath.appendingPathComponent("swift-frontend-crash")
195+
let bundleDirectory = bundlePath.appending(component: "swift-frontend-crash")
196196
try makeReproducerBundle(for: reducedRequesInfo, toolchain: toolchain, bundlePath: bundleDirectory)
197197

198198
// If reduce didn't throw, we have found a reproducer. Stop.
@@ -218,7 +218,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
218218
private func addOsLog(toBundle bundlePath: URL) async throws {
219219
#if os(macOS)
220220
reportProgress(.collectingLogMessages(progress: 0), message: "Collecting log messages")
221-
let outputFileUrl = bundlePath.appendingPathComponent("log.txt")
221+
let outputFileUrl = bundlePath.appending(component: "log.txt")
222222
try FileManager.default.createFile(at: outputFileUrl, contents: nil)
223223
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
224224
let bytesCollected = AtomicInt32(initialValue: 0)
@@ -265,20 +265,19 @@ package struct DiagnoseCommand: AsyncParsableCommand {
265265
private func addNonDarwinLogs(toBundle bundlePath: URL) async throws {
266266
reportProgress(.collectingLogMessages(progress: 0), message: "Collecting log files")
267267

268-
let destinationDir = bundlePath.appendingPathComponent("logs")
268+
let destinationDir = bundlePath.appending(component: "logs")
269269
try FileManager.default.createDirectory(at: destinationDir, withIntermediateDirectories: true)
270270

271271
let logFileDirectoryURL = FileManager.default.homeDirectoryForCurrentUser
272-
.appendingPathComponent(".sourcekit-lsp")
273-
.appendingPathComponent("logs")
272+
.appending(components: ".sourcekit-lsp", "logs")
274273
let enumerator = FileManager.default.enumerator(at: logFileDirectoryURL, includingPropertiesForKeys: nil)
275274
while let fileUrl = enumerator?.nextObject() as? URL {
276275
guard fileUrl.lastPathComponent.hasPrefix("sourcekit-lsp") else {
277276
continue
278277
}
279278
try? FileManager.default.copyItem(
280279
at: fileUrl,
281-
to: destinationDir.appendingPathComponent(fileUrl.lastPathComponent)
280+
to: destinationDir.appending(component: fileUrl.lastPathComponent)
282281
)
283282
}
284283
}
@@ -294,7 +293,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
294293
#if os(macOS)
295294
reportProgress(.collectingCrashReports, message: "Collecting crash reports")
296295

297-
let destinationDir = bundlePath.appendingPathComponent("crashes")
296+
let destinationDir = bundlePath.appending(component: "crashes")
298297
try FileManager.default.createDirectory(at: destinationDir, withIntermediateDirectories: true)
299298

300299
let processesToIncludeCrashReportsOf = ["SourceKitService", "sourcekit-lsp", "swift-frontend"]
@@ -308,7 +307,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
308307
}
309308
try? FileManager.default.copyItem(
310309
at: fileUrl,
311-
to: destinationDir.appendingPathComponent(fileUrl.lastPathComponent)
310+
to: destinationDir.appending(component: fileUrl.lastPathComponent)
312311
)
313312
}
314313
}
@@ -317,7 +316,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
317316

318317
@MainActor
319318
private func addSwiftVersion(toBundle bundlePath: URL) async throws {
320-
let outputFileUrl = bundlePath.appendingPathComponent("swift-versions.txt")
319+
let outputFileUrl = bundlePath.appending(component: "swift-versions.txt")
321320
try FileManager.default.createFile(at: outputFileUrl, contents: nil)
322321
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
323322

@@ -388,8 +387,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
388387
URL(fileURLWithPath: bundleOutputPath)
389388
} else {
390389
FileManager.default.temporaryDirectory
391-
.appendingPathComponent("sourcekit-lsp-diagnose")
392-
.appendingPathComponent("sourcekit-lsp-diagnose-\(date)")
390+
.appending(components: "sourcekit-lsp-diagnose", "sourcekit-lsp-diagnose-\(date)")
393391
}
394392
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)
395393

0 commit comments

Comments
 (0)