diff options
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/docs.rs | 22 |
1 files changed, 11 insertions, 11 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 @@ | |||
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | use either::Either; | 8 | use either::Either; |
9 | use syntax::ast; | 9 | use itertools::Itertools; |
10 | use syntax::{ast, SmolStr}; | ||
10 | 11 | ||
11 | use crate::{ | 12 | use crate::{ |
12 | db::DefDatabase, | 13 | db::DefDatabase, |
@@ -93,7 +94,7 @@ fn merge_doc_comments_and_attrs( | |||
93 | ) -> Option<String> { | 94 | ) -> Option<String> { |
94 | match (doc_comment_text, doc_attr_text) { | 95 | match (doc_comment_text, doc_attr_text) { |
95 | (Some(mut comment_text), Some(attr_text)) => { | 96 | (Some(mut comment_text), Some(attr_text)) => { |
96 | comment_text.push_str("\n\n"); | 97 | comment_text.push_str("\n"); |
97 | comment_text.push_str(&attr_text); | 98 | comment_text.push_str(&attr_text); |
98 | Some(comment_text) | 99 | Some(comment_text) |
99 | } | 100 | } |
@@ -105,17 +106,16 @@ fn merge_doc_comments_and_attrs( | |||
105 | 106 | ||
106 | fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> { | 107 | fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> { |
107 | let mut docs = String::new(); | 108 | let mut docs = String::new(); |
108 | for attr in owner.attrs() { | 109 | owner |
109 | if let Some(("doc", value)) = | 110 | .attrs() |
110 | attr.as_simple_key_value().as_ref().map(|(k, v)| (k.as_str(), v.as_str())) | 111 | .filter_map(|attr| attr.as_simple_key_value().filter(|(key, _)| key == "doc")) |
111 | { | 112 | .map(|(_, value)| value) |
112 | docs.push_str(value); | 113 | .intersperse(SmolStr::new_inline("\n")) |
113 | docs.push_str("\n\n"); | 114 | // No FromIterator<SmolStr> for String |
114 | } | 115 | .for_each(|s| docs.push_str(s.as_str())); |
115 | } | ||
116 | if docs.is_empty() { | 116 | if docs.is_empty() { |
117 | None | 117 | None |
118 | } else { | 118 | } else { |
119 | Some(docs.trim_end_matches("\n\n").to_owned()) | 119 | Some(docs) |
120 | } | 120 | } |
121 | } | 121 | } |