Repository navigation
fix(canonical): keep a comment in an empty key beside its opener - #30
Merged
adammharris merged 1 commit intoNov 7, 2026
Merged
adammharris merged 1 commit into
adammharris merged 1 commit into
Conversation
An empty container prints inline and leaves its trailing comment to
whoever writes its line. An entry's line writes the value's trailing
comment, so when the empty container was the entry's key nothing wrote
its own: `{[//\n]:1}` lost the comment and canonical_round_trip failed.
The parser refuses a comment between a key and its `:`, so it cannot go
after the key's close.
The KeyValue arm now writes its key through `Printer::key`, which prints
an empty container holding a trailing comment as a block, the comment
beside the opener, where `capture_open_trailing` reads it back. The
JavaScript twin's printer lost the comment the same way and gets the same
`writeKey`, so the two still write one spelling. `{[//\n]:1}` joins
`canonical_seeds`, so every PR checks it.
Closes docs/tasks/a-comment-in-an-empty-key-container-is-dropped.md.
Behavioural-change: a line comment after the opening bracket of an empty container used as a mapping key in canonical text now prints beside that bracket, with the key written over two lines, in both the compiled format and `@diaryx/fig`'s canonical language. It used to be dropped without a word. `fig fmt` on a `.fig` file keeps such a comment.
adammharris
deleted the
agent/backlog-a-comment-in-an-empty-key-container-is-dropped
branch
November 7, 2026 16:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
rust/fig-core/src/canonical/printer.rs: theKeyValuearm writes its key through a newPrinter::key. An empty container holding a trailing comment prints as a block, with the comment beside its opener:bindings/typescript/js/canonical.js: the same change aswriteKey. The task did not name this file, but the JavaScript twin's printer lost the comment the same way, and a test showed it before the fix.rust/fig-fuzz/src/lib.rs:{[//\n]:1}joinscanonical_seeds.The task is marked done.
Why
An empty container prints inline and leaves its trailing comment to whoever writes its line. An entry's line writes the value's comment, so when the empty container was the key, nothing wrote its comment. It was lost silently and
canonical_round_tripfailed. The parser refuses a comment between a key and its:, so the comment can only go beside the opener, wherecapture_open_trailingreads it back.Closes
docs/tasks/a-comment-in-an-empty-key-container-is-dropped.md.Behavioural change
Canonical output changes for these inputs only: the key is written over two lines and the comment is kept. This is recorded in the commit's
Behavioural-change:trailer.How it was verified
a_comment_in_an_empty_container_used_as_a_key_stays_beside_its_openeranda_commented_empty_key_at_the_nesting_limit_printsinparser.rs, and a canonical twin test intwins.test.ts. All pass now. The first covers the task's three inputs plus{[// a\n]: {[// b\n]: 2}},{&x [// a\n]: 1}and a key nested inside a key.ship ci: all 11 jobs passed, withnode_modulesinstalled so the TypeScript suite ran for real (118 passed, 0 failed, 0 skipped).Not in the gate, and not clean on
maineither, in code this PR does not change:cargo clippy -D warningsstops on 18 errors infig-kitand flagscapture_open_trailinginparser.rs, andcargo fmt --checkreports diffs in other files.