Skip to content

Commit 6425a8e

Browse files
committed
Only report log collection progress in sourcekit-lsp diagnose if we’ve made meaningful progress
Especially when we didn’t have a redrawing progress indicator, we would spam the output with out making progress that was visible to the user because the overall progress just shows a percentage without any decimal digits. To fix this, only report progress when we’ve made at least 1% of progress in log collection.
1 parent cec73bb commit 6425a8e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import class TSCUtility.PercentProgressAnimation
2525
@MainActor
2626
private var progressBar: PercentProgressAnimation? = nil
2727

28+
/// The last progress that was reported on the progress bar. This ensures that when the progress indicator uses the
29+
/// `MultiLinePercentProgressAnimation` (eg. because stderr is redirected to a file) we don't emit status updates
30+
/// without making any real progress.
31+
@MainActor
32+
private var lastProgress: (Int, String)? = nil
33+
2834
/// A component of the diagnostic bundle that's collected in independent stages.
2935
fileprivate enum BundleComponent: String, CaseIterable, ExpressibleByArgument {
3036
case crashReports = "crash-reports"
@@ -292,7 +298,11 @@ public struct DiagnoseCommand: AsyncParsableCommand {
292298

293299
@MainActor
294300
private func reportProgress(_ state: DiagnoseProgressState, message: String) {
295-
progressBar?.update(step: Int(state.progress * 100), total: 100, text: message)
301+
let progress: (step: Int, message: String) = (Int(state.progress * 100), message)
302+
if lastProgress == nil || progress != lastProgress! {
303+
progressBar?.update(step: Int(state.progress * 100), total: 100, text: message)
304+
lastProgress = progress
305+
}
296306
}
297307

298308
@MainActor

0 commit comments

Comments
 (0)