Skip to content

Commit 7184d52

Browse files
authored
fix: delay showing the progress bar. (#19)
This commit delays showing the progress bar until two seconds of analysis have passed. For small analysis jobs, like single files, this will prevent a progress bar from showing and then immediately completing.
1 parent b266a4a commit 7184d52

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
* Implemented the `check` command as a full static analysis ([#17](https://github.com/stjude-rust-labs/sprocket/pull/17)).
1313

14+
### Fixed
15+
16+
* Fixed the progress bar from showing up for short analysis jobs; it now is
17+
delayed by two seconds ([#19](https://github.com/stjude-rust-labs/sprocket/pull/19)).
18+
1419
## 0.6.0 - 08-22-2024
1520

1621
### Added

src/commands/check.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::borrow::Cow;
44
use std::path::PathBuf;
5+
use std::time::Duration;
56

67
use anyhow::bail;
78
use anyhow::Context;
@@ -22,6 +23,9 @@ use wdl::ast::SyntaxNode;
2223
use wdl::ast::Validator;
2324
use wdl::lint::LintVisitor;
2425

26+
/// The delay in showing the progress bar.
27+
const PROGRESS_BAR_DELAY: Duration = Duration::from_secs(2);
28+
2529
/// The diagnostic mode to use for reporting diagnostics.
2630
#[derive(Clone, Debug, Default, ValueEnum)]
2731
pub enum Mode {
@@ -113,10 +117,15 @@ pub async fn check(args: CheckArgs) -> anyhow::Result<()> {
113117
let except_rules = args.common.except;
114118
let analyzer = Analyzer::new_with_validator(
115119
move |bar: ProgressBar, kind, completed, total| async move {
116-
if completed == 0 {
120+
if bar.elapsed() < PROGRESS_BAR_DELAY {
121+
return;
122+
}
123+
124+
if completed == 0 || bar.length() == Some(0) {
117125
bar.set_length(total.try_into().unwrap());
118126
bar.set_message(format!("{kind}"));
119127
}
128+
120129
bar.set_position(completed.try_into().unwrap());
121130
},
122131
move || {
@@ -137,13 +146,14 @@ pub async fn check(args: CheckArgs) -> anyhow::Result<()> {
137146
},
138147
);
139148

149+
analyzer.add_documents(args.common.paths).await?;
150+
140151
let bar = ProgressBar::new(0);
141152
bar.set_style(
142153
ProgressStyle::with_template("[{elapsed_precise}] {bar:40.cyan/blue} {msg} {pos}/{len}")
143154
.unwrap(),
144155
);
145156

146-
analyzer.add_documents(args.common.paths).await?;
147157
let results = analyzer
148158
.analyze(bar.clone())
149159
.await

0 commit comments

Comments
 (0)