allow multi line doc strings#57
Conversation
9aea6c3 to
1c1e8f0
Compare
|
I don't think this is correct: we definitely don't want newlines in Display impls. Allowing line wrapping seems good, though. What if we make a minimal change: allow multiline doc comments, but only when the lines are not empty (which creates a paragraph break in Markdown). In those cases, we still error as we do now. Separately, we can see what people think is the most logical choice in those cases. Perhaps we could have an attribute that lets you pick between "insert newline" or "ignore everything after the paragraph break". I don't know, but that's a more involve discussion that needs to happen, and I don't want to block getting the newline problem fixed on that. |
|
@Manishearth Makes sense! I went off of the example in #44, which used newlines. Off the top of my head, clap concatenates with spaces with multiple lines of doc comments, for example I believe argh also concatenates with spaces and rustdoc preserves line breaks |
|
To be clear, you are interested in what I have now with multiline doc comments, but error on empty lines, right? For example /// all
/// good!
struct CoolStruct;
/// multi paragraph
///
/// Not allowed
struct CoolStruct; |
|
Yes, and the first one should produce the string |
|
Ah! I wasn't on the same page there, is this in line with what you're thinking? 1.) Outputs "all good!" /// all
/// good!
struct CoolStruct;2.) error, multiline is not allowed /// multi paragraph
///
/// Not allowed
struct CoolStruct;3.) "multi paragraph" #[ignore_extra_doc_attributes]
/// multi paragraph
///
/// Not allowed
struct CoolStruct; |
|
correct! |
dc022d8 to
7726201
Compare
Updated! Fixed up the example and the documentation as well. Let me know if you have anything else you'd like changed |
7726201 to
d9a92b3
Compare
| #[derive(Display)] | ||
| /// Really fancy first line with thing: {thing} | ||
| /// Really cool second line | ||
| struct HappyMultiLine { |
There was a problem hiding this comment.
issue: please include a test for multiline attributes with ignore_extra_doc_attributes
d9a92b3 to
c500245
Compare
| #[derive(Display)] | ||
| #[ignore_extra_doc_attributes] | ||
| /// multi | ||
| /// line | ||
| /// | ||
| /// new paragraph should be ignored | ||
| struct HappyMultilineWithIgnore; |
There was a problem hiding this comment.
issue: please include a test for multiline attributes with ignore_extra_doc_attributes
Good callout! Here's a new test covering that case
Output is "multi line"
63ce708 to
e561494
Compare
| /** | ||
| * block | ||
| * comment | ||
| */ | ||
| /** | ||
| * block | ||
| * comment2 | ||
| */ | ||
| DoubleBlock, |
There was a problem hiding this comment.
I just added test cases for several other edge cases
Question—is it appropriate to concatenate sequential block comments with spaces?
This outputs "block\ncomment block\ncomment2"
There was a problem hiding this comment.
Just checking in if there's anything I'm missing to push this across the finish line. Please let me know if you'd like any changes!
There was a problem hiding this comment.
I'm on vacation right now and previously I had hit the limit of the amount of time I wanted to spend on an optional feature for displaydoc. I'll get around to this eventually.
There was a problem hiding this comment.
No problem. I appreciate the directness. Enjoy your vacation!
| } else { | ||
| strs.collect::<Option<Vec<_>>>() | ||
| }.unwrap_or_else(|| { | ||
| panic!("Line breaks in multi-line doc comments are disabled by default by displaydoc. Please consider using block doc comments (/** */) or adding the #[ignore_extra_doc_attributes] attribute to your type next to the derive"); |
There was a problem hiding this comment.
nit: should be double line breaks, i think, since single line breaks are now allowed.
Manishearth
left a comment
There was a problem hiding this comment.
Should be good with one nit
|
Actually I'll merge as is and fix up the panic message myself. Thanks! |
#44 requests multi line doc strings, and I've also wanted this myself, so figured may as well!
Since multiple doc comments caused a panic prior, this is backwards compatible. If
#[ignore_extra_doc_attributes]is there, the firstdocident continues to be displayed, otherwise each doc comment is joined by newlinesThe first doc comment is used as the span
closes #44