1212
1313import ArgumentParser
1414import Foundation
15+ import SKCore
1516import SKSupport
1617import SourceKitD
1718
1819import struct TSCBasic. AbsolutePath
1920
20- public struct SourceKitdRequestCommand : AsyncParsableCommand {
21+ public struct RunSourceKitdRequestCommand : AsyncParsableCommand {
2122 public static let configuration = CommandConfiguration (
2223 commandName: " run-sourcekitd-request " ,
2324 abstract: " Run a sourcekitd request and print its result " ,
@@ -28,7 +29,7 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand {
2829 name: . customLong( " sourcekitd " ) ,
2930 help: " Path to sourcekitd.framework/sourcekitd "
3031 )
31- var sourcekitdPath : String
32+ var sourcekitdPath : String ?
3233
3334 @Option (
3435 name: . customLong( " request-file " ) ,
@@ -44,6 +45,16 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand {
4445 public func run( ) async throws {
4546 var requestString = try String ( contentsOf: URL ( fileURLWithPath: sourcekitdRequestPath) )
4647
48+ let installPath = try AbsolutePath ( validating: Bundle . main. bundlePath)
49+ let sourcekitdPath =
50+ if let sourcekitdPath {
51+ sourcekitdPath
52+ } else if let path = await ToolchainRegistry ( installPath: installPath) . default? . sourcekitd? . pathString {
53+ path
54+ } else {
55+ print ( " Did not find sourcekitd in the toolchain. Specify path to sourcekitd manually by passing --sourcekitd " )
56+ throw ExitCode ( 1 )
57+ }
4758 let sourcekitd = try await DynamicallyLoadedSourceKitD . getOrCreate (
4859 dylibPath: try ! AbsolutePath ( validating: sourcekitdPath)
4960 )
0 commit comments