Repository navigation
Harden our Check for Common-Leading-Whitespace in Doc-Comments - #829
Merged
InsertCreativityHere merged 3 commits intoSep 16, 2026
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Regression tests are needed for mixed ASCII, tab, and multibyte whitespace cases.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Hardens doc-comment indentation stripping against mixed and multibyte whitespace.
Changes:
- Computes the exact common whitespace prefix.
- Safely strips prefixes at UTF-8 boundaries.
File summaries
| File | Description |
|---|---|
slicec/src/parsers/comments/grammar.rs |
Implements prefix-based whitespace sanitization. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+106
to
+109
| common_leading_whitespace = Some(match common_leading_whitespace { | ||
| Some(current_whitespace) => get_common_prefix(current_whitespace, text), | ||
| None => get_leading_whitespace(text), | ||
| }); |
Member
Author
There was a problem hiding this comment.
I think this is minor and finicky enough to not warrant a test, if any other reviewers disagree, let me know and I will add a test using a mix of ASCII and non-ASCII whitespace at the start of doc-comment lines.
pepone
approved these changes
Sep 16, 2026
InsertCreativityHere
added a commit
that referenced
this pull request
Sep 16, 2026
(cherry picked from commit a4a6610)
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.
This PR is a code-hardening to handle doc-comments where a user has different kinds of whitespace at the starts of their doc-comment lines. It fixes #800.
It is common for users to have whitespace between a
///and the actual comment's text:We have code to detect this and strip it away from the comment's actual content.
The exact check is to determine the "common leading whitespace" and remove it; i.e. find the maximum amount of whitespace such that every line starts with at least that amount of whitespace.
However, this check isn't very exact right now. We currently only count the number of whitespace characters. So if I have a multiline comment, one starts with 2 spaces, and one starts with 2 tabs, we'd count those as the same amount of whitespace, which is wrong. If you have 2 spaces and 2 non-ASCII whitespace characters, this could ever cause a panic, since we're counting over bytes instead of unicode characters.
This PR changes this so we track the
whitespaceas an actualstr, not just acountof characters. We determine the largest substring such that:And like before, we strip it from every single line.
What's Changed
Nothing - this only affects doc-comments where an inconsistent kind of whitespace is used to pad the start of each line.
In practice, almost all users will use a consistent kind of whitespace padding.