aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/hover.rs45
1 files changed, 2 insertions, 43 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 91d8e2ffa..bd3b1e396 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,6 +1,6 @@
1use ra_db::SourceDatabase; 1use ra_db::SourceDatabase;
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeParamsOwner}, 3 AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner},
4 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, 4 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}},
5}; 5};
6 6
@@ -177,47 +177,6 @@ impl NavigationTarget {
177 // TODO: After type inference is done, add type information to improve the output 177 // TODO: After type inference is done, add type information to improve the output
178 let node = self.node(db)?; 178 let node = self.node(db)?;
179 179
180 // FIXME: This is copied from `structure.rs` and should probably
181 // be moved somewhere common
182 fn collapse_ws(node: &SyntaxNode, output: &mut String) {
183 let mut can_insert_ws = false;
184 for line in node.text().chunks().flat_map(|chunk| chunk.lines()) {
185 let line = line.trim();
186 if line.is_empty() {
187 if can_insert_ws {
188 output.push_str(" ");
189 can_insert_ws = false;
190 }
191 } else {
192 output.push_str(line);
193 can_insert_ws = true;
194 }
195 }
196 }
197
198 // FIXME: This is also partially copied from `structure.rs`
199 fn visit_fn(node: &ast::FnDef) -> Option<String> {
200 let mut detail =
201 node.visibility().map(|v| format!("{} ", v.syntax().text())).unwrap_or_default();
202
203 detail.push_str("fn ");
204
205 node.name()?.syntax().text().push_to(&mut detail);
206
207 if let Some(type_param_list) = node.type_param_list() {
208 collapse_ws(type_param_list.syntax(), &mut detail);
209 }
210 if let Some(param_list) = node.param_list() {
211 collapse_ws(param_list.syntax(), &mut detail);
212 }
213 if let Some(ret_type) = node.ret_type() {
214 detail.push_str(" ");
215 collapse_ws(ret_type.syntax(), &mut detail);
216 }
217
218 Some(detail)
219 }
220
221 fn visit_node<T>(node: &T, label: &str) -> Option<String> 180 fn visit_node<T>(node: &T, label: &str) -> Option<String>
222 where 181 where
223 T: NameOwner + VisibilityOwner, 182 T: NameOwner + VisibilityOwner,
@@ -230,7 +189,7 @@ impl NavigationTarget {
230 } 189 }
231 190
232 visitor() 191 visitor()
233 .visit(visit_fn) 192 .visit(crate::completion::function_label)
234 .visit(|node: &ast::StructDef| visit_node(node, "struct ")) 193 .visit(|node: &ast::StructDef| visit_node(node, "struct "))
235 .visit(|node: &ast::EnumDef| visit_node(node, "enum ")) 194 .visit(|node: &ast::EnumDef| visit_node(node, "enum "))
236 .visit(|node: &ast::TraitDef| visit_node(node, "trait ")) 195 .visit(|node: &ast::TraitDef| visit_node(node, "trait "))