aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/goto_definition.rs38
-rw-r--r--crates/ra_ide/src/references/classify.rs2
-rw-r--r--crates/ra_ide/src/references/rename.rs2
3 files changed, 21 insertions, 21 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index f2b5af321..5a12a619c 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -24,13 +24,14 @@ pub(crate) fn goto_definition(
24 let original_token = pick_best(file.token_at_offset(position.offset))?; 24 let original_token = pick_best(file.token_at_offset(position.offset))?;
25 let token = descend_into_macros(db, position.file_id, original_token.clone()); 25 let token = descend_into_macros(db, position.file_id, original_token.clone());
26 26
27 let mut sb = SourceBinder::new(db);
27 let nav_targets = match_ast! { 28 let nav_targets = match_ast! {
28 match (token.value.parent()) { 29 match (token.value.parent()) {
29 ast::NameRef(name_ref) => { 30 ast::NameRef(name_ref) => {
30 reference_definition(db, token.with_value(&name_ref)).to_vec() 31 reference_definition(&mut sb, token.with_value(&name_ref)).to_vec()
31 }, 32 },
32 ast::Name(name) => { 33 ast::Name(name) => {
33 name_definition(db, token.with_value(&name))? 34 name_definition(&mut sb, token.with_value(&name))?
34 }, 35 },
35 _ => return None, 36 _ => return None,
36 } 37 }
@@ -67,20 +68,19 @@ impl ReferenceResult {
67} 68}
68 69
69pub(crate) fn reference_definition( 70pub(crate) fn reference_definition(
70 db: &RootDatabase, 71 sb: &mut SourceBinder<RootDatabase>,
71 name_ref: InFile<&ast::NameRef>, 72 name_ref: InFile<&ast::NameRef>,
72) -> ReferenceResult { 73) -> ReferenceResult {
73 use self::ReferenceResult::*; 74 use self::ReferenceResult::*;
74 75
75 let mut sb = SourceBinder::new(db); 76 let name_kind = classify_name_ref(sb, name_ref).map(|d| d.kind);
76 let name_kind = classify_name_ref(&mut sb, name_ref).map(|d| d.kind);
77 match name_kind { 77 match name_kind {
78 Some(Macro(it)) => return Exact(it.to_nav(db)), 78 Some(Macro(it)) => return Exact(it.to_nav(sb.db)),
79 Some(Field(it)) => return Exact(it.to_nav(db)), 79 Some(Field(it)) => return Exact(it.to_nav(sb.db)),
80 Some(TypeParam(it)) => return Exact(it.to_nav(db)), 80 Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)),
81 Some(AssocItem(it)) => return Exact(it.to_nav(db)), 81 Some(AssocItem(it)) => return Exact(it.to_nav(sb.db)),
82 Some(Local(it)) => return Exact(it.to_nav(db)), 82 Some(Local(it)) => return Exact(it.to_nav(sb.db)),
83 Some(Def(def)) => match NavigationTarget::from_def(db, def) { 83 Some(Def(def)) => match NavigationTarget::from_def(sb.db, def) {
84 Some(nav) => return Exact(nav), 84 Some(nav) => return Exact(nav),
85 None => return Approximate(vec![]), 85 None => return Approximate(vec![]),
86 }, 86 },
@@ -88,21 +88,21 @@ pub(crate) fn reference_definition(
88 // FIXME: ideally, this should point to the type in the impl, and 88 // FIXME: ideally, this should point to the type in the impl, and
89 // not at the whole impl. And goto **type** definition should bring 89 // not at the whole impl. And goto **type** definition should bring
90 // us to the actual type 90 // us to the actual type
91 return Exact(imp.to_nav(db)); 91 return Exact(imp.to_nav(sb.db));
92 } 92 }
93 None => {} 93 None => {}
94 }; 94 };
95 95
96 // Fallback index based approach: 96 // Fallback index based approach:
97 let navs = crate::symbol_index::index_resolve(db, name_ref.value) 97 let navs = crate::symbol_index::index_resolve(sb.db, name_ref.value)
98 .into_iter() 98 .into_iter()
99 .map(|s| s.to_nav(db)) 99 .map(|s| s.to_nav(sb.db))
100 .collect(); 100 .collect();
101 Approximate(navs) 101 Approximate(navs)
102} 102}
103 103
104pub(crate) fn name_definition( 104fn name_definition(
105 db: &RootDatabase, 105 sb: &mut SourceBinder<RootDatabase>,
106 name: InFile<&ast::Name>, 106 name: InFile<&ast::Name>,
107) -> Option<Vec<NavigationTarget>> { 107) -> Option<Vec<NavigationTarget>> {
108 let parent = name.value.syntax().parent()?; 108 let parent = name.value.syntax().parent()?;
@@ -110,14 +110,14 @@ pub(crate) fn name_definition(
110 if let Some(module) = ast::Module::cast(parent.clone()) { 110 if let Some(module) = ast::Module::cast(parent.clone()) {
111 if module.has_semi() { 111 if module.has_semi() {
112 let src = name.with_value(module); 112 let src = name.with_value(module);
113 if let Some(child_module) = hir::Module::from_declaration(db, src) { 113 if let Some(child_module) = sb.to_def(src) {
114 let nav = child_module.to_nav(db); 114 let nav = child_module.to_nav(sb.db);
115 return Some(vec![nav]); 115 return Some(vec![nav]);
116 } 116 }
117 } 117 }
118 } 118 }
119 119
120 if let Some(nav) = named_target(db, name.with_value(&parent)) { 120 if let Some(nav) = named_target(sb.db, name.with_value(&parent)) {
121 return Some(vec![nav]); 121 return Some(vec![nav]);
122 } 122 }
123 123
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index 82a18a0a5..cb7da1fff 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -42,7 +42,7 @@ pub(crate) fn classify_name(
42 hir::Module::from_definition(sb.db, src) 42 hir::Module::from_definition(sb.db, src)
43 } else { 43 } else {
44 let src = name.with_value(it); 44 let src = name.with_value(it);
45 hir::Module::from_declaration(sb.db, src) 45 sb.to_def(src)
46 } 46 }
47 }?; 47 }?;
48 Some(from_module_def(sb.db, def.into(), None)) 48 Some(from_module_def(sb.db, def.into(), None))
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index e02985dcd..626efb603 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -63,7 +63,7 @@ fn rename_mod(
63 let mut source_file_edits = Vec::new(); 63 let mut source_file_edits = Vec::new();
64 let mut file_system_edits = Vec::new(); 64 let mut file_system_edits = Vec::new();
65 let module_src = hir::InFile { file_id: position.file_id.into(), value: ast_module.clone() }; 65 let module_src = hir::InFile { file_id: position.file_id.into(), value: ast_module.clone() };
66 if let Some(module) = hir::Module::from_declaration(db, module_src) { 66 if let Some(module) = hir::SourceBinder::new(db).to_def(module_src) {
67 let src = module.definition_source(db); 67 let src = module.definition_source(db);
68 let file_id = src.file_id.original_file(db); 68 let file_id = src.file_id.original_file(db);
69 match src.value { 69 match src.value {