-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect padding in doc comments #204
base: master
Are you sure you want to change the base?
Conversation
src/documentation/literal.rs
Outdated
@@ -111,13 +111,26 @@ impl CommentVariant { | |||
} | |||
} | |||
|
|||
#[derive(Clone, Hash, PartialEq)] | |||
pub enum Padding { | |||
Padding(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only have one content variant here, we might want to limit it to AsteriskSpace{ leading_spaces: usize }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, thanks! To make sure I'm understanding, for the string " * "
, it would be AsteriskSpace
with 1 for leading_spaces
or 3 to account for the whole string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of the two variants: Doc
and NonDoc
, the first might be a single span for now and hence contain all leading spaces as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be a separate enum or replace the current one? I updated the current enum to reflect your comments and the more specific variant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was misleading, sorry about that. I think we can represent both with the enum Padding
with the Asterisk*
variant.
Thanks for the feedback on this! I updated the branch with your comments, should this be incorporated into the |
I think, removing it at the span/syn/ra_ap_syntax stage will simplify later stages significantly (or: avoid additional code changes), so I'd recommend having a clean Note: There is a caveat that a few consecutive |
Great, thanks! Should this be in or before the Also, I think we'll need to bump the version of |
Whereever you see fit :) Bump deps as needed. |
I made some updates to reflect the recent feedback but it looks like I'm a bit stuck again. Should |
@@ -656,7 +730,7 @@ mod tests { | |||
block_comment_test!( | |||
trimmed_multi_doc, | |||
"/** | |||
mood | |||
* mood |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both variants should work, the *
should be optional.
let content = "/**\n doc\n doc\n */".to_string(); | ||
assert_matches!( | ||
detect_and_remove_padding(&content), | ||
(CommentPaddingStyle::NoPadding, content) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer smaller test cases, even if this has a compile time cost to it.
And I think we need a few more to cover the indented variants, as in multiple leading spaces before the asterisk.
assert_matches!( | ||
detect_and_remove_padding(&content), | ||
(CommentPaddingStyle::NoPadding, content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice use of assert_matches
:)
lazy_static! { | ||
static ref PADDING_STR: Regex = | ||
Regex::new(r##"(?m)^\s\*\s"##).expect("PADDING_STR regex compiles"); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#202 introduced an optimization to avoid the regex
entirely and use smid instructions as available, probably worth to hand roll this, but that can be done once you're confident of the structure - this is works and is good for the time being 👍
268ad24
to
03b0d5a
Compare
I think you have two options: Either replace
Just explaining this to you makes it clear that there is a lot of documentation missing and quite a few design joices are not obvious, and naming of things could be improved by quite a bit. Very much appreciate your effort! @pjsier let me know if there is anything else I can do to aid you driving this to completion :) |
@pjsier gentle ping :) |
@drahnr thanks for following up on this! I haven't had as much time as I would have liked, so if I'm holding anything up feel free to take over and thanks for all the input |
I think it's better if you push it over the finish line :) there is no particular rush here - take your time! |
What does this PR accomplish?
Closes #133.
Changes proposed by this PR:
Detect padding in doc comments with
CommentPaddingStyle
enumNotes to reviewer:
Adds enum and
detect_padding
method to parse and store padding style📜 Checklist
./demo
sub directory