Begin making pretty errors with lyneate
This commit is contained in:
parent
4b0910a545
commit
a53f83f03a
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -263,6 +263,16 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colored"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@ -363,6 +373,7 @@ version = "0.4.1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"clap",
|
"clap",
|
||||||
|
"colored",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"csv",
|
"csv",
|
||||||
"enum-iterator",
|
"enum-iterator",
|
||||||
@ -371,6 +382,7 @@ dependencies = [
|
|||||||
"humantime",
|
"humantime",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
|
"lyneate",
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
"rand",
|
"rand",
|
||||||
"rayon",
|
"rayon",
|
||||||
@ -830,6 +842,16 @@ version = "0.4.20"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lyneate"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db93f0347ea71252796f5c6a61f2b75ed8434635ab2ad84238837a89125fa5e3"
|
||||||
|
dependencies = [
|
||||||
|
"colored",
|
||||||
|
"widestring",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "malloc_buf"
|
name = "malloc_buf"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
@ -1833,6 +1855,12 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "widestring"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
@ -36,6 +36,8 @@ crossterm = "0.27.0"
|
|||||||
nu-ansi-term = "0.49.0"
|
nu-ansi-term = "0.49.0"
|
||||||
humantime = "2.1.0"
|
humantime = "2.1.0"
|
||||||
stanza = "0.5.1"
|
stanza = "0.5.1"
|
||||||
|
colored = "2.1.0"
|
||||||
|
lyneate = "0.2.1"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
|
@ -65,9 +65,9 @@ impl fmt::Display for Error {
|
|||||||
use Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Syntax(error) => write!(f, "Syntax error: {error}"),
|
Syntax(error) => write!(f, "{error}"),
|
||||||
Validation(error) => write!(f, "Validation error: {error}"),
|
Validation(error) => write!(f, "{error}"),
|
||||||
Runtime(error) => write!(f, "Runtime error: {error}"),
|
Runtime(error) => write!(f, "{error}"),
|
||||||
ParserCancelled => write!(f, "Parsing was cancelled because the parser took too long."),
|
ParserCancelled => write!(f, "Parsing was cancelled because the parser took too long."),
|
||||||
Language(_error) => write!(f, "Parser failed to load language grammar."),
|
Language(_error) => write!(f, "Parser failed to load language grammar."),
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
|
||||||
|
use lyneate::Report;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tree_sitter::{Node as SyntaxNode, Point};
|
use tree_sitter::{Node as SyntaxNode, Point};
|
||||||
|
|
||||||
@ -62,6 +63,25 @@ impl From<RwLockError> for SyntaxError {
|
|||||||
|
|
||||||
impl Display for SyntaxError {
|
impl Display for SyntaxError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
if let SyntaxError::InvalidSource { source, position } = self {
|
||||||
|
let report = Report::new_char_spanned(
|
||||||
|
&source,
|
||||||
|
[(
|
||||||
|
position.start_byte..position.end_byte,
|
||||||
|
format!(
|
||||||
|
"Syntax error at ({}, {}) to ({}, {}).",
|
||||||
|
position.start_row,
|
||||||
|
position.start_column,
|
||||||
|
position.end_row,
|
||||||
|
position.end_column
|
||||||
|
),
|
||||||
|
(255, 100, 100),
|
||||||
|
)],
|
||||||
|
);
|
||||||
|
|
||||||
|
f.write_str(&report.display_str())
|
||||||
|
} else {
|
||||||
write!(f, "{self:?}")
|
write!(f, "{self:?}")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user