From e30c533eb67ba8a24708a94385849854c17e67f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 15:19:37 +0300 Subject: move stuct to code_model_api --- crates/ra_hir/src/adt.rs | 24 ++++-------------------- crates/ra_hir/src/code_model_api.rs | 22 +++++++++++++++++++++- crates/ra_hir/src/lib.rs | 3 ++- 3 files changed, 27 insertions(+), 22 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index b75adda84..4b35c01b3 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -4,41 +4,25 @@ use ra_db::Cancelable; use ra_syntax::ast::{self, NameOwner, StructFlavor}; use crate::{ - DefId, Name, AsName, + DefId, Name, AsName, Struct, db::HirDatabase, type_ref::TypeRef, }; -pub struct Struct { - def_id: DefId, -} - impl Struct { pub(crate) fn new(def_id: DefId) -> Self { Struct { def_id } } - pub fn def_id(&self) -> DefId { - self.def_id - } - - pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.struct_data(self.def_id)?.variant_data.clone()) - } - - pub fn struct_data(&self, db: &impl HirDatabase) -> Cancelable> { + pub(crate) fn struct_data(&self, db: &impl HirDatabase) -> Cancelable> { Ok(db.struct_data(self.def_id)?) } - - pub fn name(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.struct_data(self.def_id)?.name.clone()) - } } #[derive(Debug, Clone, PartialEq, Eq)] pub struct StructData { - name: Option, - variant_data: Arc, + pub(crate) name: Option, + pub(crate) variant_data: Arc, } impl StructData { diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 43cddb504..12947da2d 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -1,8 +1,10 @@ +use std::sync::Arc; + use relative_path::RelativePathBuf; use ra_db::{CrateId, Cancelable, FileId}; use ra_syntax::{ast, TreePtr, SyntaxNode}; -use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope}; +use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope, adt::VariantData}; /// hir::Crate describes a single crate. It's the main inteface with which /// crate's dependencies interact. Mostly, it should be just a proxy for the @@ -111,3 +113,21 @@ impl Module { self.problems_impl(db) } } + +pub struct Struct { + pub(crate) def_id: DefId, +} + +impl Struct { + pub fn def_id(&self) -> DefId { + self.def_id + } + + pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable> { + Ok(self.struct_data(db)?.variant_data.clone()) + } + + pub fn name(&self, db: &impl HirDatabase) -> Cancelable> { + Ok(self.struct_data(db)?.name.clone()) + } +} diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 9f133f174..9b66f5bb7 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -50,7 +50,7 @@ pub use self::{ module_tree::ModuleId, nameres::{ItemMap, PerNs, Namespace, Resolution}, function::{Function, FnSignature, FnScopes, ScopesWithSyntaxMapping}, - adt::{Struct, Enum}, + adt::Enum, ty::Ty, impl_block::{ImplBlock, ImplItem}, }; @@ -60,6 +60,7 @@ pub use self::function::FnSignatureInfo; pub use self::code_model_api::{ Crate, CrateDependency, Module, ModuleSource, Problem, + Struct, }; pub enum Def { -- cgit v1.2.3