mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
move query impls to adt
This commit is contained in:
parent
64f202bdd7
commit
5edcf313f6
3 changed files with 31 additions and 25 deletions
|
@ -1,9 +1,10 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use ra_syntax::ast::{self, NameOwner, StructFlavor};
|
||||
use ra_db::Cancelable;
|
||||
use ra_syntax::ast::{self, NameOwner, StructFlavor, AstNode};
|
||||
|
||||
use crate::{
|
||||
DefId, Name, AsName, Struct, Enum, VariantData, StructField,
|
||||
DefId, Name, AsName, Struct, Enum, VariantData, StructField, HirDatabase, DefKind,
|
||||
type_ref::TypeRef,
|
||||
};
|
||||
|
||||
|
@ -20,12 +21,24 @@ pub struct StructData {
|
|||
}
|
||||
|
||||
impl StructData {
|
||||
pub(crate) fn new(struct_def: &ast::StructDef) -> StructData {
|
||||
fn new(struct_def: &ast::StructDef) -> StructData {
|
||||
let name = struct_def.name().map(|n| n.as_name());
|
||||
let variant_data = VariantData::new(struct_def.flavor());
|
||||
let variant_data = Arc::new(variant_data);
|
||||
StructData { name, variant_data }
|
||||
}
|
||||
|
||||
pub(crate) fn struct_data_query(
|
||||
db: &impl HirDatabase,
|
||||
def_id: DefId,
|
||||
) -> Cancelable<Arc<StructData>> {
|
||||
let def_loc = def_id.loc(db);
|
||||
assert!(def_loc.kind == DefKind::Struct);
|
||||
let syntax = db.file_item(def_loc.source_item_id);
|
||||
let struct_def =
|
||||
ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node");
|
||||
Ok(Arc::new(StructData::new(struct_def)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Enum {
|
||||
|
@ -41,7 +54,7 @@ pub struct EnumData {
|
|||
}
|
||||
|
||||
impl EnumData {
|
||||
pub(crate) fn new(enum_def: &ast::EnumDef) -> Self {
|
||||
fn new(enum_def: &ast::EnumDef) -> Self {
|
||||
let name = enum_def.name().map(|n| n.as_name());
|
||||
let variants = if let Some(evl) = enum_def.variant_list() {
|
||||
evl.variants()
|
||||
|
@ -57,6 +70,17 @@ impl EnumData {
|
|||
};
|
||||
EnumData { name, variants }
|
||||
}
|
||||
|
||||
pub(crate) fn enum_data_query(
|
||||
db: &impl HirDatabase,
|
||||
def_id: DefId,
|
||||
) -> Cancelable<Arc<EnumData>> {
|
||||
let def_loc = def_id.loc(db);
|
||||
assert!(def_loc.kind == DefKind::Enum);
|
||||
let syntax = db.file_item(def_loc.source_item_id);
|
||||
let enum_def = ast::EnumDef::cast(&syntax).expect("enum def should point to EnumDef node");
|
||||
Ok(Arc::new(EnumData::new(enum_def)))
|
||||
}
|
||||
}
|
||||
|
||||
impl VariantData {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue