diff options
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index c445d4fa1..d73c5bc31 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ra_db::{Cancelable, SyntaxDatabase}; | 1 | use ra_db::{Cancelable, SyntaxDatabase}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | AstNode, SyntaxNode, TreeArc, | 3 | AstNode, SyntaxNode, TreeArc, |
4 | ast::{self, NameOwner}, | 4 | ast::self, |
5 | algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, | 5 | algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, |
6 | }; | 6 | }; |
7 | 7 | ||
@@ -137,48 +137,29 @@ impl NavigationTarget { | |||
137 | fn description(&self, db: &RootDatabase) -> Option<String> { | 137 | fn description(&self, db: &RootDatabase) -> Option<String> { |
138 | // TODO: After type inference is done, add type information to improve the output | 138 | // TODO: After type inference is done, add type information to improve the output |
139 | let node = self.node(db)?; | 139 | let node = self.node(db)?; |
140 | // TODO: Refactor to be have less repetition | 140 | |
141 | fn visit_node<T>(node: &T, label: &str) -> Option<String> | ||
142 | where | ||
143 | T: ast::NameOwner + ast::VisibilityOwner, | ||
144 | { | ||
145 | let mut string = node | ||
146 | .visibility() | ||
147 | .map(|v| format!("{} ", v.syntax().text())) | ||
148 | .unwrap_or_default(); | ||
149 | string.push_str(label); | ||
150 | node.name()?.syntax().text().push_to(&mut string); | ||
151 | Some(string) | ||
152 | } | ||
153 | |||
141 | visitor() | 154 | visitor() |
142 | .visit(|node: &ast::FnDef| { | 155 | .visit(|node: &ast::FnDef| visit_node(node, "fn ")) |
143 | let mut string = "fn ".to_string(); | 156 | .visit(|node: &ast::StructDef| visit_node(node, "struct ")) |
144 | node.name()?.syntax().text().push_to(&mut string); | 157 | .visit(|node: &ast::EnumDef| visit_node(node, "enum ")) |
145 | Some(string) | 158 | .visit(|node: &ast::TraitDef| visit_node(node, "trait ")) |
146 | }) | 159 | .visit(|node: &ast::Module| visit_node(node, "mod ")) |
147 | .visit(|node: &ast::StructDef| { | 160 | .visit(|node: &ast::TypeDef| visit_node(node, "type ")) |
148 | let mut string = "struct ".to_string(); | 161 | .visit(|node: &ast::ConstDef| visit_node(node, "const ")) |
149 | node.name()?.syntax().text().push_to(&mut string); | 162 | .visit(|node: &ast::StaticDef| visit_node(node, "static ")) |
150 | Some(string) | ||
151 | }) | ||
152 | .visit(|node: &ast::EnumDef| { | ||
153 | let mut string = "enum ".to_string(); | ||
154 | node.name()?.syntax().text().push_to(&mut string); | ||
155 | Some(string) | ||
156 | }) | ||
157 | .visit(|node: &ast::TraitDef| { | ||
158 | let mut string = "trait ".to_string(); | ||
159 | node.name()?.syntax().text().push_to(&mut string); | ||
160 | Some(string) | ||
161 | }) | ||
162 | .visit(|node: &ast::Module| { | ||
163 | let mut string = "mod ".to_string(); | ||
164 | node.name()?.syntax().text().push_to(&mut string); | ||
165 | Some(string) | ||
166 | }) | ||
167 | .visit(|node: &ast::TypeDef| { | ||
168 | let mut string = "type ".to_string(); | ||
169 | node.name()?.syntax().text().push_to(&mut string); | ||
170 | Some(string) | ||
171 | }) | ||
172 | .visit(|node: &ast::ConstDef| { | ||
173 | let mut string = "const ".to_string(); | ||
174 | node.name()?.syntax().text().push_to(&mut string); | ||
175 | Some(string) | ||
176 | }) | ||
177 | .visit(|node: &ast::StaticDef| { | ||
178 | let mut string = "static ".to_string(); | ||
179 | node.name()?.syntax().text().push_to(&mut string); | ||
180 | Some(string) | ||
181 | }) | ||
182 | .accept(&node)? | 163 | .accept(&node)? |
183 | } | 164 | } |
184 | } | 165 | } |