feat(derive): preserve verbatim doc comments - #949
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Central YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThe PR adds opt-in verbatim preservation for derived doc-comment metadata while retaining existing default formatting behavior.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (5): Last reviewed commit: "fix(derive): preserve verbatim continuat..." | Re-trigger Greptile |
Instruction countsNothing was compared, and so nothing was gated. No series appears on both sides: either the base has no measurements recorded, or the two were measured on different runner classes, which are deliberately not comparable — counts shift between machine types by more than a real regression does. New, nothing to compare against: Only instruction counts gate. Wall clock is shown for context — on identical hardware it moves 4-20% run to run. Measured by tak — instruction-counted CLI benchmarks, stored in this repository's git notes. Shadow comparisonParsing
|
73e64cb to
e2abbb5
Compare
e5e1446 to
641c80c
Compare
## Summary - add a usage-owned `usage_argv::ValueHint` for `value_hint` expressions - map `FilePath` and `AnyPath` to the spec's `type="path"`, and `DirPath` to `type="dir"` - carry hints through native `usage-argv` completion and emitted KDL - reject hints on valueless fields or alongside a custom completer - document and test file/directory completion behavior end to end Declarations use usage’s own hint type: ```rust #[usage(long, value_hint = usage_argv::ValueHint::FilePath)] ``` The hint type lives in `usage-argv`, the derive runtime a compiled CLI already uses. ## Stack Targets #949 and becomes the direct base for #936. ## Checks - `cargo test -p usage-conformance --test completion` - `cargo test -p usage-argv --features spec,complete` - `cargo test -p usage-derive` - `cargo test --all --all-features` - `cargo clippy --all --all-features --all-targets -- -D warnings` - `mise run render` _This PR was generated by Codex._ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Changes are limited to completion/spec metadata and derive codegen; parsing is unaffected and behavior is covered by conformance tests. > > **Overview** > Adds **`usage_argv::ValueHint`** (`FilePath`, `AnyPath`, `DirPath`) so `#[usage(value_hint = …)]` can declare filesystem completion without pulling in clap. > > The derive maps hints to spec vocabulary (`path` / `dir`), stores them on **`FlagMeta` / `ArgMeta`** as **`complete_type`**, and emits **`complete "…" type="…"`** blocks in KDL. Native completion now prefers that metadata (then still falls back to value-name heuristics like `<FILE>`). > > Compile-time guards reject **`value_hint`** on valueless fields and **`value_hint`** together with a custom **`complete`** function. Conformance tests cover bash markers, emitted KDL, and parsing unchanged. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 26fa455. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
…#965) Stacked on #963, the `usage-rs` facade. `usage` is now its own first adopter. Its command structs, root, and command enums use the `usage-rs` facade instead of Clap, and `--usage-spec` prints `Cli::to_kdl()` from the same tables that parsed the command line. ## What goes away - `clap`, `clap_usage`, and the `clap-sort` dev dependency - `tests/clap_sort.rs`; declaration order is held by the spec - the duplicated command-effect tables; effects now live on the commands they describe - the empty `Sponsors` struct; unit subcommands are supported directly - runtime checks for relationships the spec can express ## Migration shape The declarations remain close to their former Clap layout: - inferred shorts use `#[usage(short, long)]` - command aliases live on their command structs, e.g. `#[usage(alias = "c", alias_hidden("complete", "completions"))]` - positive dependencies use `requires`, including `--cache-key` → `--usage-cmd` and `--out-dir` → `--multi` - aliases written on enum variants still merge with struct aliases for compatibility - deliberately formatted docs keep `#[usage(verbatim_doc_comment)]` - path hints keep `value_hint = usage_rs::ValueHint::FilePath` or `DirPath` from usage’s own runtime type - subcommand payloads stay unboxed as they were under Clap; `Box<T>` remains an optional size optimization The four shell commands are separate derived structs flattening a shared group. A single destination struct cannot identify which enum variant selected it, so a macro keeps their common declaration in one place. ## Parity gaps closed by the stack - required subcommands survive KDL generation (#937) - strict unknown-flag behavior is inherited by subcommands (#939) - command-owned visible and hidden aliases are supported (#946) - duplicate non-repeatable flags are rejected (#945) - a missing required subcommand prints the available command choices (#947) - verbatim doc-comment layout is preserved on commands, fields, and variants (#949) - file and directory value hints reach native and emitted completions (#951) The emitted spec still intentionally gains metadata the Clap bridge dropped, including `JDX_USAGE_BIN` on `--usage-bin`, preserved multiline long help, the manpage description, and the correct binary name `usage`. ## Verification - `mise run render` - `cargo test --all --all-features` - `cargo clippy --all --all-features --all-targets -- -D warnings` - direct binary checks for no-argument help, duplicate flags, command aliases, and positive requirements _This PR was generated by Codex._ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes how the primary `usage` CLI is parsed and documented (including `--completions` UX), but behavior is covered by updated integration tests and is an intentional migration to the shipped parser. > > **Overview** > The **`usage` binary dogfoods `usage-rs`**: command structs use `#[derive(usage_rs::Cli)]` / `#[usage(...)]` instead of Clap, and **`--usage-spec` emits `Cli::to_kdl()`** from the same parse tables that handle argv. **Clap, `clap_usage`, and `clap-sort` are removed**, along with the post-hoc **`command_effects` patch table**—`effect`, `requires`, `overrides`, and similar metadata now live on the declarations. > > **Root CLI shape is corrected in spec and docs**: **`--completions <SHELL>` is a long flag** (not a positional), with an **explicit multi-line `usage` synopsis** for `usage <COMMAND>` / `--completions` / `--usage-spec`. Shell runner commands (`bash`, `fish`, `zsh`, `powershell`, `exec`) use **`unknown_flags = "value"`** so script arguments can include unknown flags. > > **Help and manpages** gain support for an optional root **`usage` string** on `Spec` (derive + KDL emission); root help/man synopsis prefer that over generated lines. Generated assets (`usage.usage.kdl`, `usage.1`, Fig spec, CLI reference markdown, snapshots) are refreshed to match. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3aba1aa. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added `--completions <SHELL>` for selecting a completion shell. * Improved command validation, aliases, defaults, environment settings, and file-output completion hints. * Shell commands now forward unrecognized arguments as script values. * Added clearer help text and descriptions for generation commands. * **Documentation** * Updated CLI references, manpages, usage specifications, and shell documentation to reflect revised options and behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Replaces #936 after flipping the facade and CLI layers. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Summary
#[usage(verbatim_doc_comment)]on root and command structs, fields, and subcommand variants///and outer blank linesThis keeps Clap declarations that use ASCII art, tables, examples, or deliberately formatted prose intact during migration.
Stack
Targets #947 and becomes the direct base for #936.
Checks
cargo test -p usage-conformance --test metadatacargo test -p usage-derivecargo test --all --all-featurescargo clippy --all --all-features --all-targets -- -D warningsmise run renderThis PR was generated by Codex.
Note
Low Risk
Changes are confined to derive-time help text extraction with default behavior preserved; risk is limited to help/spec wording, covered by new conformance tests.
Overview
Adds
#[usage(verbatim_doc_comment)]on root/Argsstructs, fields, and subcommand variants so doc comments can feed help/about text with intentional line breaks, blank lines, and indentation instead of flowing the first paragraph like prose.The derive’s
doc_commenthelper now takes a verbatim flag: default behavior is unchanged (first paragraph collapsed to one line for short help; multiline#[doc = "..."]still behaves as before). With verbatim, it strips only the usual///leading space and outer blank lines, then splits short help at the first blank line and keeps the full text for long help when there is more.Crate docs list the new option; conformance metadata tests cover root, flag, and subcommand specs plus ordinary vs verbatim multiline
#[doc]attributes.Reviewed by Cursor Bugbot for commit 641c80c. Bugbot is set up for automated code reviews on this repo. Configure here.