diff options
author | Lukas Wirth <[email protected]> | 2020-12-07 14:55:52 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-12-07 15:10:46 +0000 |
commit | 93262c750e65dcc58b9a87b9efdec55177269210 (patch) | |
tree | 2bc2686d7ae7250959208a159417432c4c1e7d76 | |
parent | 2ff1ebe8f3eb820e13e08f8cfbdac2f12a921e15 (diff) |
Don't insert blank lines between doc attributes
-rw-r--r-- | crates/hir_def/src/docs.rs | 22 | ||||
-rw-r--r-- | 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 @@ | |||
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 | } |
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 | ); |