From 3d66aa054230ad788162ce49f0d334e900458cac Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Mon, 11 May 2020 14:28:14 +0300 Subject: New definition_visibility method --- crates/ra_hir/src/code_model.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crates/ra_hir') 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 { ModuleDef::BuiltinType(_) => None, } } + + pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option { + let module = match self { + ModuleDef::Module(it) => it.parent(db)?, + ModuleDef::Function(it) => return Some(it.visibility(db)), + ModuleDef::Adt(it) => it.module(db), + ModuleDef::EnumVariant(it) => { + let parent = it.parent_enum(db); + let module = it.module(db); + return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent))); + } + ModuleDef::Const(it) => return Some(it.visibility(db)), + ModuleDef::Static(it) => it.module(db), + ModuleDef::Trait(it) => it.module(db), + ModuleDef::TypeAlias(it) => return Some(it.visibility(db)), + ModuleDef::BuiltinType(_) => return None, + }; + + module.visibility_of(db, self) + } } pub use hir_def::{ -- cgit v1.2.3