diff --git a/Sources/Diagnose/CMakeLists.txt b/Sources/Diagnose/CMakeLists.txt index b93da89cd..32caa5515 100644 --- a/Sources/Diagnose/CMakeLists.txt +++ b/Sources/Diagnose/CMakeLists.txt @@ -12,8 +12,8 @@ add_library(Diagnose STATIC ReductionError.swift ReproducerBundle.swift RequestInfo.swift + RunSourcekitdRequestCommand.swift SourceKitD+RunWithYaml.swift - SourcekitdRequestCommand.swift SourceKitDRequestExecutor.swift SourceReducer.swift StderrStreamConcurrencySafe.swift diff --git a/Sources/Diagnose/SourcekitdRequestCommand.swift b/Sources/Diagnose/RunSourcekitdRequestCommand.swift similarity index 85% rename from Sources/Diagnose/SourcekitdRequestCommand.swift rename to Sources/Diagnose/RunSourcekitdRequestCommand.swift index ba4e0686f..771fc4777 100644 --- a/Sources/Diagnose/SourcekitdRequestCommand.swift +++ b/Sources/Diagnose/RunSourcekitdRequestCommand.swift @@ -12,12 +12,13 @@ import ArgumentParser import Foundation +import SKCore import SKSupport import SourceKitD import struct TSCBasic.AbsolutePath -public struct SourceKitdRequestCommand: AsyncParsableCommand { +public struct RunSourceKitdRequestCommand: AsyncParsableCommand { public static let configuration = CommandConfiguration( commandName: "run-sourcekitd-request", abstract: "Run a sourcekitd request and print its result", @@ -28,7 +29,7 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand { name: .customLong("sourcekitd"), help: "Path to sourcekitd.framework/sourcekitd" ) - var sourcekitdPath: String + var sourcekitdPath: String? @Option( name: .customLong("request-file"), @@ -44,6 +45,16 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand { public func run() async throws { var requestString = try String(contentsOf: URL(fileURLWithPath: sourcekitdRequestPath)) + let installPath = try AbsolutePath(validating: Bundle.main.bundlePath) + let sourcekitdPath = + if let sourcekitdPath { + sourcekitdPath + } else if let path = await ToolchainRegistry(installPath: installPath).default?.sourcekitd?.pathString { + path + } else { + print("Did not find sourcekitd in the toolchain. Specify path to sourcekitd manually by passing --sourcekitd") + throw ExitCode(1) + } let sourcekitd = try await DynamicallyLoadedSourceKitD.getOrCreate( dylibPath: try! AbsolutePath(validating: sourcekitdPath) ) diff --git a/Sources/sourcekit-lsp/SourceKitLSP.swift b/Sources/sourcekit-lsp/SourceKitLSP.swift index b8942db77..0cece17c0 100644 --- a/Sources/sourcekit-lsp/SourceKitLSP.swift +++ b/Sources/sourcekit-lsp/SourceKitLSP.swift @@ -108,7 +108,7 @@ struct SourceKitLSP: AsyncParsableCommand { IndexCommand.self, ReduceCommand.self, ReduceFrontendCommand.self, - SourceKitdRequestCommand.self, + RunSourceKitdRequestCommand.self, ] )