Skip to content

Commit

Permalink
fix: delay showing the progress bar. (#19)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
peterhuene authored Sep 16, 2024
1 parent b266a4a commit 7184d52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

### Fixed

* Fixed the progress bar from showing up for short analysis jobs; it now is
delayed by two seconds ([#19](https://github.com/stjude-rust-labs/sprocket/pull/19)).

## 0.6.0 - 08-22-2024

### Added
Expand Down
14 changes: 12 additions & 2 deletions src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::borrow::Cow;
use std::path::PathBuf;
use std::time::Duration;

use anyhow::bail;
use anyhow::Context;
Expand All @@ -22,6 +23,9 @@ use wdl::ast::SyntaxNode;
use wdl::ast::Validator;
use wdl::lint::LintVisitor;

/// The delay in showing the progress bar.
const PROGRESS_BAR_DELAY: Duration = Duration::from_secs(2);

/// The diagnostic mode to use for reporting diagnostics.
#[derive(Clone, Debug, Default, ValueEnum)]
pub enum Mode {
Expand Down Expand Up @@ -113,10 +117,15 @@ pub async fn check(args: CheckArgs) -> anyhow::Result<()> {
let except_rules = args.common.except;
let analyzer = Analyzer::new_with_validator(
move |bar: ProgressBar, kind, completed, total| async move {
if completed == 0 {
if bar.elapsed() < PROGRESS_BAR_DELAY {
return;
}

if completed == 0 || bar.length() == Some(0) {
bar.set_length(total.try_into().unwrap());
bar.set_message(format!("{kind}"));
}

bar.set_position(completed.try_into().unwrap());
},
move || {
Expand All @@ -137,13 +146,14 @@ pub async fn check(args: CheckArgs) -> anyhow::Result<()> {
},
);

analyzer.add_documents(args.common.paths).await?;

let bar = ProgressBar::new(0);
bar.set_style(
ProgressStyle::with_template("[{elapsed_precise}] {bar:40.cyan/blue} {msg} {pos}/{len}")
.unwrap(),
);

analyzer.add_documents(args.common.paths).await?;
let results = analyzer
.analyze(bar.clone())
.await
Expand Down

0 comments on commit 7184d52

Please sign in to comment.