aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-06-10 18:18:32 +0100
committerEdwin Cheng <[email protected]>2019-06-10 18:18:32 +0100
commit656a0fa9f99298123d7dcee8c65a8a5ed7043bc4 (patch)
tree331fe1559a1c6fb293f9d68a4d5d5b08565c7afb /crates
parent34322ea9a3bc9ca2be4724447ca61e8bd9d09e30 (diff)
Simpliy hover on ast::name
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/display.rs10
-rw-r--r--crates/ra_ide_api/src/hover.rs42
2 files changed, 35 insertions, 17 deletions
diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs
index b81f4db0c..882518838 100644
--- a/crates/ra_ide_api/src/display.rs
+++ b/crates/ra_ide_api/src/display.rs
@@ -73,13 +73,3 @@ where
73 format!("```rust\n{}\n```", val.as_ref()) 73 format!("```rust\n{}\n```", val.as_ref())
74 } 74 }
75} 75}
76
77// FIXME: this should not really use navigation target. Rather, approximately
78// resolved symbol should return a `DefId`.
79pub(crate) fn doc_text_for(nav: NavigationTarget) -> Option<String> {
80 match (nav.description(), nav.docs()) {
81 (Some(desc), docs) => Some(rust_code_markup_with_doc(desc, docs)),
82 (None, Some(docs)) => Some(docs.to_string()),
83 _ => None,
84 }
85}
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 1f454be21..fbabeb194 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,14 +1,14 @@
1use ra_db::SourceDatabase; 1use ra_db::SourceDatabase;
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, ast::{self, DocCommentsOwner}, 3 AstNode, ast::{self, DocCommentsOwner},
4 algo::{find_covering_element, find_node_at_offset, ancestors_at_offset}, 4 algo::{find_covering_element, find_node_at_offset, ancestors_at_offset, visit::{visitor, Visitor}},
5}; 5};
6use hir::HirDisplay; 6use hir::HirDisplay;
7 7
8use crate::{ 8use crate::{
9 db::RootDatabase, 9 db::RootDatabase,
10 RangeInfo, FilePosition, FileRange, 10 RangeInfo, FilePosition, FileRange,
11 display::{rust_code_markup, doc_text_for, rust_code_markup_with_doc, ShortLabel, docs_from_symbol, description_from_symbol}, 11 display::{rust_code_markup, rust_code_markup_with_doc, ShortLabel, docs_from_symbol, description_from_symbol},
12 name_ref_kind::{NameRefKind::*, classify_name_ref}, 12 name_ref_kind::{NameRefKind::*, classify_name_ref},
13}; 13};
14 14
@@ -216,11 +216,39 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
216 range = Some(name_ref.syntax().range()) 216 range = Some(name_ref.syntax().range())
217 } 217 }
218 } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { 218 } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) {
219 let navs = crate::goto_definition::name_definition(db, position.file_id, name); 219 if let Some(parent) = name.syntax().parent() {
220 220 let text = visitor()
221 if let Some(navs) = navs { 221 .visit(|node: &ast::StructDef| {
222 for nav in navs { 222 hover_text(node.doc_comment_text(), node.short_label())
223 res.extend(doc_text_for(nav)) 223 })
224 .visit(|node: &ast::EnumDef| {
225 hover_text(node.doc_comment_text(), node.short_label())
226 })
227 .visit(|node: &ast::EnumVariant| {
228 hover_text(node.doc_comment_text(), node.short_label())
229 })
230 .visit(|node: &ast::FnDef| hover_text(node.doc_comment_text(), node.short_label()))
231 .visit(|node: &ast::TypeAliasDef| {
232 hover_text(node.doc_comment_text(), node.short_label())
233 })
234 .visit(|node: &ast::ConstDef| {
235 hover_text(node.doc_comment_text(), node.short_label())
236 })
237 .visit(|node: &ast::StaticDef| {
238 hover_text(node.doc_comment_text(), node.short_label())
239 })
240 .visit(|node: &ast::TraitDef| {
241 hover_text(node.doc_comment_text(), node.short_label())
242 })
243 .visit(|node: &ast::NamedFieldDef| {
244 hover_text(node.doc_comment_text(), node.short_label())
245 })
246 .visit(|node: &ast::Module| hover_text(node.doc_comment_text(), node.short_label()))
247 .visit(|node: &ast::MacroCall| hover_text(node.doc_comment_text(), None))
248 .accept(parent);
249
250 if let Some(text) = text {
251 res.extend(text);
224 } 252 }
225 } 253 }
226 254