Don't insert blank lines between doc attributes

This commit is contained in:
Lukas Wirth 2020-12-07 15:55:52 +01:00
parent 2ff1ebe8f3
commit 93262c750e
2 changed files with 11 additions and 13 deletions

View file

@ -6,7 +6,8 @@
use std::sync::Arc; use std::sync::Arc;
use either::Either; use either::Either;
use syntax::ast; use itertools::Itertools;
use syntax::{ast, SmolStr};
use crate::{ use crate::{
db::DefDatabase, db::DefDatabase,
@ -93,7 +94,7 @@ fn merge_doc_comments_and_attrs(
) -> Option<String> { ) -> Option<String> {
match (doc_comment_text, doc_attr_text) { match (doc_comment_text, doc_attr_text) {
(Some(mut comment_text), Some(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); comment_text.push_str(&attr_text);
Some(comment_text) Some(comment_text)
} }
@ -105,17 +106,16 @@ fn merge_doc_comments_and_attrs(
fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> { fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> {
let mut docs = String::new(); let mut docs = String::new();
for attr in owner.attrs() { owner
if let Some(("doc", value)) = .attrs()
attr.as_simple_key_value().as_ref().map(|(k, v)| (k.as_str(), v.as_str())) .filter_map(|attr| attr.as_simple_key_value().filter(|(key, _)| key == "doc"))
{ .map(|(_, value)| value)
docs.push_str(value); .intersperse(SmolStr::new_inline("\n"))
docs.push_str("\n\n"); // No FromIterator<SmolStr> for String
} .for_each(|s| docs.push_str(s.as_str()));
}
if docs.is_empty() { if docs.is_empty() {
None None
} else { } else {
Some(docs.trim_end_matches("\n\n").to_owned()) Some(docs)
} }
} }

View file

@ -1525,9 +1525,7 @@ fn foo() { let bar = Ba<|>r; }
--- ---
bar docs 0 bar docs 0
bar docs 1 bar docs 1
bar docs 2 bar docs 2
"#]], "#]],
); );