Skip to content
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
4 changes: 2 additions & 2 deletions apps/oxfmt/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl FormatService {
&source_text,
ret.errors,
);
tx_error.send((path.clone(), diagnostics)).unwrap();
tx_error.send(diagnostics).unwrap();
return;
}

Expand Down Expand Up @@ -99,7 +99,7 @@ impl FormatService {
))),
_ => None,
} {
tx_error.send((path.clone(), vec![diagnostic.into()])).unwrap();
tx_error.send(vec![diagnostic.into()]).unwrap();
}
}
}
2 changes: 1 addition & 1 deletion crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use std::{

pub mod reporter;

pub use crate::service::{DiagnosticSender, DiagnosticService, DiagnosticTuple};
pub use crate::service::{DiagnosticSender, DiagnosticService};

pub type Error = miette::Error;
pub type Severity = miette::Severity;
Expand Down
29 changes: 18 additions & 11 deletions crates/oxc_diagnostics/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ use crate::{
reporter::{DiagnosticReporter, DiagnosticResult},
};

pub type DiagnosticTuple = (PathBuf, Vec<Error>);
pub type DiagnosticSender = mpsc::Sender<DiagnosticTuple>;
pub type DiagnosticReceiver = mpsc::Receiver<DiagnosticTuple>;
pub type DiagnosticSender = mpsc::Sender<Vec<Error>>;
pub type DiagnosticReceiver = mpsc::Receiver<Vec<Error>>;

/// Listens for diagnostics sent over a [channel](DiagnosticSender) by some job, and
/// formats/reports them to the user.
///
/// [`DiagnosticService`] is designed to support multi-threaded jobs that may produce
/// reports. These jobs can send [messages](DiagnosticTuple) to the service over its
/// multi-producer, single-consumer channel.
/// reports. These jobs can send messages to the service over its multi-producer,
/// single-consumer channel.
///
/// # Example
/// ```rust
Expand Down Expand Up @@ -156,7 +155,7 @@ impl DiagnosticService {
let mut warnings_count: usize = 0;
let mut errors_count: usize = 0;

while let Ok((path, diagnostics)) = self.receiver.recv() {
while let Ok(diagnostics) = self.receiver.recv() {
let mut is_minified = false;
for diagnostic in diagnostics {
let severity = diagnostic.severity();
Expand All @@ -180,15 +179,23 @@ impl DiagnosticService {
continue;
}

let path = diagnostic
.source_code()
.and_then(|source| source.name())
.map(ToString::to_string);

if let Some(err_str) = self.reporter.render_error(diagnostic) {
// Skip large output and print only once.
// Setting to 1200 because graphical output may contain ansi escape codes and other decorations.
if err_str.lines().any(|line| line.len() >= 1200) {
let minified_diagnostic = Error::new(
OxcDiagnostic::warn("File is too long to fit on the screen").with_help(
format!("{} seems like a minified file", path.display()),
),
);
let mut diagnostic =
OxcDiagnostic::warn("File is too long to fit on the screen");
if let Some(path) = path {
diagnostic =
diagnostic.with_help(format!("{path} seems like a minified file"));
}

let minified_diagnostic = Error::new(diagnostic);

if let Some(err_str) = self.reporter.render_error(minified_diagnostic) {
writer
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_linter/src/lint_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ impl DirectivesStore {
&source_text,
diagnostics,
);
tx_error
.send((path.clone(), wrapped))
.expect("failed to send unused directive diagnostics");
tx_error.send(wrapped).expect("failed to send unused directive diagnostics");
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl Runtime {
dep.source_text,
messages,
);
tx_error.send((path.to_path_buf(), diagnostics)).unwrap();
tx_error.send(diagnostics).unwrap();
}
None
}
Expand Down Expand Up @@ -622,7 +622,7 @@ impl Runtime {
dep.source_text,
errors,
);
tx_error.send((path.to_path_buf(), diagnostics)).unwrap();
tx_error.send(diagnostics).unwrap();
}

// If the new source text is owned, that means it was modified,
Expand Down Expand Up @@ -809,7 +809,7 @@ impl Runtime {
Ok(v) => v,
Err(e) => {
if let Some(tx_error) = tx_error {
tx_error.send((Path::new(path).to_path_buf(), vec![e])).unwrap();
tx_error.send(vec![e]).unwrap();
}
return Err(());
}
Expand Down Expand Up @@ -840,7 +840,7 @@ impl Runtime {
Ok(v) => v,
Err(e) => {
if let Some(tx_error) = tx_error {
tx_error.send((Path::new(path).to_path_buf(), vec![e])).unwrap();
tx_error.send(vec![e]).unwrap();
}
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/tsgolint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl TsGoLintState {
vec![oxc_diagnostic],
);

if error_sender.send((path, diagnostics)).is_err() {
if error_sender.send(diagnostics).is_err() {
// Receiver has been dropped, stop processing
return Ok(());
}
Expand Down
Loading