diff --git a/Cargo.lock b/Cargo.lock index 1a740aa..146214e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,12 +67,12 @@ checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "ariadne" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd002a6223f12c7a95cdd4b1cb3a0149d22d37f7a9ecdb2cb691a071fe236c29" +checksum = "44055e597c674aef7cb903b2b9f6e4cba1277ed0d2d61dae7cd52d7ffa81f8e2" dependencies = [ "unicode-width", - "yansi", + "yansi 1.0.1", ] [[package]] @@ -476,7 +476,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" dependencies = [ "diff", - "yansi", + "yansi 0.5.1", ] [[package]] @@ -931,3 +931,9 @@ name = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" diff --git a/Cargo.toml b/Cargo.toml index c83d575..e97d00a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ harness = false [dependencies] anyhow = "1.0" -ariadne = "0.4" +ariadne = "0.4.1" base64 = "0.22" blake3 = "1.5" cargo_metadata = "0.18" diff --git a/src/diagnostic.rs b/src/diagnostic.rs index fa8bc52..ba16f48 100644 --- a/src/diagnostic.rs +++ b/src/diagnostic.rs @@ -3,6 +3,10 @@ use std::{io, ops::Range}; pub type Span = Range; +fn config() -> ariadne::Config { + ariadne::Config::default().with_index_type(ariadne::IndexType::Byte) +} + pub struct Diagnostic { filename: String, code: String, @@ -41,7 +45,7 @@ impl Diagnostic { .code .split('\n') .take(at.line - 1) - .map(|line| line.chars().count() + 1) + .map(|line| line.len() + 1) .sum(); line_offset + at.column } @@ -57,6 +61,7 @@ impl Diagnostic { self.filename.clone(), 0 ) + .with_config(config()) .with_message(msg) .finish() ); @@ -69,6 +74,7 @@ impl Diagnostic { { self.reports.push( Report::build(ReportKind::Warning, self.filename.clone(), 0) + .with_config(config()) .with_message(msg) .finish() ); @@ -83,6 +89,7 @@ impl Diagnostic { let span = self.offset(span.start()) .. self.offset(span.end()); self.reports.push( Report::build(ReportKind::Warning, self.filename.clone(), span.start) + .with_config(config()) .with_message(msg) .with_label(Label::new((self.filename.clone(), span)).with_message(label)) .finish() @@ -94,6 +101,7 @@ impl Diagnostic { let span = self.offset(span.start()) .. self.offset(span.end()); self.reports.push( Report::build(ReportKind::Warning, self.filename.clone(), span.start) + .with_config(config()) .with_message("Macro not expanded") .with_label(Label::new((self.filename.clone(), span)).with_message("This macro was not expanded")) .with_help("You can use `--expand-macros` on a nightly Rust toolchain to expand macros.") @@ -107,7 +115,8 @@ impl Diagnostic { ReportKind::Error, self.filename.clone(), self.offset(err.span().start()) - ); + ) + .with_config(config()); report.set_message("Syntax Error"); for err in err { let span = err.span(); @@ -130,6 +139,7 @@ impl Diagnostic { { self.reports.push( Report::build(ReportKind::Error, self.filename.clone(), 0) + .with_config(config()) .with_message(msg) .finish() );