aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/docs.rs22
-rw-r--r--crates/ide/src/hover.rs2
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 @@
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use either::Either; 8use either::Either;
9use syntax::ast; 9use itertools::Itertools;
10use syntax::{ast, SmolStr};
10 11
11use crate::{ 12use 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
106fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> { 107fn 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}
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; }
1525 --- 1525 ---
1526 1526
1527 bar docs 0 1527 bar docs 0
1528
1529 bar docs 1 1528 bar docs 1
1530
1531 bar docs 2 1529 bar docs 2
1532 "#]], 1530 "#]],
1533 ); 1531 );