diff options
author | Aleksey Kladov <[email protected]> | 2020-02-19 13:56:22 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-19 13:56:22 +0000 |
commit | 372439dec88f8ce3350f29aa56801c8f30e59abe (patch) | |
tree | 4c93760e3d696a6a1a1e8acf10eebf1a29be85f2 /crates/ra_ide/src/hover.rs | |
parent | 0d5ae89948903bb150b72885c6d9f24dc7a2bb51 (diff) |
Merge NameDefinition and NameKind
Diffstat (limited to 'crates/ra_ide/src/hover.rs')
-rw-r--r-- | crates/ra_ide/src/hover.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 6d4416c0b..1c6ca36df 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, SourceBinder}; | 3 | use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, SourceBinder}; |
4 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::{defs::NameDefinition, RootDatabase}; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | algo::find_covering_element, | 7 | algo::find_covering_element, |
8 | ast::{self, DocCommentsOwner}, | 8 | ast::{self, DocCommentsOwner}, |
@@ -14,7 +14,7 @@ use ra_syntax::{ | |||
14 | use crate::{ | 14 | use crate::{ |
15 | display::{macro_label, rust_code_markup, rust_code_markup_with_doc, ShortLabel}, | 15 | display::{macro_label, rust_code_markup, rust_code_markup_with_doc, ShortLabel}, |
16 | expand::{descend_into_macros, original_range}, | 16 | expand::{descend_into_macros, original_range}, |
17 | references::{classify_name, classify_name_ref, NameKind, NameKind::*}, | 17 | references::{classify_name, classify_name_ref}, |
18 | FilePosition, FileRange, RangeInfo, | 18 | FilePosition, FileRange, RangeInfo, |
19 | }; | 19 | }; |
20 | 20 | ||
@@ -92,20 +92,20 @@ fn hover_text(docs: Option<String>, desc: Option<String>) -> Option<String> { | |||
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<String> { | 95 | fn hover_text_from_name_kind(db: &RootDatabase, def: NameDefinition) -> Option<String> { |
96 | return match name_kind { | 96 | return match def { |
97 | Macro(it) => { | 97 | NameDefinition::Macro(it) => { |
98 | let src = it.source(db); | 98 | let src = it.source(db); |
99 | hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) | 99 | hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) |
100 | } | 100 | } |
101 | StructField(it) => { | 101 | NameDefinition::StructField(it) => { |
102 | let src = it.source(db); | 102 | let src = it.source(db); |
103 | match src.value { | 103 | match src.value { |
104 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), | 104 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), |
105 | _ => None, | 105 | _ => None, |
106 | } | 106 | } |
107 | } | 107 | } |
108 | ModuleDef(it) => match it { | 108 | NameDefinition::ModuleDef(it) => match it { |
109 | hir::ModuleDef::Module(it) => match it.definition_source(db).value { | 109 | hir::ModuleDef::Module(it) => match it.definition_source(db).value { |
110 | hir::ModuleSource::Module(it) => { | 110 | hir::ModuleSource::Module(it) => { |
111 | hover_text(it.doc_comment_text(), it.short_label()) | 111 | hover_text(it.doc_comment_text(), it.short_label()) |
@@ -123,8 +123,10 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<S | |||
123 | hir::ModuleDef::TypeAlias(it) => from_def_source(db, it), | 123 | hir::ModuleDef::TypeAlias(it) => from_def_source(db, it), |
124 | hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), | 124 | hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), |
125 | }, | 125 | }, |
126 | Local(it) => Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string())), | 126 | NameDefinition::Local(it) => { |
127 | TypeParam(_) | SelfType(_) => { | 127 | Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string())) |
128 | } | ||
129 | NameDefinition::TypeParam(_) | NameDefinition::SelfType(_) => { | ||
128 | // FIXME: Hover for generic param | 130 | // FIXME: Hover for generic param |
129 | None | 131 | None |
130 | } | 132 | } |
@@ -151,10 +153,10 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
151 | if let Some((node, name_kind)) = match_ast! { | 153 | if let Some((node, name_kind)) = match_ast! { |
152 | match (token.value.parent()) { | 154 | match (token.value.parent()) { |
153 | ast::NameRef(name_ref) => { | 155 | ast::NameRef(name_ref) => { |
154 | classify_name_ref(&mut sb, token.with_value(&name_ref)).map(|d| (name_ref.syntax().clone(), d.kind)) | 156 | classify_name_ref(&mut sb, token.with_value(&name_ref)).map(|d| (name_ref.syntax().clone(), d)) |
155 | }, | 157 | }, |
156 | ast::Name(name) => { | 158 | ast::Name(name) => { |
157 | classify_name(&mut sb, token.with_value(&name)).map(|d| (name.syntax().clone(), d.kind)) | 159 | classify_name(&mut sb, token.with_value(&name)).map(|d| (name.syntax().clone(), d)) |
158 | }, | 160 | }, |
159 | _ => None, | 161 | _ => None, |
160 | } | 162 | } |