aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/references
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-03 17:36:39 +0000
committerAleksey Kladov <[email protected]>2020-03-03 17:40:27 +0000
commitd49a4d1863c30e2dc6e744bf1f1dc92411912bb5 (patch)
tree66a368988b4f3e698c6ec71309ffb4155a725331 /crates/ra_ide/src/references
parent13b25d73b56ede36d1680efc19f5c11b0669b96c (diff)
Rename NameDefinition -> Definition
Diffstat (limited to 'crates/ra_ide/src/references')
-rw-r--r--crates/ra_ide/src/references/classify.rs36
-rw-r--r--crates/ra_ide/src/references/search_scope.rs6
2 files changed, 21 insertions, 21 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}
diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs
index 27d483233..d98c84d91 100644
--- a/crates/ra_ide/src/references/search_scope.rs
+++ b/crates/ra_ide/src/references/search_scope.rs
@@ -12,7 +12,7 @@ use rustc_hash::FxHashMap;
12 12
13use ra_ide_db::RootDatabase; 13use ra_ide_db::RootDatabase;
14 14
15use super::NameDefinition; 15use super::Definition;
16 16
17pub struct SearchScope { 17pub struct SearchScope {
18 entries: FxHashMap<FileId, Option<TextRange>>, 18 entries: FxHashMap<FileId, Option<TextRange>>,
@@ -23,7 +23,7 @@ impl SearchScope {
23 SearchScope { entries: FxHashMap::default() } 23 SearchScope { entries: FxHashMap::default() }
24 } 24 }
25 25
26 pub(crate) fn for_def(def: &NameDefinition, db: &RootDatabase) -> SearchScope { 26 pub(crate) fn for_def(def: &Definition, db: &RootDatabase) -> SearchScope {
27 let _p = profile("search_scope"); 27 let _p = profile("search_scope");
28 let module = match def.module(db) { 28 let module = match def.module(db) {
29 Some(it) => it, 29 Some(it) => it,
@@ -32,7 +32,7 @@ impl SearchScope {
32 let module_src = module.definition_source(db); 32 let module_src = module.definition_source(db);
33 let file_id = module_src.file_id.original_file(db); 33 let file_id = module_src.file_id.original_file(db);
34 34
35 if let NameDefinition::Local(var) = def { 35 if let Definition::Local(var) = def {
36 let range = match var.parent(db) { 36 let range = match var.parent(db) {
37 DefWithBody::Function(f) => f.source(db).value.syntax().text_range(), 37 DefWithBody::Function(f) => f.source(db).value.syntax().text_range(),
38 DefWithBody::Const(c) => c.source(db).value.syntax().text_range(), 38 DefWithBody::Const(c) => c.source(db).value.syntax().text_range(),