mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
move enum to code_model_api
This commit is contained in:
parent
e30c533eb6
commit
2d4dc22af8
3 changed files with 26 additions and 29 deletions
|
@ -1,11 +1,9 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ra_db::Cancelable;
|
|
||||||
use ra_syntax::ast::{self, NameOwner, StructFlavor};
|
use ra_syntax::ast::{self, NameOwner, StructFlavor};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DefId, Name, AsName, Struct,
|
DefId, Name, AsName, Struct, Enum,
|
||||||
db::HirDatabase,
|
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,10 +11,6 @@ impl Struct {
|
||||||
pub(crate) fn new(def_id: DefId) -> Self {
|
pub(crate) fn new(def_id: DefId) -> Self {
|
||||||
Struct { def_id }
|
Struct { def_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn struct_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<StructData>> {
|
|
||||||
Ok(db.struct_data(self.def_id)?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -42,32 +36,16 @@ impl StructData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Enum {
|
|
||||||
def_id: DefId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Enum {
|
impl Enum {
|
||||||
pub(crate) fn new(def_id: DefId) -> Self {
|
pub(crate) fn new(def_id: DefId) -> Self {
|
||||||
Enum { def_id }
|
Enum { def_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_id(&self) -> DefId {
|
|
||||||
self.def_id
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
|
|
||||||
Ok(db.enum_data(self.def_id)?.name.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, Arc<VariantData>)>> {
|
|
||||||
Ok(db.enum_data(self.def_id)?.variants.clone())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct EnumData {
|
pub struct EnumData {
|
||||||
name: Option<Name>,
|
pub(crate) name: Option<Name>,
|
||||||
variants: Vec<(Name, Arc<VariantData>)>,
|
pub(crate) variants: Vec<(Name, Arc<VariantData>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EnumData {
|
impl EnumData {
|
||||||
|
|
|
@ -114,6 +114,7 @@ impl Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Struct {
|
pub struct Struct {
|
||||||
pub(crate) def_id: DefId,
|
pub(crate) def_id: DefId,
|
||||||
}
|
}
|
||||||
|
@ -124,10 +125,29 @@ impl Struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> {
|
pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> {
|
||||||
Ok(self.struct_data(db)?.variant_data.clone())
|
Ok(db.struct_data(self.def_id)?.variant_data.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
|
pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
|
||||||
Ok(self.struct_data(db)?.name.clone())
|
Ok(db.struct_data(self.def_id)?.name.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Enum {
|
||||||
|
pub(crate) def_id: DefId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Enum {
|
||||||
|
pub fn def_id(&self) -> DefId {
|
||||||
|
self.def_id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
|
||||||
|
Ok(db.enum_data(self.def_id)?.name.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, Arc<VariantData>)>> {
|
||||||
|
Ok(db.enum_data(self.def_id)?.variants.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ pub use self::{
|
||||||
module_tree::ModuleId,
|
module_tree::ModuleId,
|
||||||
nameres::{ItemMap, PerNs, Namespace, Resolution},
|
nameres::{ItemMap, PerNs, Namespace, Resolution},
|
||||||
function::{Function, FnSignature, FnScopes, ScopesWithSyntaxMapping},
|
function::{Function, FnSignature, FnScopes, ScopesWithSyntaxMapping},
|
||||||
adt::Enum,
|
|
||||||
ty::Ty,
|
ty::Ty,
|
||||||
impl_block::{ImplBlock, ImplItem},
|
impl_block::{ImplBlock, ImplItem},
|
||||||
};
|
};
|
||||||
|
@ -60,7 +59,7 @@ pub use self::function::FnSignatureInfo;
|
||||||
pub use self::code_model_api::{
|
pub use self::code_model_api::{
|
||||||
Crate, CrateDependency,
|
Crate, CrateDependency,
|
||||||
Module, ModuleSource, Problem,
|
Module, ModuleSource, Problem,
|
||||||
Struct,
|
Struct, Enum,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum Def {
|
pub enum Def {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue