From 5c27bb91c7523596a05beb88d8b4f5337731d829 Mon Sep 17 00:00:00 2001 From: "hash-worker[bot]" <180894564+hash-worker[bot]@users.noreply.github.com> Date: Thu, 31 Oct 2024 02:58:18 +0000 Subject: [PATCH 1/5] Update Rust crate `ariadne` to v0.5.0 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd3d0dc4e21..516a6980ca7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "ariadne" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44055e597c674aef7cb903b2b9f6e4cba1277ed0d2d61dae7cd52d7ffa81f8e2" +checksum = "31beedec3ce83ae6da3a79592b3d8d7afd146a5b15bb9bb940279aced60faa89" dependencies = [ "unicode-width", "yansi", diff --git a/Cargo.toml b/Cargo.toml index 2a602c7f74f..3a2596436f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,7 +84,7 @@ error-stack = { path = "./libs/error-stack", default-features = false } # Public dependencies ahash = { version = "=0.8.11", default-features = false } -ariadne = { version = "=0.4.1", default-features = false } +ariadne = { version = "=0.5.0", default-features = false } aws-types = { version = "=1.3.3", default-features = false } axum = "0.7.5" axum-core = "0.4.3" From 1ed15659fb7f9bd7b2f49112990792c5fed86c71 Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Mon, 4 Nov 2024 13:05:47 +0100 Subject: [PATCH 2/5] feat: update to ariadne 0.5 --- libs/@local/hql/diagnostics/src/diagnostic.rs | 34 +++++++------------ libs/@local/hql/diagnostics/src/label.rs | 11 ++++-- libs/@local/hql/diagnostics/src/span.rs | 6 ++++ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/libs/@local/hql/diagnostics/src/diagnostic.rs b/libs/@local/hql/diagnostics/src/diagnostic.rs index 20a13bf7366..519c1b260f8 100644 --- a/libs/@local/hql/diagnostics/src/diagnostic.rs +++ b/libs/@local/hql/diagnostics/src/diagnostic.rs @@ -4,7 +4,7 @@ use core::{ }; use ariadne::ColorGenerator; -use error_stack::{Report, Result, TryReportIteratorExt, TryReportTupleExt}; +use error_stack::{Result, TryReportIteratorExt}; use hql_span::{Span, SpanId, storage::SpanStorage, tree::SpanNode}; use crate::{ @@ -16,7 +16,7 @@ use crate::{ note::Note, rob::RefOrBox, severity::Severity, - span::{AbsoluteDiagnosticSpan, TransformSpan, absolute_span}, + span::{AbsoluteDiagnosticSpan, TransformSpan}, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -26,7 +26,6 @@ pub struct Diagnostic<'a, S> { pub severity: RefOrBox<'a, Severity<'a>>, pub message: Option>, - pub span: Option, pub labels: Vec>, pub note: Option, @@ -43,7 +42,6 @@ impl<'a, S> Diagnostic<'a, S> { category: category.into(), severity: severity.into(), message: None, - span: None, labels: Vec::new(), note: None, help: None, @@ -64,29 +62,18 @@ impl<'a> Diagnostic<'a, SpanId> { where S: Span + Clone, { - let span = self - .span - .map(|id| { - storage - .resolve(id) - .ok_or_else(|| Report::new(ResolveError::UnknownSpan { id })) - }) - .transpose(); - let labels: Result, _> = self .labels .into_iter() .map(|label| label.resolve(storage)) .try_collect_reports(); - let (span, labels) = (span, labels).try_collect()?; - Ok(Diagnostic { category: self.category, severity: self.severity, message: self.message, - span, - labels, + + labels: labels?, note: self.note, help: self.help, }) @@ -98,13 +85,18 @@ impl Diagnostic<'_, SpanNode> { &self, mut config: ReportConfig>, ) -> ariadne::Report { - let start = self.span.as_ref().map_or(0, |span| { - u32::from(absolute_span(span, &mut config.transform_span).start()) - }); + // According to the examples, the first range supplied should be the one that is absolute. + // See: https://github.com/zesterer/ariadne/blob/74c2a7f8881e95629f9fb8d70140c133972d81d3/examples/simple.rs#L14 + let span = self + .labels + .first() + .map_or_else(AbsoluteDiagnosticSpan::full, |label| { + label.absolute_span(&mut config.transform_span) + }); let mut generator = ColorGenerator::new(); - let mut builder = ariadne::Report::build(self.severity.as_ref().kind(), (), start as usize) + let mut builder = ariadne::Report::build(self.severity.as_ref().kind(), span) .with_code(self.category.as_ref().canonical_id()); builder.set_message( diff --git a/libs/@local/hql/diagnostics/src/label.rs b/libs/@local/hql/diagnostics/src/label.rs index 6ac14994628..864db8c90ae 100644 --- a/libs/@local/hql/diagnostics/src/label.rs +++ b/libs/@local/hql/diagnostics/src/label.rs @@ -90,14 +90,21 @@ impl Label { } impl Label> { + pub(crate) fn absolute_span( + &self, + transform: &mut impl TransformSpan, + ) -> AbsoluteDiagnosticSpan { + AbsoluteDiagnosticSpan::new(&self.span, transform) + } + pub(crate) fn ariadne( &self, enable_color: bool, generator: &mut ColorGenerator, transform: &mut impl TransformSpan, ) -> ariadne::Label { - let mut label = ariadne::Label::new(AbsoluteDiagnosticSpan::new(&self.span, transform)) - .with_message(&self.message); + let mut label = + ariadne::Label::new(self.absolute_span(transform)).with_message(&self.message); let color = self .color diff --git a/libs/@local/hql/diagnostics/src/span.rs b/libs/@local/hql/diagnostics/src/span.rs index b8afcc2af8e..e3ce8708921 100644 --- a/libs/@local/hql/diagnostics/src/span.rs +++ b/libs/@local/hql/diagnostics/src/span.rs @@ -54,6 +54,12 @@ impl AbsoluteDiagnosticSpan { Self { range } } + + pub(crate) const fn full() -> Self { + Self { + range: TextRange::new(TextSize::new(0), TextSize::new(u32::MAX)), + } + } } impl ariadne::Span for AbsoluteDiagnosticSpan { From 9f83d74f238305eff40265532af9d0905221d853 Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Mon, 4 Nov 2024 13:10:31 +0100 Subject: [PATCH 3/5] fix: wording --- libs/@local/hql/diagnostics/src/diagnostic.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/@local/hql/diagnostics/src/diagnostic.rs b/libs/@local/hql/diagnostics/src/diagnostic.rs index 1fafe65e0a6..be9e536a686 100644 --- a/libs/@local/hql/diagnostics/src/diagnostic.rs +++ b/libs/@local/hql/diagnostics/src/diagnostic.rs @@ -85,7 +85,8 @@ impl Diagnostic<'_, SpanNode> { &self, mut config: ReportConfig>, ) -> ariadne::Report { - // According to the examples, the first range supplied should be the one that is absolute. + // According to the examples, the span given to `Report::build` should be the span of the + // primary (first) label. // See: https://github.com/zesterer/ariadne/blob/74c2a7f8881e95629f9fb8d70140c133972d81d3/examples/simple.rs#L14 let span = self .labels From 22eb7f2d5fb84432265b56d5d0f0283a7bf9734a Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Mon, 4 Nov 2024 13:14:47 +0100 Subject: [PATCH 4/5] fix: apply suggestion from code review --- libs/@local/hql/diagnostics/src/diagnostic.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/@local/hql/diagnostics/src/diagnostic.rs b/libs/@local/hql/diagnostics/src/diagnostic.rs index be9e536a686..cd8b13f6d32 100644 --- a/libs/@local/hql/diagnostics/src/diagnostic.rs +++ b/libs/@local/hql/diagnostics/src/diagnostic.rs @@ -62,18 +62,18 @@ impl<'a> Diagnostic<'a, SpanId> { where S: Span + Clone, { - let labels: Result, _> = self + let labels: Vec<_> = self .labels .into_iter() .map(|label| label.resolve(storage)) - .try_collect_reports(); + .try_collect_reports()?; Ok(Diagnostic { category: self.category, severity: self.severity, message: self.message, - labels: labels?, + labels, note: self.note, help: self.help, }) From 826fd2a8570b31a28aecb789b9774284e458cc83 Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Mon, 4 Nov 2024 13:26:30 +0100 Subject: [PATCH 5/5] chore: change snapshots --- .../hql_syntax_jexpr__lexer__test__invalid_escape.snap | 2 +- .../hql_syntax_jexpr__lexer__test__invalid_number.snap | 2 +- .../hql_syntax_jexpr__lexer__test__missing_surrogate_pair.snap | 2 +- .../hql_syntax_jexpr__lexer__test__unrecognized_character.snap | 2 +- .../hql_syntax_jexpr__lexer__test__unterminated_string.snap | 2 +- ...arser__expr__test__object_is_constant_with_extra_fields.snap | 2 +- ...hql_syntax_jexpr__parser__expr__test__object_is_invalid.snap | 2 +- .../hql_syntax_jexpr__parser__value__test__duplicate_key.snap | 2 +- .../hql_syntax_jexpr__parser__value__test__key_is_number.snap | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_escape.snap b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_escape.snap index 3625c4fc59a..b6d1e748cb2 100644 --- a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_escape.snap +++ b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_escape.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/lexer/mod.rs expression: "\"\\z\"" --- [jexpr::lexing::invalid-string] Error: Invalid String Literal - ╭─[:1:1] + ╭─[:1:4] │ 1 │ "\z" │ │ diff --git a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_number.snap b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_number.snap index 5a46af5f2ed..50d788070b8 100644 --- a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_number.snap +++ b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__invalid_number.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/lexer/mod.rs expression: "{\"number\": 42.}" --- [jexpr::lexing::invalid-number] Error: Invalid Number Literal - ╭─[:1:1] + ╭─[:1:12] │ 1 │ {"number": 42.} │ │ diff --git a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__missing_surrogate_pair.snap b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__missing_surrogate_pair.snap index fb6b628105a..486db181700 100644 --- a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__missing_surrogate_pair.snap +++ b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__missing_surrogate_pair.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/lexer/mod.rs expression: "\"\\uD800\"" --- [jexpr::lexing::invalid-string] Error: Invalid String Literal - ╭─[:1:1] + ╭─[:1:9] │ 1 │ "\uD800" │ │ diff --git a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unrecognized_character.snap b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unrecognized_character.snap index 9ca630c702c..1f6ca7256d5 100644 --- a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unrecognized_character.snap +++ b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unrecognized_character.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/lexer/mod.rs expression: "{\"ferris\": 🦀}" --- [jexpr::lexing::invalid-character] Error: Invalid Character - ╭─[:1:1] + ╭─[:1:12] │ 1 │ {"ferris": 🦀} │ ┬─ diff --git a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unterminated_string.snap b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unterminated_string.snap index 018a384835f..e5f49a1f0e0 100644 --- a/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unterminated_string.snap +++ b/libs/@local/hql/syntax-jexpr/src/lexer/snapshots/hql_syntax_jexpr__lexer__test__unterminated_string.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/lexer/mod.rs expression: "\"hello" --- [jexpr::lexing::invalid-string] Error: Invalid String Literal - ╭─[:1:1] + ╭─[:1:7] │ 1 │ "hello │ │ diff --git a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_constant_with_extra_fields.snap b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_constant_with_extra_fields.snap index 70ff32e1910..f2b70ad8a74 100644 --- a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_constant_with_extra_fields.snap +++ b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_constant_with_extra_fields.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/parser/expr.rs expression: "{\"type\": \"u32\", \"const\": 42, \"sig\": \"() -> Unit\"}" --- [jexpr::parse::object::unknown-key] Error: Unknown Key - ╭─[:1:1] + ╭─[:1:30] │ 1 │ {"type": "u32", "const": 42, "sig": "() -> Unit"} │ ──┬── diff --git a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_invalid.snap b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_invalid.snap index 706f2c7adcc..a468cd36571 100644 --- a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_invalid.snap +++ b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__expr__test__object_is_invalid.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/parser/expr.rs expression: "{\"unknown\": \"key\"}" --- [jexpr::parse::object::unknown-key] Error: Unknown Key - ╭─[:1:1] + ╭─[:1:2] │ 1 │ {"unknown": "key"} │ ────┬──── diff --git a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__duplicate_key.snap b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__duplicate_key.snap index c9c027ee600..1bd582cb5b7 100644 --- a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__duplicate_key.snap +++ b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__duplicate_key.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/parser/value.rs expression: "{\"a\": 1, \"a\": b}" --- [jexpr::parse::object::duplicate-key] Error: Duplicate Key - ╭─[:1:1] + ╭─[:1:2] │ 1 │ {"a": 1, "a": b} │ ─┬─ ─┬─ diff --git a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__key_is_number.snap b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__key_is_number.snap index 41cbad9f749..ac002af7abf 100644 --- a/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__key_is_number.snap +++ b/libs/@local/hql/syntax-jexpr/src/parser/snapshots/hql_syntax_jexpr__parser__value__test__key_is_number.snap @@ -3,7 +3,7 @@ source: libs/@local/hql/syntax-jexpr/src/parser/value.rs expression: "{12: \"12\"}" --- [jexpr::parse::unexpected-token] Error: Unexpected token - ╭─[:1:1] + ╭─[:1:2] │ 1 │ {12: "12"} │ ─┬