mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Add visibility in code model for fields
This commit is contained in:
parent
1ce809d0fa
commit
ca15cf422c
2 changed files with 20 additions and 3 deletions
|
@ -118,7 +118,7 @@ impl_froms!(
|
|||
BuiltinType
|
||||
);
|
||||
|
||||
pub use hir_def::attr::Attrs;
|
||||
pub use hir_def::{attr::Attrs, visibility::ResolvedVisibility};
|
||||
|
||||
impl Module {
|
||||
pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module {
|
||||
|
@ -255,6 +255,15 @@ impl StructField {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for StructField {
|
||||
fn visibility(&self, db: &impl HirDatabase) -> ResolvedVisibility {
|
||||
let struct_field_id: hir_def::StructFieldId = (*self).into();
|
||||
let visibility = db.visibility(struct_field_id.into());
|
||||
let parent_id: hir_def::VariantId = self.parent.into();
|
||||
visibility.resolve(db, &parent_id.resolver(db))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Struct {
|
||||
pub(crate) id: StructId,
|
||||
|
@ -1041,3 +1050,11 @@ impl<T: Into<AttrDef> + Copy> Docs for T {
|
|||
db.documentation(def.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasVisibility {
|
||||
fn visibility(&self, db: &impl HirDatabase) -> ResolvedVisibility;
|
||||
fn visible_from(&self, db: &impl HirDatabase, module: Module) -> bool {
|
||||
let vis = self.visibility(db);
|
||||
vis.visible_from(db, module.id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ mod from_source;
|
|||
pub use crate::{
|
||||
code_model::{
|
||||
Adt, AssocItem, AttrDef, Const, Crate, CrateDependency, DefWithBody, Docs, Enum,
|
||||
EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Local, MacroDef,
|
||||
Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias,
|
||||
EnumVariant, FieldSource, Function, GenericDef, HasAttrs, HasVisibility, ImplBlock, Local,
|
||||
MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias,
|
||||
TypeParam, Union, VariantDef,
|
||||
},
|
||||
from_source::FromSource,
|
||||
|
|
Loading…
Reference in a new issue