diff options
author | Aleksey Kladov <[email protected]> | 2019-01-08 12:19:37 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 12:19:37 +0000 |
commit | e30c533eb67ba8a24708a94385849854c17e67f9 (patch) | |
tree | 95f42bac96ce8c851938854860746be65e535acd /crates/ra_hir | |
parent | 3bb1cb7017aab6fddb38eae3ca671ecbdaedb4da (diff) |
move stuct to code_model_api
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 3 |
3 files changed, 27 insertions, 22 deletions
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; | |||
4 | use ra_syntax::ast::{self, NameOwner, StructFlavor}; | 4 | use ra_syntax::ast::{self, NameOwner, StructFlavor}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | DefId, Name, AsName, | 7 | DefId, Name, AsName, Struct, |
8 | db::HirDatabase, | 8 | db::HirDatabase, |
9 | type_ref::TypeRef, | 9 | type_ref::TypeRef, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | pub struct Struct { | ||
13 | def_id: DefId, | ||
14 | } | ||
15 | |||
16 | impl Struct { | 12 | impl Struct { |
17 | pub(crate) fn new(def_id: DefId) -> Self { | 13 | pub(crate) fn new(def_id: DefId) -> Self { |
18 | Struct { def_id } | 14 | Struct { def_id } |
19 | } | 15 | } |
20 | 16 | ||
21 | pub fn def_id(&self) -> DefId { | 17 | pub(crate) fn struct_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<StructData>> { |
22 | self.def_id | ||
23 | } | ||
24 | |||
25 | pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { | ||
26 | Ok(db.struct_data(self.def_id)?.variant_data.clone()) | ||
27 | } | ||
28 | |||
29 | pub fn struct_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<StructData>> { | ||
30 | Ok(db.struct_data(self.def_id)?) | 18 | Ok(db.struct_data(self.def_id)?) |
31 | } | 19 | } |
32 | |||
33 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { | ||
34 | Ok(db.struct_data(self.def_id)?.name.clone()) | ||
35 | } | ||
36 | } | 20 | } |
37 | 21 | ||
38 | #[derive(Debug, Clone, PartialEq, Eq)] | 22 | #[derive(Debug, Clone, PartialEq, Eq)] |
39 | pub struct StructData { | 23 | pub struct StructData { |
40 | name: Option<Name>, | 24 | pub(crate) name: Option<Name>, |
41 | variant_data: Arc<VariantData>, | 25 | pub(crate) variant_data: Arc<VariantData>, |
42 | } | 26 | } |
43 | 27 | ||
44 | impl StructData { | 28 | 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 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
1 | use relative_path::RelativePathBuf; | 3 | use relative_path::RelativePathBuf; |
2 | use ra_db::{CrateId, Cancelable, FileId}; | 4 | use ra_db::{CrateId, Cancelable, FileId}; |
3 | use ra_syntax::{ast, TreePtr, SyntaxNode}; | 5 | use ra_syntax::{ast, TreePtr, SyntaxNode}; |
4 | 6 | ||
5 | use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope}; | 7 | use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope, adt::VariantData}; |
6 | 8 | ||
7 | /// hir::Crate describes a single crate. It's the main inteface with which | 9 | /// hir::Crate describes a single crate. It's the main inteface with which |
8 | /// crate's dependencies interact. Mostly, it should be just a proxy for the | 10 | /// crate's dependencies interact. Mostly, it should be just a proxy for the |
@@ -111,3 +113,21 @@ impl Module { | |||
111 | self.problems_impl(db) | 113 | self.problems_impl(db) |
112 | } | 114 | } |
113 | } | 115 | } |
116 | |||
117 | pub struct Struct { | ||
118 | pub(crate) def_id: DefId, | ||
119 | } | ||
120 | |||
121 | impl Struct { | ||
122 | pub fn def_id(&self) -> DefId { | ||
123 | self.def_id | ||
124 | } | ||
125 | |||
126 | pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { | ||
127 | Ok(self.struct_data(db)?.variant_data.clone()) | ||
128 | } | ||
129 | |||
130 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { | ||
131 | Ok(self.struct_data(db)?.name.clone()) | ||
132 | } | ||
133 | } | ||
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::{ | |||
50 | module_tree::ModuleId, | 50 | module_tree::ModuleId, |
51 | nameres::{ItemMap, PerNs, Namespace, Resolution}, | 51 | nameres::{ItemMap, PerNs, Namespace, Resolution}, |
52 | function::{Function, FnSignature, FnScopes, ScopesWithSyntaxMapping}, | 52 | function::{Function, FnSignature, FnScopes, ScopesWithSyntaxMapping}, |
53 | adt::{Struct, Enum}, | 53 | adt::Enum, |
54 | ty::Ty, | 54 | ty::Ty, |
55 | impl_block::{ImplBlock, ImplItem}, | 55 | impl_block::{ImplBlock, ImplItem}, |
56 | }; | 56 | }; |
@@ -60,6 +60,7 @@ pub use self::function::FnSignatureInfo; | |||
60 | pub use self::code_model_api::{ | 60 | pub use self::code_model_api::{ |
61 | Crate, CrateDependency, | 61 | Crate, CrateDependency, |
62 | Module, ModuleSource, Problem, | 62 | Module, ModuleSource, Problem, |
63 | Struct, | ||
63 | }; | 64 | }; |
64 | 65 | ||
65 | pub enum Def { | 66 | pub enum Def { |