Skip to content

Commit

Permalink
Bump ariadne to 0.4.1 and use byte spans (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
msrd0 authored May 13, 2024
1 parent 3c3c3b0 commit fa621ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
14 changes: 10 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 12 additions & 2 deletions src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use std::{io, ops::Range};

pub type Span = Range<usize>;

fn config() -> ariadne::Config {
ariadne::Config::default().with_index_type(ariadne::IndexType::Byte)
}

pub struct Diagnostic {
filename: String,
code: String,
Expand Down Expand Up @@ -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
}
Expand All @@ -57,6 +61,7 @@ impl Diagnostic {
self.filename.clone(),
0
)
.with_config(config())
.with_message(msg)
.finish()
);
Expand All @@ -69,6 +74,7 @@ impl Diagnostic {
{
self.reports.push(
Report::build(ReportKind::Warning, self.filename.clone(), 0)
.with_config(config())
.with_message(msg)
.finish()
);
Expand All @@ -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()
Expand All @@ -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.")
Expand All @@ -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();
Expand All @@ -130,6 +139,7 @@ impl Diagnostic {
{
self.reports.push(
Report::build(ReportKind::Error, self.filename.clone(), 0)
.with_config(config())
.with_message(msg)
.finish()
);
Expand Down

0 comments on commit fa621ac

Please sign in to comment.