@@ -25,6 +25,14 @@ import class TSCUtility.PercentProgressAnimation
25
25
/// to be a `AsyncParsableCommand`.
26
26
private var progressBar : PercentProgressAnimation ? = nil
27
27
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
+
28
36
public struct DiagnoseCommand : AsyncParsableCommand {
29
37
public static var configuration : CommandConfiguration = CommandConfiguration (
30
38
commandName: " diagnose " ,
@@ -59,6 +67,16 @@ public struct DiagnoseCommand: AsyncParsableCommand {
59
67
var predicate : String ?
60
68
#endif
61
69
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
+
62
80
var toolchainRegistry : ToolchainRegistry {
63
81
get throws {
64
82
let installPath = try AbsolutePath ( validating: Bundle . main. bundlePath)
@@ -225,7 +243,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
225
243
public func run( ) async throws {
226
244
print (
227
245
"""
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.
229
247
This information contains:
230
248
- Crash logs from SourceKit
231
249
- Log messages emitted by SourceKit
@@ -244,10 +262,18 @@ public struct DiagnoseCommand: AsyncParsableCommand {
244
262
. appendingPathComponent ( " sourcekitd-reproducer- \( date) " )
245
263
try FileManager . default. createDirectory ( at: bundlePath, withIntermediateDirectories: true )
246
264
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
+ }
251
277
252
278
progressBar? . complete ( success: true )
253
279
0 commit comments