diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 31 |
4 files changed, 19 insertions, 24 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index c5cfd875f..3f0ebca0d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -234,6 +234,10 @@ impl Module { | |||
234 | .collect() | 234 | .collect() |
235 | } | 235 | } |
236 | 236 | ||
237 | pub fn visibility_of(self, db: &dyn HirDatabase, def: &ModuleDef) -> Option<Visibility> { | ||
238 | db.crate_def_map(self.id.krate)[self.id.local_id].scope.visbility_of(def.clone().into()) | ||
239 | } | ||
240 | |||
237 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { | 241 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { |
238 | let _p = profile("Module::diagnostics"); | 242 | let _p = profile("Module::diagnostics"); |
239 | let crate_def_map = db.crate_def_map(self.id.krate); | 243 | let crate_def_map = db.crate_def_map(self.id.krate); |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 713d45f48..5af7e5d6d 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -54,7 +54,7 @@ pub use crate::{ | |||
54 | Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, | 54 | Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, |
55 | DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, | 55 | DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, |
56 | HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, | 56 | HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, |
57 | StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, | 57 | StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, |
58 | }, | 58 | }, |
59 | has_source::HasSource, | 59 | has_source::HasSource, |
60 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, | 60 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, |
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index 5e943b780..ef1aaba6f 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -68,6 +68,12 @@ impl ItemScope { | |||
68 | self.impls.iter().copied() | 68 | self.impls.iter().copied() |
69 | } | 69 | } |
70 | 70 | ||
71 | pub fn visbility_of(&self, def: ModuleDefId) -> Option<Visibility> { | ||
72 | self.name_of(ItemInNs::Types(def)) | ||
73 | .or_else(|| self.name_of(ItemInNs::Values(def))) | ||
74 | .map(|(_, v)| v) | ||
75 | } | ||
76 | |||
71 | /// Iterate over all module scoped macros | 77 | /// Iterate over all module scoped macros |
72 | pub(crate) fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a { | 78 | pub(crate) fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a { |
73 | self.visible.iter().filter_map(|(name, def)| def.take_macros().map(|macro_| (name, macro_))) | 79 | self.visible.iter().filter_map(|(name, def)| def.take_macros().map(|macro_| (name, macro_))) |
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 97961bb6d..e9934844e 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -6,12 +6,12 @@ | |||
6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). | 6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). |
7 | 7 | ||
8 | use hir::{ | 8 | use hir::{ |
9 | Adt, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, | 9 | HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, Semantics, |
10 | Semantics, StructField, TypeParam, | 10 | StructField, TypeParam, Visibility, |
11 | }; | 11 | }; |
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
13 | use ra_syntax::{ | 13 | use ra_syntax::{ |
14 | ast::{self, AstNode, VisibilityOwner}, | 14 | ast::{self, AstNode}, |
15 | match_ast, | 15 | match_ast, |
16 | }; | 16 | }; |
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
@@ -41,28 +41,13 @@ impl Definition { | |||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | pub fn visibility(&self, db: &RootDatabase) -> Option<ast::Visibility> { | 44 | pub fn visibility(&self, db: &RootDatabase) -> Option<Visibility> { |
45 | let module = self.module(db); | ||
46 | |||
45 | match self { | 47 | match self { |
46 | Definition::Macro(_) => None, | 48 | Definition::Macro(_) => None, |
47 | Definition::StructField(sf) => match sf.source(db).value { | 49 | Definition::StructField(sf) => Some(sf.visibility(db)), |
48 | FieldSource::Named(it) => it.visibility(), | 50 | Definition::ModuleDef(def) => module?.visibility_of(db, def), |
49 | FieldSource::Pos(it) => it.visibility(), | ||
50 | }, | ||
51 | Definition::ModuleDef(def) => match def { | ||
52 | ModuleDef::Module(it) => it.declaration_source(db)?.value.visibility(), | ||
53 | ModuleDef::Function(it) => it.source(db).value.visibility(), | ||
54 | ModuleDef::Adt(adt) => match adt { | ||
55 | Adt::Struct(it) => it.source(db).value.visibility(), | ||
56 | Adt::Union(it) => it.source(db).value.visibility(), | ||
57 | Adt::Enum(it) => it.source(db).value.visibility(), | ||
58 | }, | ||
59 | ModuleDef::Const(it) => it.source(db).value.visibility(), | ||
60 | ModuleDef::Static(it) => it.source(db).value.visibility(), | ||
61 | ModuleDef::Trait(it) => it.source(db).value.visibility(), | ||
62 | ModuleDef::TypeAlias(it) => it.source(db).value.visibility(), | ||
63 | ModuleDef::EnumVariant(_) => None, | ||
64 | ModuleDef::BuiltinType(_) => None, | ||
65 | }, | ||
66 | Definition::SelfType(_) => None, | 51 | Definition::SelfType(_) => None, |
67 | Definition::Local(_) => None, | 52 | Definition::Local(_) => None, |
68 | Definition::TypeParam(_) => None, | 53 | Definition::TypeParam(_) => None, |