diff --git a/.gitignore b/.gitignore index 2e3d0f9..756c54b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ result tmp/ tests/.DS_Store .DS_Store + +# skills +.github/skills/* diff --git a/src/formatting.rs b/src/formatting.rs index e75fcae..7fff267 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -133,6 +133,20 @@ impl<'a> Formatter<'a> { self.write_span(expr.span); } + /// Write an attribute expression while preserving a leading '@' sigil. + fn write_attribute_span(&mut self, expr: &Expression) { + let mut start = expr.span.start; + + if start > 0 && self.source[start - 1] == b'@' { + start -= 1; + } + + self.write_span(Span { + start, + end: expr.span.end, + }); + } + // ───────────────────────────────────────────────────────────────────────────── // Comment handling // ───────────────────────────────────────────────────────────────────────────── @@ -383,7 +397,7 @@ impl<'a> Formatter<'a> { Expr::AttributeBlock(attr_block) => { for attr in &attr_block.attributes { - self.write_span(attr.expr.span); + self.write_attribute_span(&attr.expr); self.newline(); } self.format_expression(&attr_block.item); diff --git a/tests/fixtures/expected/issue100.nu b/tests/fixtures/expected/issue100.nu new file mode 100644 index 0000000..cce970d --- /dev/null +++ b/tests/fixtures/expected/issue100.nu @@ -0,0 +1,2 @@ +@category a +def a [] { } diff --git a/tests/fixtures/input/issue100.nu b/tests/fixtures/input/issue100.nu new file mode 100644 index 0000000..cce970d --- /dev/null +++ b/tests/fixtures/input/issue100.nu @@ -0,0 +1,2 @@ +@category a +def a [] { } diff --git a/tests/ground_truth.rs b/tests/ground_truth.rs index 300ed0b..360be8b 100644 --- a/tests/ground_truth.rs +++ b/tests/ground_truth.rs @@ -806,4 +806,5 @@ issue_fixture_tests!( ("issue94", issue94_test, idempotency_issue94_test), ("issue95", issue95_test, idempotency_issue95_test), ("issue97", issue97_test, idempotency_issue97_test), + ("issue100", issue100_test, idempotency_issue100_test), );