Extensions (Verso documentation)
By default, Canolean refuses Verso documentation comments (set_option doc.verso true or doc.verso.module true). Pass --ext verso to enable formatting for them.
With --ext verso, every Verso-documented file in Lean 4.36.0 is accepted (adding 59 files across Std, Init, Lake, and Lean). When the flag is off, the extension does not run.
Example
Given Counter.lean:
set_option doc.verso true
structure Counter where
/--
Current value:
* non-negative
* starts at `0`
* incremented by `step`
-/
value : Nat
Without --ext verso:
$ canolean --bundled-only Counter.lean
canolean: unsupported: command 2: syntax node Lean.Parser.Command.versoCommentBody
With --ext verso, canolean --bundled-only --ext verso Counter.lean prints:
set_option doc.verso true
structure Counter where
/--
Current value:
* non-negative
* starts at `0`
* incremented by `step`
-/
value : Nat
How the Verso extension works
- Each Verso comment is re-indented verbatim to its target column, preserving the author’s prose and tight lists (just as Canolean preserves non-Verso documentation bodies). Only if verbatim re-indentation cannot preserve the Verso syntax tree at the target column does it fall back to Lean 4.36.0’s
Lean.Doc.Parser.versoDocumentToString. - The resulting comment is re-parsed in Lean at its target column. If the
versoCommentBodysyntax tree changes or fails to parse, the file is refused. - Indented multi-line Verso comments are pinned to their target column with
layout_core::Guard::ColIs, which is checked bylayout_core::verifiedand proved sound inproofs/LayoutProofs.lean.
Rust API
Driver extensions implement the canolean::ext::Extension trait to handle opaque syntax nodes without changing the verified core. From Rust, attach the Verso extension with:
let formatter = Formatter::new()?.with_extensions(Extensions::new().with(VersoExtension::new()));
Use VersoExtension::verbatim() if you only want to accept column-invariant Verso comments without re-indenting them.