aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/references
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-16 16:58:13 +0000
committerGitHub <[email protected]>2020-01-16 16:58:13 +0000
commitd3c4fbbbc45afc7d480185493b5ce77b5daa1747 (patch)
treeaa12838a1b0c45710bb7657f6f3c34947519484c /crates/ra_ide/src/references
parente614356de10256c64e02f5d0f82cfa39e27b0f07 (diff)
parent846f11c2177f3e3a6348acb67503028180b3c1f8 (diff)
Merge #2862
2862: Move from `from_source` to `SourceBinder` r=matklad a=matklad bors r+ Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/references')
-rw-r--r--crates/ra_ide/src/references/classify.rs28
-rw-r--r--crates/ra_ide/src/references/name_definition.rs2
-rw-r--r--crates/ra_ide/src/references/rename.rs2
3 files changed, 12 insertions, 20 deletions
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index 4a6e11e27..46cba30a3 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -1,6 +1,6 @@
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::{FromSource, InFile, Module, ModuleSource, PathResolution, SourceBinder}; 3use hir::{InFile, PathResolution, SourceBinder};
4use ra_prof::profile; 4use ra_prof::profile;
5use ra_syntax::{ast, match_ast, AstNode}; 5use ra_syntax::{ast, match_ast, AstNode};
6use test_utils::tested_by; 6use test_utils::tested_by;
@@ -22,7 +22,7 @@ pub(crate) fn classify_name(
22 match parent { 22 match parent {
23 ast::BindPat(it) => { 23 ast::BindPat(it) => {
24 let src = name.with_value(it); 24 let src = name.with_value(it);
25 let local = hir::Local::from_source(sb.db, src)?; 25 let local = sb.to_def(src)?;
26 Some(NameDefinition { 26 Some(NameDefinition {
27 visibility: None, 27 visibility: None,
28 container: local.module(sb.db), 28 container: local.module(sb.db),
@@ -35,16 +35,7 @@ pub(crate) fn classify_name(
35 Some(from_struct_field(sb.db, field)) 35 Some(from_struct_field(sb.db, field))
36 }, 36 },
37 ast::Module(it) => { 37 ast::Module(it) => {
38 let def = { 38 let def = sb.to_def(name.with_value(it))?;
39 if !it.has_semi() {
40 let ast = hir::ModuleSource::Module(it);
41 let src = name.with_value(ast);
42 hir::Module::from_definition(sb.db, src)
43 } else {
44 let src = name.with_value(it);
45 hir::Module::from_declaration(sb.db, src)
46 }
47 }?;
48 Some(from_module_def(sb.db, def.into(), None)) 39 Some(from_module_def(sb.db, def.into(), None))
49 }, 40 },
50 ast::StructDef(it) => { 41 ast::StructDef(it) => {
@@ -101,10 +92,9 @@ pub(crate) fn classify_name(
101 }, 92 },
102 ast::MacroCall(it) => { 93 ast::MacroCall(it) => {
103 let src = name.with_value(it); 94 let src = name.with_value(it);
104 let def = hir::MacroDef::from_source(sb.db, src.clone())?; 95 let def = sb.to_def(src.clone())?;
105 96
106 let module_src = ModuleSource::from_child_node(sb.db, src.as_ref().map(|it| it.syntax())); 97 let module = sb.to_module_def(src.file_id.original_file(sb.db))?;
107 let module = Module::from_definition(sb.db, src.with_value(module_src))?;
108 98
109 Some(NameDefinition { 99 Some(NameDefinition {
110 visibility: None, 100 visibility: None,
@@ -114,7 +104,7 @@ pub(crate) fn classify_name(
114 }, 104 },
115 ast::TypeParam(it) => { 105 ast::TypeParam(it) => {
116 let src = name.with_value(it); 106 let src = name.with_value(it);
117 let def = hir::TypeParam::from_source(sb.db, src)?; 107 let def = sb.to_def(src)?;
118 Some(NameDefinition { 108 Some(NameDefinition {
119 visibility: None, 109 visibility: None,
120 container: def.module(sb.db), 110 container: def.module(sb.db),
@@ -157,10 +147,9 @@ pub(crate) fn classify_name_ref(
157 } 147 }
158 } 148 }
159 149
160 let ast = ModuleSource::from_child_node(sb.db, name_ref.with_value(&parent));
161 // FIXME: find correct container and visibility for each case 150 // FIXME: find correct container and visibility for each case
162 let container = Module::from_definition(sb.db, name_ref.with_value(ast))?;
163 let visibility = None; 151 let visibility = None;
152 let container = sb.to_module_def(name_ref.file_id.original_file(sb.db))?;
164 153
165 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 154 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
166 tested_by!(goto_def_for_macros); 155 tested_by!(goto_def_for_macros);
@@ -178,12 +167,13 @@ pub(crate) fn classify_name_ref(
178 PathResolution::Def(def) => Some(from_module_def(sb.db, def, Some(container))), 167 PathResolution::Def(def) => Some(from_module_def(sb.db, def, Some(container))),
179 PathResolution::AssocItem(item) => Some(from_assoc_item(sb.db, item)), 168 PathResolution::AssocItem(item) => Some(from_assoc_item(sb.db, item)),
180 PathResolution::Local(local) => { 169 PathResolution::Local(local) => {
181 let container = local.module(sb.db);
182 let kind = NameKind::Local(local); 170 let kind = NameKind::Local(local);
171 let container = local.module(sb.db);
183 Some(NameDefinition { kind, container, visibility: None }) 172 Some(NameDefinition { kind, container, visibility: None })
184 } 173 }
185 PathResolution::TypeParam(par) => { 174 PathResolution::TypeParam(par) => {
186 let kind = NameKind::TypeParam(par); 175 let kind = NameKind::TypeParam(par);
176 let container = par.module(sb.db);
187 Some(NameDefinition { kind, container, visibility }) 177 Some(NameDefinition { kind, container, visibility })
188 } 178 }
189 PathResolution::Macro(def) => { 179 PathResolution::Macro(def) => {
diff --git a/crates/ra_ide/src/references/name_definition.rs b/crates/ra_ide/src/references/name_definition.rs
index 8c67c8863..1e4226ab9 100644
--- a/crates/ra_ide/src/references/name_definition.rs
+++ b/crates/ra_ide/src/references/name_definition.rs
@@ -25,6 +25,8 @@ pub enum NameKind {
25#[derive(PartialEq, Eq)] 25#[derive(PartialEq, Eq)]
26pub(crate) struct NameDefinition { 26pub(crate) struct NameDefinition {
27 pub visibility: Option<ast::Visibility>, 27 pub visibility: Option<ast::Visibility>,
28 /// FIXME: this doesn't really make sense. For example, builtin types don't
29 /// really have a module.
28 pub container: Module, 30 pub container: Module,
29 pub kind: NameKind, 31 pub kind: NameKind,
30} 32}
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 {