Avoid initializing progress bars early (#18049)

## Summary

Resolves https://github.com/astral-sh/ty/issues/324.
This commit is contained in:
Ibraheem Ahmed 2025-05-12 15:07:55 -04:00 committed by GitHub
parent bdccb37b4a
commit 550b8be552
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 53 additions and 39 deletions

View file

@ -1,7 +1,7 @@
use std::panic::RefUnwindSafe;
use std::panic::{AssertUnwindSafe, RefUnwindSafe};
use std::sync::Arc;
use crate::DEFAULT_LINT_REGISTRY;
use crate::{DummyReporter, DEFAULT_LINT_REGISTRY};
use crate::{Project, ProjectMetadata, Reporter};
use ruff_db::diagnostic::Diagnostic;
use ruff_db::files::{File, Files};
@ -68,7 +68,18 @@ impl ProjectDatabase {
}
/// Checks all open files in the project and its dependencies.
pub fn check(&self, reporter: &impl Reporter) -> Result<Vec<Diagnostic>, Cancelled> {
pub fn check(&self) -> Result<Vec<Diagnostic>, Cancelled> {
let mut reporter = DummyReporter;
let reporter = AssertUnwindSafe(&mut reporter as &mut dyn Reporter);
self.with_db(|db| db.project().check(db, reporter))
}
/// Checks all open files in the project and its dependencies, using the given reporter.
pub fn check_with_reporter(
&self,
reporter: &mut dyn Reporter,
) -> Result<Vec<Diagnostic>, Cancelled> {
let reporter = AssertUnwindSafe(reporter);
self.with_db(|db| db.project().check(db, reporter))
}

View file

@ -18,7 +18,7 @@ use rustc_hash::FxHashSet;
use salsa::Durability;
use salsa::Setter;
use std::backtrace::BacktraceStatus;
use std::panic::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
use std::panic::{AssertUnwindSafe, UnwindSafe};
use std::sync::Arc;
use thiserror::Error;
use tracing::error;
@ -107,9 +107,9 @@ pub struct Project {
}
/// A progress reporter.
pub trait Reporter: Default + Send + Sync + RefUnwindSafe + 'static {
pub trait Reporter: Send + Sync {
/// Initialize the reporter with the number of files.
fn set_files(&self, files: usize);
fn set_files(&mut self, files: usize);
/// Report the completion of a given file.
fn report_file(&self, file: &File);
@ -120,7 +120,7 @@ pub trait Reporter: Default + Send + Sync + RefUnwindSafe + 'static {
pub struct DummyReporter;
impl Reporter for DummyReporter {
fn set_files(&self, _files: usize) {}
fn set_files(&mut self, _files: usize) {}
fn report_file(&self, _file: &File) {}
}
@ -186,7 +186,11 @@ impl Project {
}
/// Checks all open files in the project and its dependencies.
pub(crate) fn check(self, db: &ProjectDatabase, reporter: &impl Reporter) -> Vec<Diagnostic> {
pub(crate) fn check(
self,
db: &ProjectDatabase,
mut reporter: AssertUnwindSafe<&mut dyn Reporter>,
) -> Vec<Diagnostic> {
let project_span = tracing::debug_span!("Project::check");
let _span = project_span.enter();
@ -215,6 +219,7 @@ impl Project {
let db = db.clone();
let file_diagnostics = &file_diagnostics;
let project_span = &project_span;
let reporter = &reporter;
rayon::scope(move |scope| {
for file in &files {