diff --git a/crates/ruff_cli/Cargo.toml b/crates/ruff_cli/Cargo.toml index 28331cd31d..59603a9d21 100644 --- a/crates/ruff_cli/Cargo.toml +++ b/crates/ruff_cli/Cargo.toml @@ -64,7 +64,7 @@ shellexpand = { workspace = true } similar = { workspace = true } strum = { workspace = true, features = [] } thiserror = { workspace = true } -tracing = { workspace = true } +tracing = { workspace = true, features = ["log"] } walkdir = { version = "2.3.2" } wild = { version = "2" } diff --git a/crates/ruff_cli/src/commands/format.rs b/crates/ruff_cli/src/commands/format.rs index d2383f17ce..1b955d6526 100644 --- a/crates/ruff_cli/src/commands/format.rs +++ b/crates/ruff_cli/src/commands/format.rs @@ -8,10 +8,10 @@ use std::time::Instant; use anyhow::Result; use colored::Colorize; -use log::{debug, warn}; use rayon::iter::Either::{Left, Right}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use thiserror::Error; +use tracing::{debug, warn}; use ruff::fs; use ruff::logging::LogLevel; @@ -61,30 +61,38 @@ pub(crate) fn format( let start = Instant::now(); let (results, errors): (Vec<_>, Vec<_>) = paths .into_par_iter() - .filter_map(|entry| match entry { - Ok(entry) => { - let path = entry.path(); + .filter_map(|entry| { + match entry { + Ok(entry) => { + let path = entry.path(); - let SourceType::Python(source_type @ (PySourceType::Python | PySourceType::Stub)) = - SourceType::from(path) - else { - // Ignore any non-Python files. - return None; - }; + let SourceType::Python( + source_type @ (PySourceType::Python | PySourceType::Stub), + ) = SourceType::from(path) + else { + // Ignore any non-Python files. + return None; + }; - let line_length = resolver.resolve(path, &pyproject_config).line_length; - let options = PyFormatOptions::from_source_type(source_type) - .with_line_width(LineWidth::from(NonZeroU16::from(line_length))); - Some(format_path(path, options, mode)) + let line_length = resolver.resolve(path, &pyproject_config).line_length; + let options = PyFormatOptions::from_source_type(source_type) + .with_line_width(LineWidth::from(NonZeroU16::from(line_length))); + debug!("Formatting {} with {:?}", path.display(), options); + Some(format_path(path, options, mode)) + } + Err(err) => Some(Err(FormatCommandError::Ignore(err))), } - Err(err) => Some(Err(FormatCommandError::Ignore(err))), }) .partition_map(|result| match result { Ok(diagnostic) => Left(diagnostic), Err(err) => Right(err), }); let duration = start.elapsed(); - debug!("Formatted files in: {:?}", duration); + debug!( + "Formatted {} files in {:.2?}", + results.len() + errors.len(), + duration + ); let summary = FormatResultSummary::new(results, mode); diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index c732c125e8..803cfa07da 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -54,32 +54,31 @@ impl<'a> Printer<'a> { /// Prints the passed in element as well as all its content, /// starting at the specified indentation level + #[tracing::instrument(name = "Printer::print", skip_all)] pub fn print_with_indent( mut self, document: &'a Document, indent: u16, ) -> PrintResult { - tracing::debug_span!("Printer::print").in_scope(move || { - let mut stack = PrintCallStack::new(PrintElementArgs::new(Indention::Level(indent))); - let mut queue: PrintQueue<'a> = PrintQueue::new(document.as_ref()); + let mut stack = PrintCallStack::new(PrintElementArgs::new(Indention::Level(indent))); + let mut queue: PrintQueue<'a> = PrintQueue::new(document.as_ref()); - loop { - if let Some(element) = queue.pop() { - self.print_element(&mut stack, &mut queue, element)?; - } else { - if !self.flush_line_suffixes(&mut queue, &mut stack, None) { - break; - } + loop { + if let Some(element) = queue.pop() { + self.print_element(&mut stack, &mut queue, element)?; + } else { + if !self.flush_line_suffixes(&mut queue, &mut stack, None) { + break; } } + } - Ok(Printed::new( - self.state.buffer, - None, - self.state.source_markers, - self.state.verbatim_markers, - )) - }) + Ok(Printed::new( + self.state.buffer, + None, + self.state.source_markers, + self.state.verbatim_markers, + )) } /// Prints a single element and push the following elements to queue