Skip to content

LSP formatting: format only the whitespace SATySFi throws away - #30

Merged
yasuo-ozu merged 16 commits into
mainfrom
lsp-format
Aug 31, 2026
Merged

yasuo-ozu merged 16 commits into
mainfrom
lsp-format

Conversation

@yasuo-ozu

Copy link
Copy Markdown
Owner

textDocument/formatting, plus the protocol-free format/format_auto the browser playground can call, and a crate::area module the completion half now shares.

The constraint is the language, not the effort available. SATySFi has four lexical areas and only program text discards whitespace; inside { … }, '< … > and ${ … } a run of spaces is a Token::Space and a newline a Token::Break, which reach the evaluator as inter-word glue and line-break opportunities. A formatter that "tidies" prose there silently re-renders the PDF. So the invariant is that no byte inside a text or math area — or inside any token's span — is ever altered.

It normalises five things, all bytes the lexer skips: trailing whitespace, the final newline, leading blank lines, runs of blank lines (capped at 2), and tabs in indentation. It does not re-indent, does not collapse interior spaces, and never inserts whitespace where none was written — each measured against the corpus rather than assumed.

Audited in five passes, and it needed them

Nine confirmed bugs were found after the initial implementation and are fixed here. The ones worth naming:

  • An unsound area-replay deviation. <[ … ]> pushed and popped a mode the lexer never changes, justified as a no-op "because Program onto Program" — true only if the two always pair, which nothing enforces. An unmatched one walked the replay out of a math area and the formatter rewrote bytes inside ${ … }.
  • lex_header split a CRLF across a token-span boundary, taking the \r and orphaning the \n. That capped blank runs one line short after a header, halved a \r\n at max_blank_lines: 0, and made a header-terminated file gain a blank line on every save.
  • Formatting was not idempotent under the options an ordinary VS Code save sends.
  • An empty contentChanges: [] silently forgot the document, leaving it unformattable and unhoverable until the next full change.
  • format_auto asked a parser a question about lexing — refusing files it could format, at ~18× the cost, and importing a stack overflow.

Three of those were introduced by earlier fixes in this branch and caught by a later audit lens rather than by the suite.

Coverage

The corpus sweep is the test that matters, and two classes of bug were structurally invisible to it — a program-whitespace rewrite, and anything CRLF (\r\n → \r is both a whitespace-only difference and idempotent). Both now have executable checks, plus a minimal_edit round-trip fuzz over the one component between the formatter and the client's buffer that nothing had exercised.

Behind the branch: ~2.9M differential fuzz cases against an instrumented copy of the real lexer, with the token stream identical in every one.

Version

0.1.6, not 0.1.5. A header token's span is one byte longer in a CRLF file, and 0.1.5 is already on crates.io with the old behaviour — main should not claim a version it no longer matches. Nothing is published by this PR.

Verified: cargo test --workspace 2503 passed; cargo clippy --workspace --all-targets exits 0. The one failure is the pre-existing LaTeX spacing test, which needs a TeX engine and which CI installs none of, so it skips there.

yasuo-ozu and others added 16 commits August 25, 2026 15:41
…ument cannot re-typeset it

`textDocument/formatting`, plus the protocol-free `format`/`format_auto` the
browser playground can call, and a `crate::area` module the completion half now
shares.

The constraint is the language, not the effort available. SATySFi has four
lexical areas and only program text discards whitespace; inside `{ … }`,
`'< … >` and `${ … }` the lexer turns a run of spaces into `Token::Space` and a
newline into `Token::Break`, which reach the evaluator as inter-word glue and
line-break opportunities, and the CJK adjacency rules decide where a line ends
from exactly those. A formatter that "tidies" prose there silently re-renders
the PDF. So the invariant is that no byte inside a text or math area — or
inside any token's span — is ever altered, and it is kept by construction: the
formatter replays the lexer's own mode stack over the token stream and rewrites
only the gaps that replay leaves in program text. A gap holding anything but
whitespace and `%` comments would mean the replay had drifted, and makes the
whole format decline rather than guess.

What it normalises is five things, all of them bytes the lexer skips: trailing
whitespace, the final newline, leading blank lines, runs of blank lines (capped
at 2), and tabs in indentation expanded to the columns they occupied. Four are
LSP `FormattingOptions` members and are honoured as such.

What it does NOT do is the scope decision, and it was measured rather than
assumed, over 99 corpus files and 24 111 lines:

  * it does not re-indent. Real SATySFi indents continuations by hand and the
    hand choice carries information a bracket counter cannot recover —
    `itemize.satyh` has a final argument line one step past its function with
    no bracket opened in between. Reproducing that is expression-level layout,
    not a whitespace pass.
  * it does not collapse runs of spaces. 1 380 of those lines carry an interior
    multi-space run and sampling finds alignment in essentially every case
    (`val font-cjk-gothic   : string * float * float`, `| f init []        =
    init`, the two-space gap before an end-of-line comment). Squeezing them
    would rewrite 5.7% of the corpus for no gain.
  * it never inserts whitespace where none was written. `let x=1` stays;
    inserting a space is the one whitespace edit that could re-tokenise a file.

A buffer that does not lex is declined (`null` on the wire, distinct from the
`[]` an already-tidy buffer gets). One that lexes but does not parse is
formatted normally — this reads tokens, not trees. Range formatting is not
advertised, because a range's own text does not say which area it starts in.
The server answers one edit narrowed to the bytes that differ rather than a
whole-document replacement.

`features.rs`'s private `Area`/`area_at` moved to `crate::area` unchanged
rather than being copied: completion and formatting now ask the same question
of the same table, and its doc comment records the two places the replay is
deliberately not one-for-one with the lexer (`Mode::Active`, and `<[ … ]>`).

One bug found while writing the tests and fixed here: `lex_header` swallows a
header's own line break into the token, so the gap after `@require:` starts at
column 0 and its first newline ends a BLANK line. Without accounting for that,
one extra blank line survived after every header in the corpus and nowhere
else (`the_blank_line_after_a_header_is_counted_from_the_right_place`).

Verified: `cargo test --workspace --no-fail-fast` — 2477 passed, 0 failed, 7
ignored, exit 0, in a checkout with `dist/fonts` and `dist/hash` both empty
(CI's own condition). `cargo clippy --workspace --all-targets` exits 0 with no
diagnostic in any changed file. `cargo build -p rustyfi-lsp --target
wasm32-unknown-unknown --no-default-features` still builds, which is what keeps
the formatter on the playground's side of the line.

The tests hold three properties on every fixture and on every corpus file:
an identical token stream (which IS meaning, since nothing downstream of
`rustyfi-syntax` reads anything else), byte-identical text and math regions
(asserted directly, over regions derived from token *kinds* rather than from
this module's own fold, so a bug in the fold cannot hide), and idempotence.
`a_formatter_that_collapsed_prose_would_fail_the_text_area_check` runs a
plausible-but-wrong formatter past the same checks and asserts the second one
rejects it, so the check is known to be able to fail. The sweep covers 162
0.0.6 files (87 change) and 47 0.1 files (1 changes), comparing 4 406 text/math
regions; every change was inspected and is one of the five documented
normalisations.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…wn default

`format_options` fell back to `crate::FormatOptions::default()` for every
member, and that default is `true` for all three of the optional ones. LSP
marks `trimTrailingWhitespace`, `insertFinalNewline` and `trimFinalNewlines`
optional, and the common clients send them ONLY when the user's corresponding
editor setting is on — VS Code's `files.trimTrailingWhitespace`,
`files.insertFinalNewline` and `files.trimFinalNewlines` all default to false,
and the client then omits the member rather than sending `false`; nvim is the
same. So an ordinary format-on-save arrives as `{"tabSize":4,
"insertSpaces":true}`, and reading that as "all three on" deleted trailing
whitespace and final newlines the user had explicitly turned off. Silence from
a client is not a request.

The library default is deliberately NOT collapsed into this. A playground or
`format_auto` caller passes no options because there is no client in the
picture, and "tidy everything" is right for them; here the silence belongs to
somebody and carries information. Only the two REQUIRED members still fall
back to the library default, and for a conforming client that fallback is
unreachable — it is there so a malformed request gets an answer rather than an
error.

The contract this produces is written down where the code is, because half of
it is not obvious: capping a run of blank lines and dropping a file's leading
blank lines are not LSP options at all, have no member to be absent, and so
apply whatever these flags say. The visible edge is at the end of a file —
with `trimFinalNewlines` off a six-newline tail still gets capped, so "off"
means this formatter does not collapse the tail to one newline, not that the
tail is untouched.

Also clamps `tabSize`, which is unbounded `uinteger` client input multiplied
into an allocation on a request an editor sends on every save: `tabSize:
40_000_000` on one tab-indented line produced a 120 MB `newText` in 0.45 s.
The bound is 256 — far past any editor's own tab stop, so no setting a user
could plausibly have chosen is clipped, while the worst case stays
proportional to the file.

Six wire tests, where before there was no test that omitted an optional member
and none that sent `insertFinalNewline` or `trimFinalNewlines` at all.
Falsified by restoring the old `true` fallback: three of them go red, and
`the_rules_that_are_not_lsp_options_apply_with_every_member_off` correctly
does not, since the flag does not govern it.

Verified: `cargo test -p rustyfi-lsp` green, exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… else

`rewrite_gap`'s comment arm trimmed unconditionally —

    Some(c) => format!("{lead}{}", rtrim(c)),

— while the blank-line arm four lines below guarded on
`!opts.trim_trailing_whitespace`. So `trimTrailingWhitespace: false` was obeyed
everywhere except after a `%`, which is exactly where a reader is most likely
to have lined something up.

The test named for this could not catch it. `every_lsp_option_can_be_turned_off`
asserts that with every rule off formatting is the identity, over a fixture
containing no `%` at all — so it passed against the one case its own name
claims. Its fixture now carries a comment line with trailing whitespace, which
is what makes the assertion mean what it says.

Falsified rather than assumed: with the fixture strengthened and the code fix
reverted the test fails (exit 101); with the fix it passes and
`cargo test -p rustyfi-lsp` is green, exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ming a guarantee it did not give

`area.rs` documented two deliberate divergences from the lexer's mode stack,
"both sound". The second was not.

A path literal is program text throughout and the lexer changes no mode for
it: the `'<'` arm emits `Token::BPath` and the `']'` arm `Token::EPath` with no
`push_mode`/`pop_mode` at all (`lexer.rs:712`, `:550`). This fold pushed
`Area::Program` on `BPath` and popped on `EPath`, justified as a no-op because
`Program` onto `Program` changes nothing — which holds only if the two always
pair, and NOTHING ENFORCES THAT. An unmatched `<[` is not a lex error. One of
them left the replay a level deeper than the lexer, and the next genuine closer
then popped the wrong entry, walking the replay out of a math or text area
early: in `${ \frac!( 1 <[ 2 )` the `)` pops the path's phantom `Program`
instead of the `(`'s, and the rest of the math reads as program text — so the
formatter rewrote bytes inside `${ … }`. The conservative twin was there too:
an unmatched `<[` leaves the replay stuck in a text area, so program
whitespace, including a missing final newline, was silently never formatted.

Both tokens are now ignored, and the replay is exact. One deliberate
divergence remains (`Active`), and its doc now states the bound that makes it
safe rather than asserting safety: the two stacks are never out of step by
more than that one entry, they re-synchronise at the end of every argument
list, and the divergence can only make `current` answer a TEXT area where the
lexer says `Active` — never `Program` where the lexer is in text or math,
which is the only direction either caller can be hurt by.

The bug predates this branch: it is inherited from `main`, where it also makes
completion offer inline-command names in math after an unmatched `<[`.

**The docs were overstated and are corrected.** `format.rs`'s module comment
and the README both said the text/math invariant is guaranteed by construction
from the area replay. It is not, and was not even before this fix: what
actually guarantees it is the span arithmetic in `program_gaps`, which can only
ever yield bytes the lexer skipped between two token spans. The area replay is
a second, weaker line. Both now say that.

**The corpus sweep could not see the failure it most needed to.** Its three
properties — same tokens, text areas byte-identical, idempotent — are each
insensitive to any rewrite confined to program whitespace, so a formatter
turned into a re-indenter passed all three. Two executable checks are added:
every differing byte is whitespace (squeeze both and compare), and indentation
is preserved verbatim. Measured before and after: with
`normalise_indent` replaced by a single space, all three sweeps now FAIL
(18 tests red) where all three passed before. The 0.1 sweep also gains the
`changed > 0` guard its 0.0.6 sibling had — only 1 of its 47 files is untidy,
so tidying one file would have made it a silent identity test.

Verified: `cargo test -p rustyfi-lsp` green, exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…dent

Scratch output from verifying that branch, not part of it.
…blank-line cap

A blank line was recognised by whether it RENDERED empty. With
`trim_trailing_whitespace` off, a line carrying a single space renders as that
space, so it counted as content and the run was never capped: five blank lines
with a space each survived where five genuinely empty ones capped to two.

That made an LSP flag silently disable a rule that has no LSP option of its
own — and the previous commit in this branch, which made an absent optional
member mean "off", turned it into what an ordinary VS Code format-on-save
gets. `server.rs`'s `format_options` states the opposite in as many words:
capping a run of blank lines and dropping a file's leading blank lines apply
whatever the client's flags say. That contract was mine and it was false; this
makes it true rather than softening the claim.

Blankness is a property of the INPUT line, not of how it renders, so it is now
read off the line's own content. Capping removes whole lines; the flag governs
what is stripped from the lines that remain — so with trimming off the run is
capped AND the survivors keep their space, which is what the client asked for
on both counts.

Falsified: with `is_blank` read back off the rendered text the new test fails
(exit 101) and nothing else does. `cargo test -p rustyfi-lsp` exit 0, corpus
sweeps included — they exercise the blank-line counter over 209 files.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… the final newline being counted from the wrong side

Four confirmed bugs, one root cause. `lex_header` consumed exactly ONE break
character, so a CRLF was split across a TOKEN SPAN BOUNDARY — the `\r` inside
the header token, the `\n` orphaned in the gap after it. Everything downstream
that reasoned about "the byte before this gap" then saw a lone `\r` with an
orphan `\n`, and:

  * a blank run after a CRLF header capped one line short, because `split_gap`
    read that `\n` as ending a blank line of its own;
  * at `max_blank_lines: 0` the `\n` was deleted outright, leaving a bare `\r`
    — a mixed-ending file written by the formatter;
  * a file whose last token is a header gained a blank line and `format` was
    not idempotent, because `insert_final_newline` judged by the gap alone and
    the terminator was inside the token's span.

`lex_header` now takes both halves or neither. That fixes the first two at the
source and, just as importantly, makes `at_line_start` UNAMBIGUOUS: it now
really does mean "the byte before this gap is a complete terminator". An
earlier attempt at the third bug used that flag while the pair could still be
split, and turned `\r\n` into a bare `\r` — strictly worse than the bug. With
the lexer sound the same fix is correct, and the trim path also stops one
newline late no longer.

The fourth is independent and needed a judgement. Trimming a whitespace-only
line between a lone `\r` and a following `\n` makes the two adjacent, and
`\r\n` is ONE break — so three logical lines came back as two. No byte can be
inserted that keeps them apart, so the line is kept untrimmed instead. That is
the trade this formatter's licence implies: it may remove INSIGNIFICANT
whitespace, and a line is not insignificant. Reachable only where a Classic-Mac
`\r` sits beside a Unix `\n` in one file, which is why no corpus file found it.

Three regression tests, each covering all the line endings rather than the one
that happened to break — the header bug was NOT uniform across them, and CRLF
was accidentally correct before, which is precisely how it survived. The
line-break count is asserted rather than the exact bytes for the fusion case,
with uniform-ending controls that must still trim normally.

Verified: `cargo test --workspace` 2489 passed. Two failures are unrelated to
this change — the pre-existing LaTeX spacing test (identical at de6e39d, and
CI never runs it because it installs no TeX), and a doctest that fails only
because this checkout's rustup `ld.lld` shim points at a garbage-collected nix
store path; it passes once `RUSTDOCFLAGS="-C linker-features=-lld"` reaches
rustdoc.

NOTE for release: this changes `rustyfi-syntax`'s lexer, and a header token's
span now includes both CRLF bytes. 0.1.5 is already published, so this wants a
0.1.6 rather than a quiet amend.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…nd clamp tab_size for library callers too

Two findings from a differential fuzz over ~4.3M source/version pairs.

**The fusion guard had a hole, and it was mine.** The guard added one commit
ago asked `out.ends_with('\r')` — only the `\r` this gap had already written.
For a gap's FIRST line nothing has been emitted yet, so the candidate `\r` is
the last byte of the PRECEDING TOKEN'S SPAN, and `lex_header` leaves a bare one
there whenever the next byte is not `\n`. Trimming the whitespace between then
let the gap's own `\n` complete it:

    "@import: p\r  \nlet x = 1\n"  ->  "@import: p\r\nlet x = 1\n"

Three line breaks became two, and — worse than the lost line — a byte APPEARED
INSIDE A TOKEN'S SPAN, which is the one thing this module may never do. Not
exotic: 158 of the 273 bundled sources reproduce it when saved with CR endings.

The caller already reads the byte before the gap to compute `at_line_start`; it
just threw away WHICH break it was. `Where` now carries that, and the guard
consults the token span when the gap has written nothing yet. Headers are the
only exposure — verified over the corpus plus 800k generated buffers, the only
token kinds that can end at a bare `\r` before a program gap are the five
header kinds.

**`tab_size` is now clamped in the library, not only at the protocol
boundary.** `FormatOptions::tab_size` is a plain public `usize` and the wasm
playground calls `format` directly, so an editor setting can arrive unmediated
by `server.rs`. Unclamped that is not a large output but a dead process:
`usize::MAX / 2` aborts with an allocation failure no caller can catch, and
`col + tab` overflows near `usize::MAX`. On wasm32 `usize` is 32-bit, so both
arrive sooner and a panic there poisons the module instance. `server.rs` now
DERIVES its ceiling from the library's rather than keeping a second copy —
two constants for one field would be a difference nobody could explain.

Falsified, both: reverting the guard to `out.ends_with('\r')` reddens the new
fusion test, while the sibling `trimming_never_fuses_two_line_breaks_into_one`
correctly survives it, because that case's `\r` really is in the gap; reverting
the clamp to `.max(1)` reddens the tab-size test alone.

Verified: `cargo test --workspace` 2495 passed. The single failure is the
pre-existing LaTeX spacing test — identical at de6e39d, needs a TeX engine, and
CI installs none so it has never run there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…pty change list forgetting the file

Two independent findings, both reachable on an ordinary editor's ordinary day.

**Formatting was not idempotent under the options VS Code actually sends.**
`insert_final_newline` appended its terminator AFTER the blank-run cap had run.
The gap's last line has no terminator of its own, so it was never a blank line
— and the appended `\n` then made it one, which only the NEXT format capped
away:

    "let x = 1\n\n\n\n   "  ->  "let x = 1\n\n\n   \n"  ->  "let x = 1\n\n\n"

Two consecutive saves of an untouched file produced two different files. The
cap now counts the terminator this pass is about to add, so it sees the line
now rather than one save later.

The trigger is `files.insertFinalNewline` on with `files.trimTrailingWhitespace`
absent — and absent means off since this branch made it so, which is what put
the combination on the default path. The suite could not see it: its only
idempotence check runs `FormatOptions::default()`, all flags on, where the
whitespace-only last line is trimmed to nothing; and the one test that turns
trimming off also turns `insert_final_newline` off, precisely the pairing that
hides it.

**An empty `contentChanges: []` silently forgot the document.**
`full_replacement` answered one `Option<&str>` in which `None` meant "what you
hold is stale, drop it". That is right for a ranged change under a Full-sync
agreement and wrong for an empty list, where nothing changed and the server's
copy is still exactly the client's — a client sends one after an undo that
restores the saved text. The document then answered `null` to formatting and
to every cursor feature, and published no diagnostics, until the next full
change arrived.

Three outcomes now have three names (`Change::Full`/`Nothing`/`Unreadable`)
rather than two sharing one, and the no-op arm keeps the buffer and sends
nothing, leaving the diagnostics on screen — they still describe the file. The
new wire test asserts the ranged case in the same session, because the fix is
exactly that the two stop sharing an answer.

Falsified, separately: restoring `!line.term.is_empty()` reddens the
idempotence test alone; returning `Unreadable` for an empty list reddens the
wire test alone.

Verified: `cargo test --workspace` 2497 passed. The one failure is the
pre-existing LaTeX spacing test — identical at de6e39d, needs a TeX engine, and
CI installs none.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… the CRLF span invariant

Three findings from the audit round, none of them in the formatter's own
arithmetic.

**`format_auto` asked a parser a question about lexing.** It deferred to
`detect_version` so that formatting and diagnostics could not disagree about a
file's grammar — a good instinct applied to the wrong question. Diagnostics
need a TREE; formatting needs a TOKEN STREAM. Going through the parser cost:

  * files that lex were REFUSED. `detect_version` picks by furthest parse
    progress, and a 0.0.6 lex failure can out-reach a 0.1 parse failure, so
    `let x = A.B.C` (0.1's `LongUpper`, a hard 0.0.6 lex error) detected as
    0.0.6 and the server answered "unformattable" for a file it formats
    perfectly;
  * two full parses on every save — 101 ms against 5.7 ms for `format` itself
    on a mid-typing buffer, now measured at 1.03x rather than ~18x;
  * a stack overflow imported from the recursive-descent parser into a
    function that walks a `Vec` and survives inputs 100x deeper.

It now tries the generation the HEADERS name and falls back to the other,
taking whichever lexes — `format` already answers `None` for a buffer that
does not lex, so the fallback IS the test and no separate pass is needed. The
two can now disagree in the narrow case where a buffer lexes as one generation
and parses further as the other, and that is the right way round: a formatter
that works on a file the diagnostics are confused about beats one that refuses
it.

**One range trim, not two.** `symbols` trimmed trailing whitespace off a span
and `analysis` did not, so the same header rendered differently depending on
which asked — and after `lex_header` began taking both CRLF bytes, a lex error
on `@stage:` reported `0:0..1:0`, a width describing the terminator rather than
the header. The loop moves to `line_index::trim_trailing_ws` with the reasoning
`symbols` already had, and both call it. A span that is entirely whitespace
still collapses to degenerate and is widened, which is right for it too.

**The CRLF span invariant is now enforced rather than asserted in prose.**
`rewrite_gap` reads `at_line_start` as "the byte before this gap is a COMPLETE
terminator", which is only true while no token span stops half way through a
`\r\n`. Nothing checked it, and one new lexer rule consuming a single break
re-arms the corruption silently. The new test CRLF-ifies every corpus file and
walks every span under both grammars; reverting the `lex_header` fix makes it
name the file, the token and the byte.

Verified: `cargo test --workspace` 2499 passed. The one failure is the
pre-existing LaTeX spacing test — identical at de6e39d, needs a TeX engine, and
CI installs none.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… and the corpus under CRLF

Both gaps were named by the audits rather than guessed at, and both are places
a bug would reach the user's file rather than merely produce odd whitespace.

**`minimal_edit` had never been exercised.** It is the last link between a
correct `format` output and the client's buffer, and a wrong cut there does not
tidy anything — it silently deletes text. The property that matters could not
be stated against it, because it returns a `Value` carrying a UTF-16
line/character range, so the arithmetic is split out as `minimal_edit_span`
returning byte offsets and the test asserts what an editor would actually do:
`old[..start] + new[start..new_end] + old[old_end..] == new`, plus that neither
cut lands inside a character in EITHER string.

The generator matters more than the count here. A first version ran 200 000
cases and a mutation that rounds the suffix cut the WRONG WAY survived all of
them — because every character in its alphabet began and ended distinctly, so
every cut landed on a boundary anyway and the rounding was unobservable. `あ`
(E3 81 82) and `も` (E3 82 82) share a trailing byte without being the same
character, which is exactly what makes the byte-wise suffix scan stop in the
middle of one; `🎉`/`🎊` are the astral version. With the pair in, both
mutations die — the missing `floor_boundary` on the prefix, and the inverted
rounding on the suffix.

**The corpus was never formatted with CRLF endings**, and the existing sweep is
structurally incapable of noticing: its three properties are each blind to this
class. Same tokens — `\r\n` and `\r` lex alike. Text areas byte-identical — the
damage is in program gaps. Idempotent — halving a `\r\n` is a fixed point once
done. That is how `stdja.satyh` could lose a blank line after its last
`@require:`, 17225 bytes to 17223, with every property still holding.

So the new sweep asserts the thing the LF sweep does not need: a CRLF file must
format to exactly what its LF twin formats to, modulo the endings. That covers
any rule which counts, deletes or fuses a line break differently depending on
how the line ends — the whole class, not the instances found so far. Reverting
the `lex_header` fix makes it name the file and the generation.

Verified: `cargo test --workspace` 2501 passed. The one failure is the
pre-existing LaTeX spacing test — identical at de6e39d, needs a TeX engine, and
CI installs none.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`lex_header` now takes both halves of a CRLF, so a header token's SPAN is one
byte longer in a CRLF file. `rustyfi-syntax` 0.1.5 is on crates.io with the old
behaviour, and leaving `main` claiming 0.1.5 would mean a build from source and
a build from the registry disagree about token spans under the same version
number.

Not a release — nothing is published here. This only stops the working tree
from asserting a version it no longer matches.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@yasuo-ozu
yasuo-ozu merged commit 9d3b6a6 into main Aug 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant