aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorFedor Sakharov <[email protected]>2020-05-11 12:28:14 +0100
committerFedor Sakharov <[email protected]>2020-05-11 12:28:14 +0100
commit3d66aa054230ad788162ce49f0d334e900458cac (patch)
tree7828ed862f66f0e99f448e3112930ea602aef3c7 /crates/ra_hir
parent753e1e679cf14b4ead73602976d43a8dc89a7052 (diff)
New definition_visibility method
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index be18c845c..cb91bd965 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -148,6 +148,26 @@ impl ModuleDef {
148 ModuleDef::BuiltinType(_) => None, 148 ModuleDef::BuiltinType(_) => None,
149 } 149 }
150 } 150 }
151
152 pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option<Visibility> {
153 let module = match self {
154 ModuleDef::Module(it) => it.parent(db)?,
155 ModuleDef::Function(it) => return Some(it.visibility(db)),
156 ModuleDef::Adt(it) => it.module(db),
157 ModuleDef::EnumVariant(it) => {
158 let parent = it.parent_enum(db);
159 let module = it.module(db);
160 return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent)));
161 }
162 ModuleDef::Const(it) => return Some(it.visibility(db)),
163 ModuleDef::Static(it) => it.module(db),
164 ModuleDef::Trait(it) => it.module(db),
165 ModuleDef::TypeAlias(it) => return Some(it.visibility(db)),
166 ModuleDef::BuiltinType(_) => return None,
167 };
168
169 module.visibility_of(db, self)
170 }
151} 171}
152 172
153pub use hir_def::{ 173pub use hir_def::{