Skip to content

Commit 27b4f36

Browse files
committed
refactor(diagnostic): remove path from sender (#15130)
needs oxc-project/oxc-miette#103
1 parent 682dca2 commit 27b4f36

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

apps/oxfmt/src/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl FormatService {
6262
&source_text,
6363
ret.errors,
6464
);
65-
tx_error.send((path.clone(), diagnostics)).unwrap();
65+
tx_error.send(diagnostics).unwrap();
6666
return;
6767
}
6868

@@ -99,7 +99,7 @@ impl FormatService {
9999
))),
100100
_ => None,
101101
} {
102-
tx_error.send((path.clone(), vec![diagnostic.into()])).unwrap();
102+
tx_error.send(vec![diagnostic.into()]).unwrap();
103103
}
104104
}
105105
}

crates/oxc_diagnostics/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use std::{
5656

5757
pub mod reporter;
5858

59-
pub use crate::service::{DiagnosticSender, DiagnosticService, DiagnosticTuple};
59+
pub use crate::service::{DiagnosticSender, DiagnosticService};
6060

6161
pub type Error = miette::Error;
6262
pub type Severity = miette::Severity;

crates/oxc_diagnostics/src/service.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ use crate::{
1515
reporter::{DiagnosticReporter, DiagnosticResult},
1616
};
1717

18-
pub type DiagnosticTuple = (PathBuf, Vec<Error>);
19-
pub type DiagnosticSender = mpsc::Sender<DiagnosticTuple>;
20-
pub type DiagnosticReceiver = mpsc::Receiver<DiagnosticTuple>;
18+
pub type DiagnosticSender = mpsc::Sender<Vec<Error>>;
19+
pub type DiagnosticReceiver = mpsc::Receiver<Vec<Error>>;
2120

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

159-
while let Ok((path, diagnostics)) = self.receiver.recv() {
158+
while let Ok(diagnostics) = self.receiver.recv() {
160159
let mut is_minified = false;
161160
for diagnostic in diagnostics {
162161
let severity = diagnostic.severity();
@@ -180,15 +179,23 @@ impl DiagnosticService {
180179
continue;
181180
}
182181

182+
let path = diagnostic
183+
.source_code()
184+
.and_then(|source| source.name())
185+
.map(ToString::to_string);
186+
183187
if let Some(err_str) = self.reporter.render_error(diagnostic) {
184188
// Skip large output and print only once.
185189
// Setting to 1200 because graphical output may contain ansi escape codes and other decorations.
186190
if err_str.lines().any(|line| line.len() >= 1200) {
187-
let minified_diagnostic = Error::new(
188-
OxcDiagnostic::warn("File is too long to fit on the screen").with_help(
189-
format!("{} seems like a minified file", path.display()),
190-
),
191-
);
191+
let mut diagnostic =
192+
OxcDiagnostic::warn("File is too long to fit on the screen");
193+
if let Some(path) = path {
194+
diagnostic =
195+
diagnostic.with_help(format!("{path} seems like a minified file"));
196+
}
197+
198+
let minified_diagnostic = Error::new(diagnostic);
192199

193200
if let Some(err_str) = self.reporter.render_error(minified_diagnostic) {
194201
writer

crates/oxc_linter/src/lint_runner.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ impl DirectivesStore {
102102
&source_text,
103103
diagnostics,
104104
);
105-
tx_error
106-
.send((path.clone(), wrapped))
107-
.expect("failed to send unused directive diagnostics");
105+
tx_error.send(wrapped).expect("failed to send unused directive diagnostics");
108106
}
109107
}
110108
}

crates/oxc_linter/src/service/runtime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl Runtime {
576576
dep.source_text,
577577
messages,
578578
);
579-
tx_error.send((path.to_path_buf(), diagnostics)).unwrap();
579+
tx_error.send(diagnostics).unwrap();
580580
}
581581
None
582582
}
@@ -622,7 +622,7 @@ impl Runtime {
622622
dep.source_text,
623623
errors,
624624
);
625-
tx_error.send((path.to_path_buf(), diagnostics)).unwrap();
625+
tx_error.send(diagnostics).unwrap();
626626
}
627627

628628
// If the new source text is owned, that means it was modified,
@@ -809,7 +809,7 @@ impl Runtime {
809809
Ok(v) => v,
810810
Err(e) => {
811811
if let Some(tx_error) = tx_error {
812-
tx_error.send((Path::new(path).to_path_buf(), vec![e])).unwrap();
812+
tx_error.send(vec![e]).unwrap();
813813
}
814814
return Err(());
815815
}
@@ -840,7 +840,7 @@ impl Runtime {
840840
Ok(v) => v,
841841
Err(e) => {
842842
if let Some(tx_error) = tx_error {
843-
tx_error.send((Path::new(path).to_path_buf(), vec![e])).unwrap();
843+
tx_error.send(vec![e]).unwrap();
844844
}
845845
return None;
846846
}

crates/oxc_linter/src/tsgolint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl TsGoLintState {
272272
vec![oxc_diagnostic],
273273
);
274274

275-
if error_sender.send((path, diagnostics)).is_err() {
275+
if error_sender.send(diagnostics).is_err() {
276276
// Receiver has been dropped, stop processing
277277
return Ok(());
278278
}

0 commit comments

Comments
 (0)