Skip to content

Commit 899d857

Browse files
authored
Merge pull request #1375 from ahoppen/infer-sourcekitd-in-run-sourcekitd-request
Use default toolchain in `sourcekit-lsp run-sourcekitd-request` if no sourcekitd is specified
2 parents 56f76c3 + 6e952f9 commit 899d857

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Sources/Diagnose/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ add_library(Diagnose STATIC
1212
ReductionError.swift
1313
ReproducerBundle.swift
1414
RequestInfo.swift
15+
RunSourcekitdRequestCommand.swift
1516
SourceKitD+RunWithYaml.swift
16-
SourcekitdRequestCommand.swift
1717
SourceKitDRequestExecutor.swift
1818
SourceReducer.swift
1919
StderrStreamConcurrencySafe.swift

Sources/Diagnose/SourcekitdRequestCommand.swift renamed to Sources/Diagnose/RunSourcekitdRequestCommand.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
import ArgumentParser
1414
import Foundation
15+
import SKCore
1516
import SKSupport
1617
import SourceKitD
1718

1819
import 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
)

Sources/sourcekit-lsp/SourceKitLSP.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct SourceKitLSP: AsyncParsableCommand {
108108
IndexCommand.self,
109109
ReduceCommand.self,
110110
ReduceFrontendCommand.self,
111-
SourceKitdRequestCommand.self,
111+
RunSourceKitdRequestCommand.self,
112112
]
113113
)
114114

0 commit comments

Comments
 (0)