From 0d5ae89948903bb150b72885c6d9f24dc7a2bb51 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Feb 2020 14:45:49 +0100 Subject: Derive visibility as well --- crates/ra_ide/src/references/classify.rs | 23 ++++++++++------------- crates/ra_ide/src/references/search_scope.rs | 2 +- 2 files changed, 11 insertions(+), 14 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 2394e68d1..ca5750521 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -22,14 +22,14 @@ 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())); + return Some(from_module_def(func.into())); } } if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { tested_by!(goto_def_for_fields); if let Some(field) = analyzer.resolve_field(&field_expr) { - return Some(from_struct_field(sb.db, field)); + return Some(from_struct_field(field)); } } @@ -37,50 +37,47 @@ pub(crate) fn classify_name_ref( tested_by!(goto_def_for_record_fields); tested_by!(goto_def_for_field_init_shorthand); if let Some(field_def) = analyzer.resolve_record_field(&record_field) { - return Some(from_struct_field(sb.db, field_def)); + return Some(from_struct_field(field_def)); } } - // FIXME: find correct container and visibility for each case - let visibility = None; - if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { tested_by!(goto_def_for_macros); if let Some(macro_def) = analyzer.resolve_macro_call(sb.db, name_ref.with_value(¯o_call)) { let kind = NameKind::Macro(macro_def); - return Some(NameDefinition { kind, visibility }); + return Some(NameDefinition { kind }); } } 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), + PathResolution::Def(def) => from_module_def(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) + from_module_def(def) } PathResolution::Local(local) => { let kind = NameKind::Local(local); - NameDefinition { kind, visibility: None } + NameDefinition { kind } } PathResolution::TypeParam(par) => { let kind = NameKind::TypeParam(par); - NameDefinition { kind, visibility } + NameDefinition { kind } } PathResolution::Macro(def) => { let kind = NameKind::Macro(def); - NameDefinition { kind, visibility } + NameDefinition { kind } } PathResolution::SelfType(impl_block) => { let kind = NameKind::SelfType(impl_block); - NameDefinition { kind, visibility } + NameDefinition { kind } } }; Some(res) diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs index f9bbe64a4..e5ac12044 100644 --- a/crates/ra_ide/src/references/search_scope.rs +++ b/crates/ra_ide/src/references/search_scope.rs @@ -43,7 +43,7 @@ impl SearchScope { return SearchScope::new(res); } - let vis = def.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); + let vis = def.visibility(db).as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); if vis.as_str() == "pub(super)" { if let Some(parent_module) = module.parent(db) { -- cgit v1.2.3