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
7 changes: 4 additions & 3 deletions SourceKitLSPDevUtils/Package.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// swift-tools-version: 6.0
// swift-tools-version: 6.2

import Foundation
import PackageDescription

let package = Package(
name: "SourceKitLSPDevUtils",
platforms: [.macOS(.v10_15)],
platforms: [.macOS(.v14)],
products: [
.executable(name: "sourcekit-lsp-dev-utils", targets: ["SourceKitLSPDevUtils"])
],
Expand All @@ -24,7 +24,8 @@ let package = Package(
.product(name: "SwiftParser", package: "swift-syntax"),
]
),
]
],
swiftLanguageModes: [.v6]
)

let dependencies: [(url: String, path: String, fromVersion: Version)] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ package struct ConfigSchemaGen {
.deletingLastPathComponent()
private static let sourceDir =
projectRoot
.appendingPathComponent("Sources")
.appendingPathComponent("SKOptions")
.appending(components: "Sources", "SKOptions")
private static let configSchemaJSONPath =
projectRoot
.appendingPathComponent("config.schema.json")
.appending(component: "config.schema.json")
private static let configSchemaDocPath =
projectRoot
.appendingPathComponent("Documentation")
.appendingPathComponent("Configuration File.md")
.appending(components: "Documentation", "Configuration File.md")

/// Generates and writes the JSON schema and documentation for the SourceKit-LSP configuration file format.
package static func generate() throws {
Expand Down
4 changes: 2 additions & 2 deletions Sources/BuildServerIntegration/CompilationDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ package struct CompilationDatabaseCompileCommand: Equatable, Codable {
if filename.isAbsolutePath || !directory.isAbsolutePath {
return DocumentURI(filePath: filename, isDirectory: false)
} else {
return DocumentURI(URL(fileURLWithPath: directory).appendingPathComponent(filename, isDirectory: false))
return DocumentURI(URL(fileURLWithPath: directory).appending(component: filename, directoryHint: .notDirectory))
}
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ package struct JSONCompilationDatabase: Equatable, Codable {
///
/// - Returns: `nil` if `compile_commands.json` was not found
package init(directory: URL) throws {
let path = directory.appendingPathComponent(JSONCompilationDatabaseBuildServer.dbName)
let path = directory.appending(component: JSONCompilationDatabaseBuildServer.dbName)
try self.init(file: path)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/BuildServerIntegration/DetermineBuildServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ private func searchForCompilationDatabaseConfig(
.compactMap { searchPath in
let path = workspaceFolder.appending(searchPath)

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

let fixedPath = path.appendingPathComponent(FixedCompilationDatabaseBuildServer.dbName)
let fixedPath = path.appending(component: FixedCompilationDatabaseBuildServer.dbName)
if FileManager.default.isFile(at: fixedPath) {
return BuildServerSpec(kind: .fixedCompilationDatabase, projectRoot: workspaceFolder, configPath: fixedPath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,34 +205,34 @@ actor ExternalBuildServerAdapter {
private static func getConfigPath(for workspaceFolder: URL? = nil, onlyConsiderRoot: Bool = false) -> URL? {
var buildServerConfigLocations: [URL?] = []
if let workspaceFolder = workspaceFolder {
buildServerConfigLocations.append(workspaceFolder.appendingPathComponent(".bsp"))
buildServerConfigLocations.append(workspaceFolder.appending(component: ".bsp"))
}

if !onlyConsiderRoot {
#if os(Windows)
if let localAppData = ProcessInfo.processInfo.environment["LOCALAPPDATA"] {
buildServerConfigLocations.append(URL(fileURLWithPath: localAppData).appendingPathComponent("bsp"))
buildServerConfigLocations.append(URL(fileURLWithPath: localAppData).appending(component: "bsp"))
}
if let programData = ProcessInfo.processInfo.environment["PROGRAMDATA"] {
buildServerConfigLocations.append(URL(fileURLWithPath: programData).appendingPathComponent("bsp"))
buildServerConfigLocations.append(URL(fileURLWithPath: programData).appending(component: "bsp"))
}
#else
if let xdgDataHome = ProcessInfo.processInfo.environment["XDG_DATA_HOME"] {
buildServerConfigLocations.append(URL(fileURLWithPath: xdgDataHome).appendingPathComponent("bsp"))
buildServerConfigLocations.append(URL(fileURLWithPath: xdgDataHome).appending(component: "bsp"))
}

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

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

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

// Pre Swift 6.1 SourceKit-LSP looked for `buildServer.json` in the project root. Maintain this search location for
// compatibility even though it's not a standard BSP search location.
if let buildServerPath = workspaceFolder?.appendingPathComponent("buildServer.json"),
if let buildServerPath = workspaceFolder?.appending(component: "buildServer.json"),
FileManager.default.isFile(at: buildServerPath)
{
return buildServerPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ package actor FixedCompilationDatabaseBuildServer: BuiltInBuildServer {
}

package var indexDatabasePath: URL? {
indexStorePath?.deletingLastPathComponent().appendingPathComponent("IndexDatabase")
indexStorePath?.deletingLastPathComponent().appending(component: "IndexDatabase")
}

package nonisolated var supportsPreparationAndOutputPaths: Bool { false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ package actor JSONCompilationDatabaseBuildServer: BuiltInBuildServer {
}

package var indexDatabasePath: URL? {
indexStorePath?.deletingLastPathComponent().appendingPathComponent("IndexDatabase")
indexStorePath?.deletingLastPathComponent().appending(component: "IndexDatabase")
}

package nonisolated var supportsPreparationAndOutputPaths: Bool { false }
Expand Down
6 changes: 3 additions & 3 deletions Sources/BuildServerIntegration/SwiftPMBuildServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
}

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

package var indexDatabasePath: URL? {
return buildPath.appendingPathComponent("index").appendingPathComponent("db")
return buildPath.appending(components: "index", "db")
}

private func indexUnitOutputPath(forSwiftFile uri: DocumentURI) -> String {
Expand Down Expand Up @@ -583,7 +583,7 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
)
}
let packageManifest = SourceItem(
uri: DocumentURI(projectRoot.appendingPathComponent("Package.swift")),
uri: DocumentURI(projectRoot.appending(component: "Package.swift")),
kind: .file,
generated: false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ private let skTestSupportInputsDirectory: URL = {
#if os(macOS)
var resources =
productsDirectory
.appendingPathComponent("SourceKitLSP_CompletionScoringTestSupport.bundle")
.appendingPathComponent("Contents")
.appendingPathComponent("Resources")
.appending(components: "SourceKitLSP_CompletionScoringTestSupport.bundle", "Contents", "Resources")
if !FileManager.default.fileExists(at: resources) {
// Xcode and command-line swiftpm differ about the path.
resources.deleteLastPathComponent()
Expand All @@ -140,18 +138,18 @@ private let skTestSupportInputsDirectory: URL = {
#else
let resources =
productsDirectory
.appendingPathComponent("SourceKitLSP_CompletionScoringTestSupport.resources")
.appending(component: "SourceKitLSP_CompletionScoringTestSupport.resources")
#endif
guard FileManager.default.fileExists(at: resources) else {
fatalError("missing resources \(resources)")
}
return resources.appendingPathComponent("INPUTS", isDirectory: true).standardizedFileURL
return resources.appending(component: "INPUTS", directoryHint: .isDirectory).standardizedFileURL
}()

func loadTestResource(name: String, withExtension ext: String) throws -> Data {
let file =
skTestSupportInputsDirectory
.appendingPathComponent("\(name).\(ext)")
.appending(component: "\(name).\(ext)")
return try Data(contentsOf: file)
}

Expand Down
22 changes: 10 additions & 12 deletions Sources/Diagnose/DiagnoseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
try await reduce(
requestInfo: requestInfo,
toolchain: toolchain,
bundlePath: bundlePath.appendingPathComponent("sourcekitd-crash"),
bundlePath: bundlePath.appending(component: "sourcekitd-crash"),
progressUpdate: { (progress, message) in
reportProgress(
.reproducingSourcekitdCrash(progress: progress),
Expand Down Expand Up @@ -192,7 +192,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
}
)

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

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

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

let logFileDirectoryURL = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent(".sourcekit-lsp")
.appendingPathComponent("logs")
.appending(components: ".sourcekit-lsp", "logs")
let enumerator = FileManager.default.enumerator(at: logFileDirectoryURL, includingPropertiesForKeys: nil)
while let fileUrl = enumerator?.nextObject() as? URL {
guard fileUrl.lastPathComponent.hasPrefix("sourcekit-lsp") else {
continue
}
try? FileManager.default.copyItem(
at: fileUrl,
to: destinationDir.appendingPathComponent(fileUrl.lastPathComponent)
to: destinationDir.appending(component: fileUrl.lastPathComponent)
)
}
}
Expand All @@ -294,7 +293,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
#if os(macOS)
reportProgress(.collectingCrashReports, message: "Collecting crash reports")

let destinationDir = bundlePath.appendingPathComponent("crashes")
let destinationDir = bundlePath.appending(component: "crashes")
try FileManager.default.createDirectory(at: destinationDir, withIntermediateDirectories: true)

let processesToIncludeCrashReportsOf = ["SourceKitService", "sourcekit-lsp", "swift-frontend"]
Expand All @@ -308,7 +307,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
}
try? FileManager.default.copyItem(
at: fileUrl,
to: destinationDir.appendingPathComponent(fileUrl.lastPathComponent)
to: destinationDir.appending(component: fileUrl.lastPathComponent)
)
}
}
Expand All @@ -317,7 +316,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {

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

Expand Down Expand Up @@ -388,8 +387,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
URL(fileURLWithPath: bundleOutputPath)
} else {
FileManager.default.temporaryDirectory
.appendingPathComponent("sourcekit-lsp-diagnose")
.appendingPathComponent("sourcekit-lsp-diagnose-\(date)")
.appending(components: "sourcekit-lsp-diagnose", "sourcekit-lsp-diagnose-\(date)")
}
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Diagnose/ReduceCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ package struct ReduceCommand: AsyncParsableCommand {

progressBar.complete(success: true)

let reducedSourceFile = FileManager.default.temporaryDirectory.appendingPathComponent("reduced.swift")
let reducedSourceFile = FileManager.default.temporaryDirectory.appending(component: "reduced.swift")
try reduceRequestInfo.fileContents.write(to: reducedSourceFile, atomically: true, encoding: .utf8)

print("Reduced Request:")
Expand Down
10 changes: 5 additions & 5 deletions Sources/Diagnose/ReproducerBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ import struct TSCBasic.AbsolutePath
func makeReproducerBundle(for requestInfo: RequestInfo, toolchain: Toolchain, bundlePath: URL) throws {
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)
try requestInfo.fileContents.write(
to: bundlePath.appendingPathComponent("input.swift"),
to: bundlePath.appending(component: "input.swift"),
atomically: true,
encoding: .utf8
)
try toolchain.path.realpath.filePath
.write(
to: bundlePath.appendingPathComponent("toolchain.txt"),
to: bundlePath.appending(component: "toolchain.txt"),
atomically: true,
encoding: .utf8
)
if requestInfo.requestTemplate == RequestInfo.fakeRequestTemplateForFrontendIssues {
let command =
"swift-frontend \\\n"
+ requestInfo.compilerArgs.replacing(["$FILE"], with: ["./input.swift"]).joined(separator: " \\\n")
try command.write(to: bundlePath.appendingPathComponent("command.sh"), atomically: true, encoding: .utf8)
try command.write(to: bundlePath.appending(component: "command.sh"), atomically: true, encoding: .utf8)
} else {
let requests = try requestInfo.requests(for: bundlePath.appendingPathComponent("input.swift"))
let requests = try requestInfo.requests(for: bundlePath.appending(component: "input.swift"))
for (index, request) in requests.enumerated() {
try request.write(
to: bundlePath.appendingPathComponent("request-\(index).yml"),
to: bundlePath.appending(component: "request-\(index).yml"),
atomically: true,
encoding: .utf8
)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Diagnose/SourceKitDRequestExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ package class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {

/// The file to which we write the reduce source file.
private var temporarySourceFile: URL {
temporaryDirectory.appendingPathComponent("reduce.swift")
temporaryDirectory.appending(component: "reduce.swift")
}

/// If this predicate evaluates to true on the sourcekitd response, the request is
Expand All @@ -86,7 +86,7 @@ package class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {
self.pluginPaths = pluginPaths
self.swiftFrontend = swiftFrontend
self.reproducerPredicate = reproducerPredicate
temporaryDirectory = FileManager.default.temporaryDirectory.appendingPathComponent("sourcekitd-execute-\(UUID())")
temporaryDirectory = FileManager.default.temporaryDirectory.appending(component: "sourcekitd-execute-\(UUID())")
try? FileManager.default.createDirectory(at: temporaryDirectory, withIntermediateDirectories: true)
}

Expand Down Expand Up @@ -171,7 +171,7 @@ package class OutOfProcessSourceKitRequestExecutor: SourceKitRequestExecutor {
try request.fileContents.write(to: temporarySourceFile, atomically: true, encoding: .utf8)
let requestStrings = try request.requests(for: temporarySourceFile)
for (index, requestString) in requestStrings.enumerated() {
let temporaryRequestFile = temporaryDirectory.appendingPathComponent("request-\(index).yml")
let temporaryRequestFile = temporaryDirectory.appending(component: "request-\(index).yml")
try requestString.write(
to: temporaryRequestFile,
atomically: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Diagnose/Toolchain+SwiftFrontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ extension Toolchain {
///
/// - Note: Not discovered as part of the toolchain because `swift-frontend` is only needed in the diagnose commands.
package var swiftFrontend: URL? {
return swift?.deletingLastPathComponent().appendingPathComponent("swift-frontend")
return swift?.deletingLastPathComponent().appending(component: "swift-frontend")
}
}
5 changes: 3 additions & 2 deletions Sources/SKLogging/SetGlobalLogFileHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func getOrCreateLogFileHandle(logDirectory: URL, logRotateCount: Int) -> FileHan
}

// Name must match the regex in `cleanOldLogFiles` and the prefix in `DiagnoseCommand.addNonDarwinLogs`.
let logFileUrl = logDirectory.appendingPathComponent(
"sourcekit-lsp-\(ProcessInfo.processInfo.processIdentifier).\(logRotateIndex % logRotateCount).log"
let logFileUrl = logDirectory.appending(
component:
"sourcekit-lsp-\(ProcessInfo.processInfo.processIdentifier).\(logRotateIndex % logRotateCount).log"
)

do {
Expand Down
5 changes: 2 additions & 3 deletions Sources/SKOptions/SourceKitLSPOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,7 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
base: base,
override: SourceKitLSPOptions(
path: workspaceFolder.fileURL?
.appendingPathComponent(".sourcekit-lsp")
.appendingPathComponent("config.json")
.appending(components: ".sourcekit-lsp", "config.json")
)
)
}
Expand All @@ -575,7 +574,7 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
return URL(fileURLWithPath: generatedFilesPath)
}

return URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("sourcekit-lsp")
return URL(fileURLWithPath: NSTemporaryDirectory()).appending(component: "sourcekit-lsp")
}

public func hasExperimentalFeature(_ feature: ExperimentalFeature) -> Bool {
Expand Down
Loading