Skip to content

fmt deletes all comments #87

Description

@danwt

specl fmt strips every comment from a spec. Format-on-save in the VSCode extension means a user loses all comments on first save.

Repro (v3.1.1)

$ grep -c '//' vault.specl     # 20
$ specl fmt vault.specl | grep -c '//'   # 0

Any spec with comments reproduces it. fmt --write and the extension's format-on-save have the same effect on disk.

Cause

Comments are lexed as trivia (specl-syntax/src/token.rs:438, is_trivia) and the AST-based formatter never reattaches them. No test asserts comment preservation.

Impact

The README and the expert-specl skill both recommend fmt --write, and the extension does format-on-save. With comment-stripping that is destructive. Worth fixing before recommending format-on-save anywhere.

Suggested fix

Preserve comment tokens (attach to adjacent AST nodes as leading/trailing trivia) and re-emit them in the pretty-printer, plus a round-trip test that a spec with comments is unchanged by fmt --check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions