Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delay showing the progress bar. #19

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading