mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(diagnostics): remove thiserror
This commit is contained in:
parent
f7a37739c8
commit
551632a348
6 changed files with 13 additions and 23 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1368,7 +1368,6 @@ dependencies = [
|
||||||
"miette",
|
"miette",
|
||||||
"owo-colors",
|
"owo-colors",
|
||||||
"textwrap",
|
"textwrap",
|
||||||
"thiserror",
|
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,6 @@ serde = "1.0.199"
|
||||||
serde_json = "1.0.116"
|
serde_json = "1.0.116"
|
||||||
syn = { version = "2.0.58", default-features = false }
|
syn = { version = "2.0.58", default-features = false }
|
||||||
tempfile = "3.10.1"
|
tempfile = "3.10.1"
|
||||||
thiserror = "1.0.59"
|
|
||||||
tokio = "1"
|
tokio = "1"
|
||||||
tower-lsp = "0.20.0"
|
tower-lsp = "0.20.0"
|
||||||
trybuild = "1.0.93"
|
trybuild = "1.0.93"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ workspace = true
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = { workspace = true }
|
|
||||||
miette = { workspace = true }
|
miette = { workspace = true }
|
||||||
|
|
||||||
unicode-width = { workspace = true }
|
unicode-width = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//! Diagnostics Wrapper
|
//! Diagnostics Wrapper
|
||||||
//! Exports `thiserror` and `miette`
|
//! Exports `miette`
|
||||||
|
|
||||||
mod graphic_reporter;
|
mod graphic_reporter;
|
||||||
mod graphical_theme;
|
mod graphical_theme;
|
||||||
|
|
@ -9,11 +9,9 @@ mod service;
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
path::PathBuf,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use miette;
|
pub use miette;
|
||||||
pub use thiserror;
|
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
graphic_reporter::GraphicalReportHandler,
|
graphic_reporter::GraphicalReportHandler,
|
||||||
|
|
@ -29,17 +27,6 @@ pub type Result<T> = std::result::Result<T, OxcDiagnostic>;
|
||||||
|
|
||||||
use miette::{Diagnostic, SourceCode};
|
use miette::{Diagnostic, SourceCode};
|
||||||
pub use miette::{LabeledSpan, NamedSource};
|
pub use miette::{LabeledSpan, NamedSource};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[derive(Debug, Error, Diagnostic)]
|
|
||||||
#[error("File is too long to fit on the screen")]
|
|
||||||
#[diagnostic(help("{0:?} seems like a minified file"))]
|
|
||||||
pub struct MinifiedFileError(pub PathBuf);
|
|
||||||
|
|
||||||
#[derive(Debug, Error, Diagnostic)]
|
|
||||||
#[error("Failed to open file {0:?} with error \"{1}\"")]
|
|
||||||
#[diagnostic(help("Failed to open file {0:?} with error \"{1}\""))]
|
|
||||||
pub struct FailedToOpenFileError(pub PathBuf, pub std::io::Error);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct OxcDiagnostic {
|
pub struct OxcDiagnostic {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
CheckstyleReporter, DiagnosticReporter, GithubReporter, GraphicalReporter, JsonReporter,
|
CheckstyleReporter, DiagnosticReporter, GithubReporter, GraphicalReporter, JsonReporter,
|
||||||
UnixReporter,
|
UnixReporter,
|
||||||
},
|
},
|
||||||
Error, MinifiedFileError, Severity,
|
Error, OxcDiagnostic, Severity,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type DiagnosticTuple = (PathBuf, Vec<Error>);
|
pub type DiagnosticTuple = (PathBuf, Vec<Error>);
|
||||||
|
|
@ -139,7 +139,10 @@ impl DiagnosticService {
|
||||||
if let Some(mut err_str) = self.reporter.render_error(diagnostic) {
|
if let Some(mut err_str) = self.reporter.render_error(diagnostic) {
|
||||||
// Skip large output and print only once
|
// Skip large output and print only once
|
||||||
if err_str.lines().any(|line| line.len() >= 400) {
|
if err_str.lines().any(|line| line.len() >= 400) {
|
||||||
let minified_diagnostic = Error::new(MinifiedFileError(path.clone()));
|
let minified_diagnostic = Error::new(
|
||||||
|
OxcDiagnostic::warning("File is too long to fit on the screen")
|
||||||
|
.with_help(format!("{path:?} seems like a minified file")),
|
||||||
|
);
|
||||||
err_str = format!("{minified_diagnostic:?}");
|
err_str = format!("{minified_diagnostic:?}");
|
||||||
output = err_str;
|
output = err_str;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use rayon::{iter::ParallelBridge, prelude::ParallelIterator};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use oxc_allocator::Allocator;
|
use oxc_allocator::Allocator;
|
||||||
use oxc_diagnostics::{DiagnosticSender, DiagnosticService, Error, FailedToOpenFileError};
|
use oxc_diagnostics::{DiagnosticSender, DiagnosticService, Error, OxcDiagnostic};
|
||||||
use oxc_parser::Parser;
|
use oxc_parser::Parser;
|
||||||
use oxc_resolver::Resolver;
|
use oxc_resolver::Resolver;
|
||||||
use oxc_semantic::{ModuleRecord, SemanticBuilder};
|
use oxc_semantic::{ModuleRecord, SemanticBuilder};
|
||||||
|
|
@ -177,8 +177,11 @@ impl Runtime {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let source_type = source_type.unwrap_or_default();
|
let source_type = source_type.unwrap_or_default();
|
||||||
let file_result = fs::read_to_string(path)
|
let file_result = fs::read_to_string(path).map_err(|e| {
|
||||||
.map_err(|e| Error::new(FailedToOpenFileError(path.to_path_buf(), e)));
|
Error::new(OxcDiagnostic::error(format!(
|
||||||
|
"Failed to open file {path:?} with error \"{e}\""
|
||||||
|
)))
|
||||||
|
});
|
||||||
Some(match file_result {
|
Some(match file_result {
|
||||||
Ok(source_text) => Ok((source_type, source_text)),
|
Ok(source_text) => Ok((source_type, source_text)),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue