mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +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
|
BuiltinType
|
||||||
);
|
);
|
||||||
|
|
||||||
pub use hir_def::attr::Attrs;
|
pub use hir_def::{attr::Attrs, visibility::ResolvedVisibility};
|
||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> 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)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Struct {
|
pub struct Struct {
|
||||||
pub(crate) id: StructId,
|
pub(crate) id: StructId,
|
||||||
|
@ -1041,3 +1050,11 @@ impl<T: Into<AttrDef> + Copy> Docs for T {
|
||||||
db.documentation(def.into())
|
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::{
|
pub use crate::{
|
||||||
code_model::{
|
code_model::{
|
||||||
Adt, AssocItem, AttrDef, Const, Crate, CrateDependency, DefWithBody, Docs, Enum,
|
Adt, AssocItem, AttrDef, Const, Crate, CrateDependency, DefWithBody, Docs, Enum,
|
||||||
EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Local, MacroDef,
|
EnumVariant, FieldSource, Function, GenericDef, HasAttrs, HasVisibility, ImplBlock, Local,
|
||||||
Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias,
|
MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias,
|
||||||
TypeParam, Union, VariantDef,
|
TypeParam, Union, VariantDef,
|
||||||
},
|
},
|
||||||
from_source::FromSource,
|
from_source::FromSource,
|
||||||
|
|
Loading…
Reference in a new issue