aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/references
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-19 13:32:22 +0000
committerAleksey Kladov <[email protected]>2020-02-19 13:32:22 +0000
commit86b66067f6321382cd72ec29c49d166da46fc3f8 (patch)
tree08439b647be9f92db7511dd68e3c51f7a3a6de2a /crates/ra_ide/src/references
parent624a9978e25c7c6cee7fd88afd1559f1f143fe4e (diff)
Don't store deriveable Module info in NameDefinition
Diffstat (limited to 'crates/ra_ide/src/references')
-rw-r--r--crates/ra_ide/src/references/classify.rs20
-rw-r--r--crates/ra_ide/src/references/search_scope.rs15
2 files changed, 19 insertions, 16 deletions
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index d0f03d8a8..2394e68d1 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -22,7 +22,7 @@ pub(crate) fn classify_name_ref(
22 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { 22 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
23 tested_by!(goto_def_for_methods); 23 tested_by!(goto_def_for_methods);
24 if let Some(func) = analyzer.resolve_method_call(&method_call) { 24 if let Some(func) = analyzer.resolve_method_call(&method_call) {
25 return Some(from_module_def(sb.db, func.into(), None)); 25 return Some(from_module_def(sb.db, func.into()));
26 } 26 }
27 } 27 }
28 28
@@ -43,7 +43,6 @@ pub(crate) fn classify_name_ref(
43 43
44 // FIXME: find correct container and visibility for each case 44 // FIXME: find correct container and visibility for each case
45 let visibility = None; 45 let visibility = None;
46 let container = sb.to_module_def(name_ref.file_id.original_file(sb.db))?;
47 46
48 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 47 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
49 tested_by!(goto_def_for_macros); 48 tested_by!(goto_def_for_macros);
@@ -51,40 +50,37 @@ pub(crate) fn classify_name_ref(
51 analyzer.resolve_macro_call(sb.db, name_ref.with_value(&macro_call)) 50 analyzer.resolve_macro_call(sb.db, name_ref.with_value(&macro_call))
52 { 51 {
53 let kind = NameKind::Macro(macro_def); 52 let kind = NameKind::Macro(macro_def);
54 return Some(NameDefinition { kind, container, visibility }); 53 return Some(NameDefinition { kind, visibility });
55 } 54 }
56 } 55 }
57 56
58 let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; 57 let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?;
59 let resolved = analyzer.resolve_path(sb.db, &path)?; 58 let resolved = analyzer.resolve_path(sb.db, &path)?;
60 let res = match resolved { 59 let res = match resolved {
61 PathResolution::Def(def) => from_module_def(sb.db, def, Some(container)), 60 PathResolution::Def(def) => from_module_def(sb.db, def),
62 PathResolution::AssocItem(item) => { 61 PathResolution::AssocItem(item) => {
63 let def = match item { 62 let def = match item {
64 hir::AssocItem::Function(it) => it.into(), 63 hir::AssocItem::Function(it) => it.into(),
65 hir::AssocItem::Const(it) => it.into(), 64 hir::AssocItem::Const(it) => it.into(),
66 hir::AssocItem::TypeAlias(it) => it.into(), 65 hir::AssocItem::TypeAlias(it) => it.into(),
67 }; 66 };
68 from_module_def(sb.db, def, Some(container)) 67 from_module_def(sb.db, def)
69 } 68 }
70 PathResolution::Local(local) => { 69 PathResolution::Local(local) => {
71 let kind = NameKind::Local(local); 70 let kind = NameKind::Local(local);
72 let container = local.module(sb.db); 71 NameDefinition { kind, visibility: None }
73 NameDefinition { kind, container, visibility: None }
74 } 72 }
75 PathResolution::TypeParam(par) => { 73 PathResolution::TypeParam(par) => {
76 let kind = NameKind::TypeParam(par); 74 let kind = NameKind::TypeParam(par);
77 let container = par.module(sb.db); 75 NameDefinition { kind, visibility }
78 NameDefinition { kind, container, visibility }
79 } 76 }
80 PathResolution::Macro(def) => { 77 PathResolution::Macro(def) => {
81 let kind = NameKind::Macro(def); 78 let kind = NameKind::Macro(def);
82 NameDefinition { kind, container, visibility } 79 NameDefinition { kind, visibility }
83 } 80 }
84 PathResolution::SelfType(impl_block) => { 81 PathResolution::SelfType(impl_block) => {
85 let kind = NameKind::SelfType(impl_block); 82 let kind = NameKind::SelfType(impl_block);
86 let container = impl_block.module(sb.db); 83 NameDefinition { kind, visibility }
87 NameDefinition { kind, container, visibility }
88 } 84 }
89 }; 85 };
90 Some(res) 86 Some(res)
diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs
index 279f57be0..f9bbe64a4 100644
--- a/crates/ra_ide/src/references/search_scope.rs
+++ b/crates/ra_ide/src/references/search_scope.rs
@@ -19,10 +19,17 @@ pub struct SearchScope {
19} 19}
20 20
21impl SearchScope { 21impl SearchScope {
22 fn empty() -> SearchScope {
23 SearchScope { entries: FxHashMap::default() }
24 }
25
22 pub(crate) fn for_def(def: &NameDefinition, db: &RootDatabase) -> SearchScope { 26 pub(crate) fn for_def(def: &NameDefinition, db: &RootDatabase) -> SearchScope {
23 let _p = profile("search_scope"); 27 let _p = profile("search_scope");
24 28 let module = match def.module(db) {
25 let module_src = def.container.definition_source(db); 29 Some(it) => it,
30 None => return SearchScope::empty(),
31 };
32 let module_src = module.definition_source(db);
26 let file_id = module_src.file_id.original_file(db); 33 let file_id = module_src.file_id.original_file(db);
27 34
28 if let NameKind::Local(var) = def.kind { 35 if let NameKind::Local(var) = def.kind {
@@ -39,7 +46,7 @@ impl SearchScope {
39 let vis = def.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); 46 let vis = def.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default();
40 47
41 if vis.as_str() == "pub(super)" { 48 if vis.as_str() == "pub(super)" {
42 if let Some(parent_module) = def.container.parent(db) { 49 if let Some(parent_module) = module.parent(db) {
43 let mut res = FxHashMap::default(); 50 let mut res = FxHashMap::default();
44 let parent_src = parent_module.definition_source(db); 51 let parent_src = parent_module.definition_source(db);
45 let file_id = parent_src.file_id.original_file(db); 52 let file_id = parent_src.file_id.original_file(db);
@@ -72,7 +79,7 @@ impl SearchScope {
72 return SearchScope::new(res); 79 return SearchScope::new(res);
73 } 80 }
74 if vis.as_str() == "pub" { 81 if vis.as_str() == "pub" {
75 let krate = def.container.krate(); 82 let krate = module.krate();
76 for rev_dep in krate.reverse_dependencies(db) { 83 for rev_dep in krate.reverse_dependencies(db) {
77 let root_file = rev_dep.root_file(db); 84 let root_file = rev_dep.root_file(db);
78 let source_root_id = db.file_source_root(root_file); 85 let source_root_id = db.file_source_root(root_file);