diff options
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 47 |
1 files changed, 7 insertions, 40 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 18b9508ef..798fb7c13 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | use std::cmp::{max, min}; | ||
2 | |||
3 | use ra_db::SyntaxDatabase; | 1 | use ra_db::SyntaxDatabase; |
4 | use ra_syntax::{ | 2 | use ra_syntax::{ |
5 | AstNode, SyntaxNode, TextUnit, TextRange, | 3 | AstNode, SyntaxNode, TextUnit, TextRange, |
@@ -107,15 +105,13 @@ impl<'a> FnCallNode<'a> { | |||
107 | 105 | ||
108 | impl CallInfo { | 106 | impl CallInfo { |
109 | fn new(node: &ast::FnDef) -> Option<Self> { | 107 | fn new(node: &ast::FnDef) -> Option<Self> { |
110 | let mut doc = None; | 108 | let label: String = if let Some(body) = node.body() { |
111 | |||
112 | // Strip the body out for the label. | ||
113 | let mut label: String = if let Some(body) = node.body() { | ||
114 | let body_range = body.syntax().range(); | 109 | let body_range = body.syntax().range(); |
115 | let label: String = node | 110 | let label: String = node |
116 | .syntax() | 111 | .syntax() |
117 | .children() | 112 | .children() |
118 | .filter(|child| !child.range().is_subrange(&body_range)) | 113 | .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body |
114 | .filter(|child| ast::Comment::cast(child).is_none()) // Filter out doc comments | ||
119 | .map(|node| node.text().to_string()) | 115 | .map(|node| node.text().to_string()) |
120 | .collect(); | 116 | .collect(); |
121 | label | 117 | label |
@@ -123,16 +119,9 @@ impl CallInfo { | |||
123 | node.syntax().text().to_string() | 119 | node.syntax().text().to_string() |
124 | }; | 120 | }; |
125 | 121 | ||
126 | if let Some((comment_range, docs)) = extract_doc_comments(node) { | 122 | let mut doc = None; |
127 | let comment_range = comment_range | 123 | let docs = node.doc_comment_text(); |
128 | .checked_sub(node.syntax().range().start()) | 124 | if !docs.is_empty() { |
129 | .unwrap(); | ||
130 | let start = comment_range.start().to_usize(); | ||
131 | let end = comment_range.end().to_usize(); | ||
132 | |||
133 | // Remove the comment from the label | ||
134 | label.replace_range(start..end, ""); | ||
135 | |||
136 | // Massage markdown | 125 | // Massage markdown |
137 | let mut processed_lines = Vec::new(); | 126 | let mut processed_lines = Vec::new(); |
138 | let mut in_code_block = false; | 127 | let mut in_code_block = false; |
@@ -150,9 +139,7 @@ impl CallInfo { | |||
150 | processed_lines.push(line); | 139 | processed_lines.push(line); |
151 | } | 140 | } |
152 | 141 | ||
153 | if !processed_lines.is_empty() { | 142 | doc = Some(processed_lines.join("\n")); |
154 | doc = Some(processed_lines.join("\n")); | ||
155 | } | ||
156 | } | 143 | } |
157 | 144 | ||
158 | Some(CallInfo { | 145 | Some(CallInfo { |
@@ -164,26 +151,6 @@ impl CallInfo { | |||
164 | } | 151 | } |
165 | } | 152 | } |
166 | 153 | ||
167 | fn extract_doc_comments(node: &ast::FnDef) -> Option<(TextRange, String)> { | ||
168 | if node.doc_comments().count() == 0 { | ||
169 | return None; | ||
170 | } | ||
171 | |||
172 | let comment_text = node.doc_comment_text(); | ||
173 | |||
174 | let (begin, end) = node | ||
175 | .doc_comments() | ||
176 | .map(|comment| comment.syntax().range()) | ||
177 | .map(|range| (range.start().to_usize(), range.end().to_usize())) | ||
178 | .fold((std::usize::MAX, std::usize::MIN), |acc, range| { | ||
179 | (min(acc.0, range.0), max(acc.1, range.1)) | ||
180 | }); | ||
181 | |||
182 | let range = TextRange::from_to(TextUnit::from_usize(begin), TextUnit::from_usize(end)); | ||
183 | |||
184 | Some((range, comment_text)) | ||
185 | } | ||
186 | |||
187 | fn param_list(node: &ast::FnDef) -> Vec<String> { | 154 | fn param_list(node: &ast::FnDef) -> Vec<String> { |
188 | let mut res = vec![]; | 155 | let mut res = vec![]; |
189 | if let Some(param_list) = node.param_list() { | 156 | if let Some(param_list) = node.param_list() { |