aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs48
1 files changed, 40 insertions, 8 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 4d1e8f921..911c809fd 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -204,19 +204,25 @@ impl Module {
204 } 204 }
205 205
206 /// Returns a `ModuleScope`: a set of items, visible in this module. 206 /// Returns a `ModuleScope`: a set of items, visible in this module.
207 pub fn scope(self, db: &impl HirDatabase, visible_from: Option<Module>) -> Vec<(Name, ScopeDef)> { 207 pub fn scope(
208 self,
209 db: &impl HirDatabase,
210 visible_from: Option<Module>,
211 ) -> Vec<(Name, ScopeDef)> {
208 db.crate_def_map(self.id.krate)[self.id.local_id] 212 db.crate_def_map(self.id.krate)[self.id.local_id]
209 .scope 213 .scope
210 .entries() 214 .entries()
211 .filter_map(|(name, def)| if let Some(m) = visible_from { 215 .filter_map(|(name, def)| {
212 let filtered = def.filter_visibility(|vis| vis.is_visible_from(db, m.id)); 216 if let Some(m) = visible_from {
213 if filtered.is_none() && !def.is_none() { 217 let filtered = def.filter_visibility(|vis| vis.is_visible_from(db, m.id));
214 None 218 if filtered.is_none() && !def.is_none() {
219 None
220 } else {
221 Some((name, filtered))
222 }
215 } else { 223 } else {
216 Some((name, filtered)) 224 Some((name, def))
217 } 225 }
218 } else {
219 Some((name, def))
220 }) 226 })
221 .map(|(name, def)| (name.clone(), def.into())) 227 .map(|(name, def)| (name.clone(), def.into()))
222 .collect() 228 .collect()
@@ -608,6 +614,14 @@ impl Const {
608 } 614 }
609} 615}
610 616
617impl HasVisibility for Const {
618 fn visibility(&self, db: &impl HirDatabase) -> Visibility {
619 let function_data = db.const_data(self.id);
620 let visibility = &function_data.visibility;
621 visibility.resolve(db, &self.id.resolver(db))
622 }
623}
624
611#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 625#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
612pub struct Static { 626pub struct Static {
613 pub(crate) id: StaticId, 627 pub(crate) id: StaticId,
@@ -682,6 +696,14 @@ impl TypeAlias {
682 } 696 }
683} 697}
684 698
699impl HasVisibility for TypeAlias {
700 fn visibility(&self, db: &impl HirDatabase) -> Visibility {
701 let function_data = db.type_alias_data(self.id);
702 let visibility = &function_data.visibility;
703 visibility.resolve(db, &self.id.resolver(db))
704 }
705}
706
685#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 707#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
686pub struct MacroDef { 708pub struct MacroDef {
687 pub(crate) id: MacroDefId, 709 pub(crate) id: MacroDefId,
@@ -769,6 +791,16 @@ impl AssocItem {
769 } 791 }
770} 792}
771 793
794impl HasVisibility for AssocItem {
795 fn visibility(&self, db: &impl HirDatabase) -> Visibility {
796 match self {
797 AssocItem::Function(f) => f.visibility(db),
798 AssocItem::Const(c) => c.visibility(db),
799 AssocItem::TypeAlias(t) => t.visibility(db),
800 }
801 }
802}
803
772#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] 804#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
773pub enum GenericDef { 805pub enum GenericDef {
774 Function(Function), 806 Function(Function),