diff --git a/crates/stef-build/src/definition.rs b/crates/stef-build/src/definition.rs index 9d73bb6..d412da8 100644 --- a/crates/stef-build/src/definition.rs +++ b/crates/stef-build/src/definition.rs @@ -207,7 +207,7 @@ fn compile_import(Import { segments, element }: &Import<'_>) -> TokenStream { } fn compile_comment(Comment(lines): &Comment<'_>) -> TokenStream { - let lines = lines.iter().map(|line| format!(" {line}")); + let lines = lines.iter().map(|line| format!(" {}", line.value)); quote! { #(#[doc = #lines])* } } diff --git a/crates/stef-go/src/definition.rs b/crates/stef-go/src/definition.rs index dc060e3..35d6ad6 100644 --- a/crates/stef-go/src/definition.rs +++ b/crates/stef-go/src/definition.rs @@ -426,7 +426,7 @@ struct RenderComment<'a> { impl Display for RenderComment<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for line in &self.comment.0 { - writeln!(f, "{:\t { for line in lines { Self::indent(f, level)?; - line.fmt(f)?; + writeln!(f, "{line}")?; } Ok(()) diff --git a/crates/stef-parser/tests/snapshots/parser__parse@alias_basic.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@alias_basic.stef.snap index 39fb321..7b0f37f 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@alias_basic.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@alias_basic.stef.snap @@ -13,7 +13,13 @@ Schema { TypeAlias { comment: Comment( [ - "Sample type alias.", + CommentLine { + value: "Sample type alias.", + span: Span { + start: 0, + end: 22, + }, + }, ], ), name: Name { diff --git a/crates/stef-parser/tests/snapshots/parser__parse@attribute_multi.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@attribute_multi.stef.snap index 5f7d090..5fc8f39 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@attribute_multi.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@attribute_multi.stef.snap @@ -23,17 +23,29 @@ Schema { Attribute { name: "min", value: Single( - Int( - 1, - ), + Literal { + value: Int( + 1, + ), + span: Span { + start: 17, + end: 18, + }, + }, ), }, Attribute { name: "max", value: Single( - Int( - 100, - ), + Literal { + value: Int( + 100, + ), + span: Span { + start: 26, + end: 29, + }, + }, ), }, ], diff --git a/crates/stef-parser/tests/snapshots/parser__parse@attribute_single.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@attribute_single.stef.snap index 2bde824..55b4228 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@attribute_single.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@attribute_single.stef.snap @@ -19,9 +19,15 @@ Schema { Attribute { name: "deprecated", value: Single( - String( - "don't use", - ), + Literal { + value: String( + "don't use", + ), + span: Span { + start: 15, + end: 26, + }, + }, ), }, ], diff --git a/crates/stef-parser/tests/snapshots/parser__parse@attributes.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@attributes.stef.snap index 53aaf0b..43bfe06 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@attributes.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@attributes.stef.snap @@ -19,9 +19,15 @@ Schema { Attribute { name: "deprecated", value: Single( - String( - "don't use", - ), + Literal { + value: String( + "don't use", + ), + span: Span { + start: 15, + end: 26, + }, + }, ), }, Attribute { @@ -39,17 +45,29 @@ Schema { Attribute { name: "min", value: Single( - Int( - 100, - ), + Literal { + value: Int( + 100, + ), + span: Span { + start: 69, + end: 72, + }, + }, ), }, Attribute { name: "max", value: Single( - Int( - 200, - ), + Literal { + value: Int( + 200, + ), + span: Span { + start: 80, + end: 83, + }, + }, ), }, ], diff --git a/crates/stef-parser/tests/snapshots/parser__parse@attributes_min_ws.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@attributes_min_ws.stef.snap index 0f2bd41..2eb197f 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@attributes_min_ws.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@attributes_min_ws.stef.snap @@ -19,9 +19,15 @@ Schema { Attribute { name: "deprecated", value: Single( - String( - "don't use", - ), + Literal { + value: String( + "don't use", + ), + span: Span { + start: 13, + end: 24, + }, + }, ), }, Attribute { @@ -39,17 +45,29 @@ Schema { Attribute { name: "min", value: Single( - Int( - 100, - ), + Literal { + value: Int( + 100, + ), + span: Span { + start: 59, + end: 62, + }, + }, ), }, Attribute { name: "max", value: Single( - Int( - 200, - ), + Literal { + value: Int( + 200, + ), + span: Span { + start: 67, + end: 70, + }, + }, ), }, ], diff --git a/crates/stef-parser/tests/snapshots/parser__parse@const_basic.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@const_basic.stef.snap index c3f54c5..933459f 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@const_basic.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@const_basic.stef.snap @@ -28,9 +28,15 @@ Schema { end: 21, }, }, - value: Bool( - true, - ), + value: Literal { + value: Bool( + true, + ), + span: Span { + start: 24, + end: 28, + }, + }, }, ), Const( @@ -52,9 +58,15 @@ Schema { end: 52, }, }, - value: Bool( - false, - ), + value: Literal { + value: Bool( + false, + ), + span: Span { + start: 55, + end: 60, + }, + }, }, ), Const( @@ -76,9 +88,15 @@ Schema { end: 76, }, }, - value: Int( - 100, - ), + value: Literal { + value: Int( + 100, + ), + span: Span { + start: 79, + end: 82, + }, + }, }, ), Const( @@ -100,9 +118,15 @@ Schema { end: 100, }, }, - value: Float( - 5.5, - ), + value: Literal { + value: Float( + 5.5, + ), + span: Span { + start: 103, + end: 106, + }, + }, }, ), Const( @@ -124,9 +148,15 @@ Schema { end: 128, }, }, - value: String( - "value", - ), + value: Literal { + value: String( + "value", + ), + span: Span { + start: 131, + end: 138, + }, + }, }, ), Const( @@ -148,13 +178,19 @@ Schema { end: 158, }, }, - value: Bytes( - [ - 1, - 2, - 3, - ], - ), + value: Literal { + value: Bytes( + [ + 1, + 2, + 3, + ], + ), + span: Span { + start: 161, + end: 170, + }, + }, }, ), ], diff --git a/crates/stef-parser/tests/snapshots/parser__parse@const_string.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@const_string.stef.snap index feec0a8..fb1a598 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@const_string.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@const_string.stef.snap @@ -28,9 +28,15 @@ Schema { end: 20, }, }, - value: String( - "value", - ), + value: Literal { + value: String( + "value", + ), + span: Span { + start: 23, + end: 30, + }, + }, }, ), Const( @@ -52,9 +58,15 @@ Schema { end: 61, }, }, - value: String( - "one two three", - ), + value: Literal { + value: String( + "one two three", + ), + span: Span { + start: 64, + end: 93, + }, + }, }, ), Const( @@ -76,9 +88,15 @@ Schema { end: 117, }, }, - value: String( - "escape basics \r\n \t \u{8} \u{c} \\ \"hello\" \nunicode ❤ emoji ❤ ", - ), + value: Literal { + value: String( + "escape basics \r\n \t \u{8} \u{c} \\ \"hello\" \nunicode ❤ emoji ❤ ", + ), + span: Span { + start: 120, + end: 213, + }, + }, }, ), Const( @@ -100,9 +118,15 @@ Schema { end: 239, }, }, - value: String( - "a\n b\n c\n", - ), + value: Literal { + value: String( + "a\n b\n c\n", + ), + span: Span { + start: 242, + end: 258, + }, + }, }, ), ], diff --git a/crates/stef-parser/tests/snapshots/parser__parse@enum_basic.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@enum_basic.stef.snap index 7fd36fc..f4c9c40 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@enum_basic.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@enum_basic.stef.snap @@ -13,7 +13,13 @@ Schema { Enum { comment: Comment( [ - "Sample enum.", + CommentLine { + value: "Sample enum.", + span: Span { + start: 0, + end: 16, + }, + }, ], ), attributes: Attributes( @@ -57,7 +63,13 @@ Schema { Variant { comment: Comment( [ - "Second variant", + CommentLine { + value: "Second variant", + span: Span { + start: 47, + end: 65, + }, + }, ], ), name: Name { @@ -169,7 +181,13 @@ Schema { NamedField { comment: Comment( [ - "Second field of third variant", + CommentLine { + value: "Second field of third variant", + span: Span { + start: 138, + end: 171, + }, + }, ], ), name: Name { diff --git a/crates/stef-parser/tests/snapshots/parser__parse@enum_generics.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@enum_generics.stef.snap index e3213fc..c6daa9d 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@enum_generics.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@enum_generics.stef.snap @@ -13,7 +13,13 @@ Schema { Enum { comment: Comment( [ - "Enum with generics.", + CommentLine { + value: "Enum with generics.", + span: Span { + start: 0, + end: 23, + }, + }, ], ), attributes: Attributes( diff --git a/crates/stef-parser/tests/snapshots/parser__parse@enum_many_ws.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@enum_many_ws.stef.snap index b5d74ff..b03fe4e 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@enum_many_ws.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@enum_many_ws.stef.snap @@ -13,7 +13,13 @@ Schema { Enum { comment: Comment( [ - "Sample enum.", + CommentLine { + value: "Sample enum.", + span: Span { + start: 2, + end: 18, + }, + }, ], ), attributes: Attributes( diff --git a/crates/stef-parser/tests/snapshots/parser__parse@module_basic.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@module_basic.stef.snap index be5dc71..bfa2c40 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@module_basic.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@module_basic.stef.snap @@ -26,7 +26,13 @@ Schema { Module { comment: Comment( [ - "Inner module", + CommentLine { + value: "Inner module", + span: Span { + start: 12, + end: 28, + }, + }, ], ), name: Name { diff --git a/crates/stef-parser/tests/snapshots/parser__parse@schema_basic.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@schema_basic.stef.snap index 242c2f1..bd05895 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@schema_basic.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@schema_basic.stef.snap @@ -13,7 +13,13 @@ Schema { Struct { comment: Comment( [ - "Basic struct.", + CommentLine { + value: "Basic struct.", + span: Span { + start: 0, + end: 17, + }, + }, ], ), attributes: Attributes( @@ -99,7 +105,13 @@ Schema { Enum { comment: Comment( [ - "Sample enum.", + CommentLine { + value: "Sample enum.", + span: Span { + start: 74, + end: 90, + }, + }, ], ), attributes: Attributes( diff --git a/crates/stef-parser/tests/snapshots/parser__parse@struct_basic.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@struct_basic.stef.snap index 5ec30a6..334ad46 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@struct_basic.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@struct_basic.stef.snap @@ -13,7 +13,13 @@ Schema { Struct { comment: Comment( [ - "Basic struct.", + CommentLine { + value: "Basic struct.", + span: Span { + start: 0, + end: 17, + }, + }, ], ), attributes: Attributes( @@ -64,7 +70,13 @@ Schema { NamedField { comment: Comment( [ - "Second field", + CommentLine { + value: "Second field", + span: Span { + start: 53, + end: 69, + }, + }, ], ), name: Name { diff --git a/crates/stef-parser/tests/snapshots/parser__parse@struct_generics.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@struct_generics.stef.snap index 9dec535..95defb2 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@struct_generics.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@struct_generics.stef.snap @@ -13,7 +13,13 @@ Schema { Struct { comment: Comment( [ - "Generic key-value pair.", + CommentLine { + value: "Generic key-value pair.", + span: Span { + start: 0, + end: 27, + }, + }, ], ), attributes: Attributes( diff --git a/crates/stef-parser/tests/snapshots/parser__parse@struct_many_ws.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@struct_many_ws.stef.snap index 0fd8587..5041cd1 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@struct_many_ws.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@struct_many_ws.stef.snap @@ -13,7 +13,13 @@ Schema { Struct { comment: Comment( [ - "Some comment", + CommentLine { + value: "Some comment", + span: Span { + start: 2, + end: 18, + }, + }, ], ), attributes: Attributes( diff --git a/crates/stef-parser/tests/snapshots/parser__parse@struct_tuple.stef.snap b/crates/stef-parser/tests/snapshots/parser__parse@struct_tuple.stef.snap index 849fffa..fa1627f 100644 --- a/crates/stef-parser/tests/snapshots/parser__parse@struct_tuple.stef.snap +++ b/crates/stef-parser/tests/snapshots/parser__parse@struct_tuple.stef.snap @@ -13,7 +13,13 @@ Schema { Struct { comment: Comment( [ - "Basic struct.", + CommentLine { + value: "Basic struct.", + span: Span { + start: 0, + end: 17, + }, + }, ], ), attributes: Attributes(