12
12
13
13
import ArgumentParser
14
14
import Foundation
15
+ import SKCore
15
16
import SKSupport
16
17
import SourceKitD
17
18
18
19
import struct TSCBasic. AbsolutePath
19
20
20
- public struct SourceKitdRequestCommand : AsyncParsableCommand {
21
+ public struct RunSourceKitdRequestCommand : AsyncParsableCommand {
21
22
public static let configuration = CommandConfiguration (
22
23
commandName: " run-sourcekitd-request " ,
23
24
abstract: " Run a sourcekitd request and print its result " ,
@@ -28,7 +29,7 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand {
28
29
name: . customLong( " sourcekitd " ) ,
29
30
help: " Path to sourcekitd.framework/sourcekitd "
30
31
)
31
- var sourcekitdPath : String
32
+ var sourcekitdPath : String ?
32
33
33
34
@Option (
34
35
name: . customLong( " request-file " ) ,
@@ -44,6 +45,16 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand {
44
45
public func run( ) async throws {
45
46
var requestString = try String ( contentsOf: URL ( fileURLWithPath: sourcekitdRequestPath) )
46
47
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
+ }
47
58
let sourcekitd = try await DynamicallyLoadedSourceKitD . getOrCreate (
48
59
dylibPath: try ! AbsolutePath ( validating: sourcekitdPath)
49
60
)
0 commit comments