Skip to content

Commit 8322b9f

Browse files
authored
Merge pull request #1133 from ahoppen/ahoppen/diagnose-components
Allow specification of components that should be included in the diagnose bundle
2 parents 4e3f201 + e755331 commit 8322b9f

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ import class TSCUtility.PercentProgressAnimation
2525
/// to be a `AsyncParsableCommand`.
2626
private var progressBar: PercentProgressAnimation? = nil
2727

28+
/// A component of the diagnostic bundle that's collected in independent stages.
29+
fileprivate enum BundleComponent: String, CaseIterable, ExpressibleByArgument {
30+
case crashReports
31+
case logs
32+
case swiftVersions
33+
case sourcekitdCrashes
34+
}
35+
2836
public struct DiagnoseCommand: AsyncParsableCommand {
2937
public static var configuration: CommandConfiguration = CommandConfiguration(
3038
commandName: "diagnose",
@@ -59,6 +67,16 @@ public struct DiagnoseCommand: AsyncParsableCommand {
5967
var predicate: String?
6068
#endif
6169

70+
@Option(
71+
parsing: .upToNextOption,
72+
help: """
73+
A space separated list of components to include in the diagnostic bundle. Includes all components by default.
74+
75+
Possible options are: \(BundleComponent.allCases.map(\.rawValue).joined(separator: ", "))
76+
"""
77+
)
78+
private var components: [BundleComponent] = BundleComponent.allCases
79+
6280
var toolchainRegistry: ToolchainRegistry {
6381
get throws {
6482
let installPath = try AbsolutePath(validating: Bundle.main.bundlePath)
@@ -225,7 +243,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
225243
public func run() async throws {
226244
print(
227245
"""
228-
sourcekit-lsp diagnose collects information that helps the developers of sourcekit-lsp diagnose and fix issues.
246+
sourcekit-lsp diagnose collects information that helps the developers of sourcekit-lsp diagnose and fix issues.
229247
This information contains:
230248
- Crash logs from SourceKit
231249
- Log messages emitted by SourceKit
@@ -244,10 +262,18 @@ public struct DiagnoseCommand: AsyncParsableCommand {
244262
.appendingPathComponent("sourcekitd-reproducer-\(date)")
245263
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)
246264

247-
await orPrintError { try addCrashLogs(toBundle: bundlePath) }
248-
await orPrintError { try await addOsLog(toBundle: bundlePath) }
249-
await orPrintError { try await addSwiftVersion(toBundle: bundlePath) }
250-
await orPrintError { try await addSourcekitdCrashReproducer(toBundle: bundlePath) }
265+
if components.isEmpty || components.contains(.crashReports) {
266+
await orPrintError { try addCrashLogs(toBundle: bundlePath) }
267+
}
268+
if components.isEmpty || components.contains(.logs) {
269+
await orPrintError { try await addOsLog(toBundle: bundlePath) }
270+
}
271+
if components.isEmpty || components.contains(.swiftVersions) {
272+
await orPrintError { try await addSwiftVersion(toBundle: bundlePath) }
273+
}
274+
if components.isEmpty || components.contains(.sourcekitdCrashes) {
275+
await orPrintError { try await addSourcekitdCrashReproducer(toBundle: bundlePath) }
276+
}
251277

252278
progressBar?.complete(success: true)
253279

0 commit comments

Comments
 (0)