Skip to content

Use default toolchain in sourcekit-lsp run-sourcekitd-request if no sourcekitd is specified #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 1 addition & 1 deletion Sources/Diagnose/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
Expand All @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/sourcekit-lsp/SourceKitLSP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct SourceKitLSP: AsyncParsableCommand {
IndexCommand.self,
ReduceCommand.self,
ReduceFrontendCommand.self,
SourceKitdRequestCommand.self,
RunSourceKitdRequestCommand.self,
]
)

Expand Down