mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
add ability to get strcut field source
This commit is contained in:
parent
0044514a4e
commit
9f2574c97e
7 changed files with 131 additions and 37 deletions
|
@ -10,8 +10,8 @@ use crate::{
|
|||
nameres::{ModuleScope, lower::ImportId},
|
||||
db::HirDatabase,
|
||||
expr::BodySyntaxMapping,
|
||||
ty::{InferenceResult, VariantDef},
|
||||
adt::{EnumVariantId, StructFieldId},
|
||||
ty::InferenceResult,
|
||||
adt::{EnumVariantId, StructFieldId, VariantDef},
|
||||
generics::GenericParams,
|
||||
docs::{Documentation, Docs, docs_from_ast},
|
||||
module_tree::ModuleId,
|
||||
|
@ -179,10 +179,16 @@ impl Module {
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct StructField {
|
||||
parent: VariantDef,
|
||||
pub(crate) parent: VariantDef,
|
||||
pub(crate) id: StructFieldId,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FieldSource {
|
||||
Named(TreeArc<ast::NamedFieldDef>),
|
||||
Pos(TreeArc<ast::PosField>),
|
||||
}
|
||||
|
||||
impl StructField {
|
||||
pub fn name(&self, db: &impl HirDatabase) -> Name {
|
||||
self.parent.variant_data(db).fields().unwrap()[self.id]
|
||||
|
@ -190,6 +196,10 @@ impl StructField {
|
|||
.clone()
|
||||
}
|
||||
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, FieldSource) {
|
||||
self.source_impl(db)
|
||||
}
|
||||
|
||||
pub fn ty(&self, db: &impl HirDatabase) -> Ty {
|
||||
db.type_for_field(*self)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue