diff options
Diffstat (limited to 'crates/ra_ide_api/src/hover.rs')
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 200b57679..24b161c5c 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -3,12 +3,9 @@ | |||
3 | use hir::{Adt, HasSource, HirDisplay}; | 3 | use hir::{Adt, HasSource, HirDisplay}; |
4 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | algo::{ | 6 | algo::{ancestors_at_offset, find_covering_element, find_node_at_offset}, |
7 | ancestors_at_offset, find_covering_element, find_node_at_offset, | ||
8 | visit::{visitor, Visitor}, | ||
9 | }, | ||
10 | ast::{self, DocCommentsOwner}, | 7 | ast::{self, DocCommentsOwner}, |
11 | AstNode, | 8 | match_ast, AstNode, |
12 | }; | 9 | }; |
13 | 10 | ||
14 | use crate::{ | 11 | use crate::{ |
@@ -178,37 +175,45 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
178 | } | 175 | } |
179 | } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { | 176 | } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { |
180 | if let Some(parent) = name.syntax().parent() { | 177 | if let Some(parent) = name.syntax().parent() { |
181 | let text = visitor() | 178 | let text = match_ast! { |
182 | .visit(|node: ast::StructDef| { | 179 | match parent { |
183 | hover_text(node.doc_comment_text(), node.short_label()) | 180 | ast::StructDef(it) => { |
184 | }) | 181 | hover_text(it.doc_comment_text(), it.short_label()) |
185 | .visit(|node: ast::EnumDef| hover_text(node.doc_comment_text(), node.short_label())) | 182 | }, |
186 | .visit(|node: ast::EnumVariant| { | 183 | ast::EnumDef(it) => { |
187 | hover_text(node.doc_comment_text(), node.short_label()) | 184 | hover_text(it.doc_comment_text(), it.short_label()) |
188 | }) | 185 | }, |
189 | .visit(|node: ast::FnDef| hover_text(node.doc_comment_text(), node.short_label())) | 186 | ast::EnumVariant(it) => { |
190 | .visit(|node: ast::TypeAliasDef| { | 187 | hover_text(it.doc_comment_text(), it.short_label()) |
191 | hover_text(node.doc_comment_text(), node.short_label()) | 188 | }, |
192 | }) | 189 | ast::FnDef(it) => { |
193 | .visit(|node: ast::ConstDef| { | 190 | hover_text(it.doc_comment_text(), it.short_label()) |
194 | hover_text(node.doc_comment_text(), node.short_label()) | 191 | }, |
195 | }) | 192 | ast::TypeAliasDef(it) => { |
196 | .visit(|node: ast::StaticDef| { | 193 | hover_text(it.doc_comment_text(), it.short_label()) |
197 | hover_text(node.doc_comment_text(), node.short_label()) | 194 | }, |
198 | }) | 195 | ast::ConstDef(it) => { |
199 | .visit(|node: ast::TraitDef| { | 196 | hover_text(it.doc_comment_text(), it.short_label()) |
200 | hover_text(node.doc_comment_text(), node.short_label()) | 197 | }, |
201 | }) | 198 | ast::StaticDef(it) => { |
202 | .visit(|node: ast::RecordFieldDef| { | 199 | hover_text(it.doc_comment_text(), it.short_label()) |
203 | hover_text(node.doc_comment_text(), node.short_label()) | 200 | }, |
204 | }) | 201 | ast::TraitDef(it) => { |
205 | .visit(|node: ast::Module| hover_text(node.doc_comment_text(), node.short_label())) | 202 | hover_text(it.doc_comment_text(), it.short_label()) |
206 | .visit(|node: ast::MacroCall| hover_text(node.doc_comment_text(), None)) | 203 | }, |
207 | .accept(&parent); | 204 | ast::RecordFieldDef(it) => { |
208 | 205 | hover_text(it.doc_comment_text(), it.short_label()) | |
209 | if let Some(text) = text { | 206 | }, |
210 | res.extend(text); | 207 | ast::Module(it) => { |
211 | } | 208 | hover_text(it.doc_comment_text(), it.short_label()) |
209 | }, | ||
210 | ast::MacroCall(it) => { | ||
211 | hover_text(it.doc_comment_text(), None) | ||
212 | }, | ||
213 | _ => None, | ||
214 | } | ||
215 | }; | ||
216 | res.extend(text); | ||
212 | } | 217 | } |
213 | 218 | ||
214 | if !res.is_empty() && range.is_none() { | 219 | if !res.is_empty() && range.is_none() { |