Conversation
Introduce `comfort`, a new contrib tool that reformats Rust doc-comment blocks (`///` and `//!`) using semantic line breaks — one sentence per line — with an optional `--max-width` safety net. The tool ships as two binaries that share a single entry-point: `comfort` (invoked directly) and `cargo-comfort` (a cargo subcommand). Direct invocation without paths defaults to stdin/stdout; `cargo comfort` defaults to walking the current workspace. The pipeline runs in three layers: - **extract**: tokenises Rust source via `ra-ap-rustc_lexer`, finding maximal runs of consecutive `///` / `//!` lines and collecting their indentation, style, and body text. - **format**: parses each block's body with `comrak`, identifies top-level paragraph spans, and hands their text to the reflow step. All other markdown structure — reference link definitions, block quotes, lists, code blocks, headings — is preserved verbatim. - **sentence**: splits paragraphs into individual sentences using UAX #29 (`unicode-segmentation`), with abbreviation-aware merging and inline-token protection (URLs, code spans, markdown links) via regex placeholders, then width-wraps each sentence with `textwrap`. A `fmt-comments-ci` just task is added to the CI pipeline: ``` comfort --check --workspace ``` It exits non-zero and prints a unified diff for any file that would be reformatted, integrating with the existing CI matrix. Signed-off-by: Jean Mertz <git@jeanmertz.com>
comfort doc-comment formatter crate…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
…ents Signed-off-by: Jean Mertz <git@jeanmertz.com>
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.
Introduce
comfort, a new contrib tool that reformats Rust doc-comment blocks (///and//!) using semantic line breaks — one sentence per line — with an optional--max-widthsafety net.The tool ships as two binaries that share a single entry-point:
comfort(invoked directly) andcargo-comfort(a cargo subcommand). Direct invocation without paths defaults to stdin/stdout;cargo comfortdefaults to walking the current workspace.The pipeline runs in three layers:
ra-ap-rustc_lexer, finding maximal runs of consecutive//////!lines and collecting their indentation, style, and body text.comrak, identifies top-level paragraph spans, and hands their text to the reflow step. All other markdown structure — reference link definitions, block quotes, lists, code blocks, headings — is preserved verbatim.unicode-segmentation), with abbreviation-aware merging and inline-token protection (URLs, code spans, markdown links) via regex placeholders, then width-wraps each sentence withtextwrap.A
fmt-comments-cijust task is added to the CI pipeline:It exits non-zero and prints a unified diff for any file that would be reformatted, integrating with the existing CI matrix.