aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/references/classify.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/references/classify.rs')
-rw-r--r--crates/ra_ide/src/references/classify.rs36
1 files changed, 18 insertions, 18 deletions
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index 571236fdc..0bbf893f8 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -1,22 +1,22 @@
1//! Functions that are used to classify an element from its definition or reference. 1//! Functions that are used to classify an element from its definition or reference.
2 2
3use hir::{Local, PathResolution, Semantics}; 3use hir::{Local, PathResolution, Semantics};
4use ra_ide_db::defs::NameDefinition; 4use ra_ide_db::defs::Definition;
5use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
6use ra_prof::profile; 6use ra_prof::profile;
7use ra_syntax::{ast, AstNode}; 7use ra_syntax::{ast, AstNode};
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
10pub enum NameRefClass { 10pub enum NameRefClass {
11 NameDefinition(NameDefinition), 11 Definition(Definition),
12 FieldShorthand { local: Local, field: NameDefinition }, 12 FieldShorthand { local: Local, field: Definition },
13} 13}
14 14
15impl NameRefClass { 15impl NameRefClass {
16 pub fn definition(self) -> NameDefinition { 16 pub fn definition(self) -> Definition {
17 match self { 17 match self {
18 NameRefClass::NameDefinition(def) => def, 18 NameRefClass::Definition(def) => def,
19 NameRefClass::FieldShorthand { local, field: _ } => NameDefinition::Local(local), 19 NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local),
20 } 20 }
21 } 21 }
22} 22}
@@ -32,14 +32,14 @@ pub(crate) fn classify_name_ref(
32 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { 32 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
33 tested_by!(goto_def_for_methods); 33 tested_by!(goto_def_for_methods);
34 if let Some(func) = sema.resolve_method_call(&method_call) { 34 if let Some(func) = sema.resolve_method_call(&method_call) {
35 return Some(NameRefClass::NameDefinition(NameDefinition::ModuleDef(func.into()))); 35 return Some(NameRefClass::Definition(Definition::ModuleDef(func.into())));
36 } 36 }
37 } 37 }
38 38
39 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { 39 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
40 tested_by!(goto_def_for_fields); 40 tested_by!(goto_def_for_fields);
41 if let Some(field) = sema.resolve_field(&field_expr) { 41 if let Some(field) = sema.resolve_field(&field_expr) {
42 return Some(NameRefClass::NameDefinition(NameDefinition::StructField(field))); 42 return Some(NameRefClass::Definition(Definition::StructField(field)));
43 } 43 }
44 } 44 }
45 45
@@ -47,9 +47,9 @@ pub(crate) fn classify_name_ref(
47 tested_by!(goto_def_for_record_fields); 47 tested_by!(goto_def_for_record_fields);
48 tested_by!(goto_def_for_field_init_shorthand); 48 tested_by!(goto_def_for_field_init_shorthand);
49 if let Some((field, local)) = sema.resolve_record_field(&record_field) { 49 if let Some((field, local)) = sema.resolve_record_field(&record_field) {
50 let field = NameDefinition::StructField(field); 50 let field = Definition::StructField(field);
51 let res = match local { 51 let res = match local {
52 None => NameRefClass::NameDefinition(field), 52 None => NameRefClass::Definition(field),
53 Some(local) => NameRefClass::FieldShorthand { field, local }, 53 Some(local) => NameRefClass::FieldShorthand { field, local },
54 }; 54 };
55 return Some(res); 55 return Some(res);
@@ -59,26 +59,26 @@ pub(crate) fn classify_name_ref(
59 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 59 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
60 tested_by!(goto_def_for_macros); 60 tested_by!(goto_def_for_macros);
61 if let Some(macro_def) = sema.resolve_macro_call(&macro_call) { 61 if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
62 return Some(NameRefClass::NameDefinition(NameDefinition::Macro(macro_def))); 62 return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
63 } 63 }
64 } 64 }
65 65
66 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; 66 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
67 let resolved = sema.resolve_path(&path)?; 67 let resolved = sema.resolve_path(&path)?;
68 let res = match resolved { 68 let res = match resolved {
69 PathResolution::Def(def) => NameDefinition::ModuleDef(def), 69 PathResolution::Def(def) => Definition::ModuleDef(def),
70 PathResolution::AssocItem(item) => { 70 PathResolution::AssocItem(item) => {
71 let def = match item { 71 let def = match item {
72 hir::AssocItem::Function(it) => it.into(), 72 hir::AssocItem::Function(it) => it.into(),
73 hir::AssocItem::Const(it) => it.into(), 73 hir::AssocItem::Const(it) => it.into(),
74 hir::AssocItem::TypeAlias(it) => it.into(), 74 hir::AssocItem::TypeAlias(it) => it.into(),
75 }; 75 };
76 NameDefinition::ModuleDef(def) 76 Definition::ModuleDef(def)
77 } 77 }
78 PathResolution::Local(local) => NameDefinition::Local(local), 78 PathResolution::Local(local) => Definition::Local(local),
79 PathResolution::TypeParam(par) => NameDefinition::TypeParam(par), 79 PathResolution::TypeParam(par) => Definition::TypeParam(par),
80 PathResolution::Macro(def) => NameDefinition::Macro(def), 80 PathResolution::Macro(def) => Definition::Macro(def),
81 PathResolution::SelfType(impl_def) => NameDefinition::SelfType(impl_def), 81 PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def),
82 }; 82 };
83 Some(NameRefClass::NameDefinition(res)) 83 Some(NameRefClass::Definition(res))
84} 84}