mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #6743
6743: Don't insert blank lines between doc attributes r=Veykril a=Veykril Fixes #6742. Doc attributes should be concatenated via a single linebreak as written in the [rustdoc book](https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html). Also changed the loop to use an iterator to get rid of the `docs.trim_end_matches("\n\n").to_owned()` part using `Itertools::intersperse`. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
9a88332452
2 changed files with 11 additions and 13 deletions
|
@ -6,7 +6,8 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use either::Either;
|
||||
use syntax::ast;
|
||||
use itertools::Itertools;
|
||||
use syntax::{ast, SmolStr};
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
|
@ -93,7 +94,7 @@ fn merge_doc_comments_and_attrs(
|
|||
) -> Option<String> {
|
||||
match (doc_comment_text, doc_attr_text) {
|
||||
(Some(mut comment_text), Some(attr_text)) => {
|
||||
comment_text.push_str("\n\n");
|
||||
comment_text.push_str("\n");
|
||||
comment_text.push_str(&attr_text);
|
||||
Some(comment_text)
|
||||
}
|
||||
|
@ -105,17 +106,16 @@ fn merge_doc_comments_and_attrs(
|
|||
|
||||
fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> {
|
||||
let mut docs = String::new();
|
||||
for attr in owner.attrs() {
|
||||
if let Some(("doc", value)) =
|
||||
attr.as_simple_key_value().as_ref().map(|(k, v)| (k.as_str(), v.as_str()))
|
||||
{
|
||||
docs.push_str(value);
|
||||
docs.push_str("\n\n");
|
||||
}
|
||||
}
|
||||
owner
|
||||
.attrs()
|
||||
.filter_map(|attr| attr.as_simple_key_value().filter(|(key, _)| key == "doc"))
|
||||
.map(|(_, value)| value)
|
||||
.intersperse(SmolStr::new_inline("\n"))
|
||||
// No FromIterator<SmolStr> for String
|
||||
.for_each(|s| docs.push_str(s.as_str()));
|
||||
if docs.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(docs.trim_end_matches("\n\n").to_owned())
|
||||
Some(docs)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1525,9 +1525,7 @@ fn foo() { let bar = Ba<|>r; }
|
|||
---
|
||||
|
||||
bar docs 0
|
||||
|
||||
bar docs 1
|
||||
|
||||
bar docs 2
|
||||
"#]],
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue