From 86b66067f6321382cd72ec29c49d166da46fc3f8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Feb 2020 14:32:22 +0100 Subject: Don't store deriveable Module info in NameDefinition --- crates/ra_ide/src/references/classify.rs | 20 ++++++++------------ crates/ra_ide/src/references/search_scope.rs | 15 +++++++++++---- 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'crates/ra_ide/src') 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( if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { tested_by!(goto_def_for_methods); if let Some(func) = analyzer.resolve_method_call(&method_call) { - return Some(from_module_def(sb.db, func.into(), None)); + return Some(from_module_def(sb.db, func.into())); } } @@ -43,7 +43,6 @@ pub(crate) fn classify_name_ref( // FIXME: find correct container and visibility for each case let visibility = None; - let container = sb.to_module_def(name_ref.file_id.original_file(sb.db))?; if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { tested_by!(goto_def_for_macros); @@ -51,40 +50,37 @@ pub(crate) fn classify_name_ref( analyzer.resolve_macro_call(sb.db, name_ref.with_value(¯o_call)) { let kind = NameKind::Macro(macro_def); - return Some(NameDefinition { kind, container, visibility }); + return Some(NameDefinition { kind, visibility }); } } let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; let resolved = analyzer.resolve_path(sb.db, &path)?; let res = match resolved { - PathResolution::Def(def) => from_module_def(sb.db, def, Some(container)), + PathResolution::Def(def) => from_module_def(sb.db, def), PathResolution::AssocItem(item) => { let def = match item { hir::AssocItem::Function(it) => it.into(), hir::AssocItem::Const(it) => it.into(), hir::AssocItem::TypeAlias(it) => it.into(), }; - from_module_def(sb.db, def, Some(container)) + from_module_def(sb.db, def) } PathResolution::Local(local) => { let kind = NameKind::Local(local); - let container = local.module(sb.db); - NameDefinition { kind, container, visibility: None } + NameDefinition { kind, visibility: None } } PathResolution::TypeParam(par) => { let kind = NameKind::TypeParam(par); - let container = par.module(sb.db); - NameDefinition { kind, container, visibility } + NameDefinition { kind, visibility } } PathResolution::Macro(def) => { let kind = NameKind::Macro(def); - NameDefinition { kind, container, visibility } + NameDefinition { kind, visibility } } PathResolution::SelfType(impl_block) => { let kind = NameKind::SelfType(impl_block); - let container = impl_block.module(sb.db); - NameDefinition { kind, container, visibility } + NameDefinition { kind, visibility } } }; 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 { } impl SearchScope { + fn empty() -> SearchScope { + SearchScope { entries: FxHashMap::default() } + } + pub(crate) fn for_def(def: &NameDefinition, db: &RootDatabase) -> SearchScope { let _p = profile("search_scope"); - - let module_src = def.container.definition_source(db); + let module = match def.module(db) { + Some(it) => it, + None => return SearchScope::empty(), + }; + let module_src = module.definition_source(db); let file_id = module_src.file_id.original_file(db); if let NameKind::Local(var) = def.kind { @@ -39,7 +46,7 @@ impl SearchScope { let vis = def.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); if vis.as_str() == "pub(super)" { - if let Some(parent_module) = def.container.parent(db) { + if let Some(parent_module) = module.parent(db) { let mut res = FxHashMap::default(); let parent_src = parent_module.definition_source(db); let file_id = parent_src.file_id.original_file(db); @@ -72,7 +79,7 @@ impl SearchScope { return SearchScope::new(res); } if vis.as_str() == "pub" { - let krate = def.container.krate(); + let krate = module.krate(); for rev_dep in krate.reverse_dependencies(db) { let root_file = rev_dep.root_file(db); let source_root_id = db.file_source_root(root_file); -- cgit v1.2.3