From 93262c750e65dcc58b9a87b9efdec55177269210 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Dec 2020 15:55:52 +0100 Subject: Don't insert blank lines between doc attributes --- crates/hir_def/src/docs.rs | 22 +++++++++++----------- crates/ide/src/hover.rs | 2 -- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/hir_def/src/docs.rs b/crates/hir_def/src/docs.rs index e9a02b11b..3e59a8f47 100644 --- a/crates/hir_def/src/docs.rs +++ b/crates/hir_def/src/docs.rs @@ -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 { 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 { 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 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) } } diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 462f5c2b8..dc9621f46 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -1525,9 +1525,7 @@ fn foo() { let bar = Ba<|>r; } --- bar docs 0 - bar docs 1 - bar docs 2 "#]], ); -- cgit v1.2.3