aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/hover.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index a18c43003..d427ed46b 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -102,18 +102,13 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
102 let node = token.parent(); 102 let node = token.parent();
103 let definition = match_ast! { 103 let definition = match_ast! {
104 match node { 104 match node {
105 ast::NameRef(name_ref) => { 105 ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition()),
106 classify_name_ref(&sema, &name_ref).map(|d| d.definition()) 106 ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition()),
107 },
108 ast::Name(name) => {
109 classify_name(&sema, &name).map(|d| d.definition())
110 },
111 _ => None, 107 _ => None,
112 } 108 }
113 }; 109 };
114 if let Some(definition) = definition { 110 if let Some(definition) = definition {
115 let range = sema.original_range(&node).range; 111 if let Some(text) = hover_for_definition(db, definition) {
116 if let Some(text) = hover_text_from_name_kind(db, definition) {
117 res.markup.push_section(&text); 112 res.markup.push_section(&text);
118 } 113 }
119 if !res.is_empty() { 114 if !res.is_empty() {
@@ -129,6 +124,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
129 res.push_action(action); 124 res.push_action(action);
130 } 125 }
131 126
127 let range = sema.original_range(&node).range;
132 return Some(RangeInfo::new(range, res)); 128 return Some(RangeInfo::new(range, res));
133 } 129 }
134 } 130 }
@@ -139,20 +135,14 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
139 135
140 let ty = match_ast! { 136 let ty = match_ast! {
141 match node { 137 match node {
142 ast::MacroCall(_it) => { 138 ast::Expr(it) => sema.type_of_expr(&it)?,
143 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve. 139 ast::Pat(it) => sema.type_of_pat(&it)?,
144 // (e.g expanding a builtin macro). So we give up here. 140 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
145 return None; 141 // (e.g expanding a builtin macro). So we give up here.
146 }, 142 ast::MacroCall(_it) => return None,
147 ast::Expr(it) => { 143 _ => return None,
148 sema.type_of_expr(&it)
149 },
150 ast::Pat(it) => {
151 sema.type_of_pat(&it)
152 },
153 _ => None,
154 } 144 }
155 }?; 145 };
156 146
157 res.markup.push_section(&rust_code_markup(&ty.display(db))); 147 res.markup.push_section(&rust_code_markup(&ty.display(db)));
158 let range = sema.original_range(&node).range; 148 let range = sema.original_range(&node).range;
@@ -300,7 +290,7 @@ fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
300 def.module(db).map(|module| determine_mod_path(db, module, definition_owner_name(db, def))) 290 def.module(db).map(|module| determine_mod_path(db, module, definition_owner_name(db, def)))
301} 291}
302 292
303fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option<String> { 293fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<String> {
304 let mod_path = definition_mod_path(db, &def); 294 let mod_path = definition_mod_path(db, &def);
305 return match def { 295 return match def {
306 Definition::Macro(it) => { 296 Definition::Macro(it) => {