mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue