diff options
author | Aleksey Kladov <[email protected]> | 2019-01-25 17:32:34 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-25 17:38:03 +0000 |
commit | 9f2574c97e55e2af1d1b93f60307aa9d41f55f42 (patch) | |
tree | 78e2eb10ef2046c4aa03b8d486325f1691b81342 /crates/ra_hir/src/code_model_api.rs | |
parent | 0044514a4e5fe2484071dc81ae59fc291626c05a (diff) |
add ability to get strcut field source
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 118562984..fdea5be57 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -10,8 +10,8 @@ use crate::{ | |||
10 | nameres::{ModuleScope, lower::ImportId}, | 10 | nameres::{ModuleScope, lower::ImportId}, |
11 | db::HirDatabase, | 11 | db::HirDatabase, |
12 | expr::BodySyntaxMapping, | 12 | expr::BodySyntaxMapping, |
13 | ty::{InferenceResult, VariantDef}, | 13 | ty::InferenceResult, |
14 | adt::{EnumVariantId, StructFieldId}, | 14 | adt::{EnumVariantId, StructFieldId, VariantDef}, |
15 | generics::GenericParams, | 15 | generics::GenericParams, |
16 | docs::{Documentation, Docs, docs_from_ast}, | 16 | docs::{Documentation, Docs, docs_from_ast}, |
17 | module_tree::ModuleId, | 17 | module_tree::ModuleId, |
@@ -179,10 +179,16 @@ impl Module { | |||
179 | 179 | ||
180 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 180 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
181 | pub struct StructField { | 181 | pub struct StructField { |
182 | parent: VariantDef, | 182 | pub(crate) parent: VariantDef, |
183 | pub(crate) id: StructFieldId, | 183 | pub(crate) id: StructFieldId, |
184 | } | 184 | } |
185 | 185 | ||
186 | #[derive(Debug)] | ||
187 | pub enum FieldSource { | ||
188 | Named(TreeArc<ast::NamedFieldDef>), | ||
189 | Pos(TreeArc<ast::PosField>), | ||
190 | } | ||
191 | |||
186 | impl StructField { | 192 | impl StructField { |
187 | pub fn name(&self, db: &impl HirDatabase) -> Name { | 193 | pub fn name(&self, db: &impl HirDatabase) -> Name { |
188 | self.parent.variant_data(db).fields().unwrap()[self.id] | 194 | self.parent.variant_data(db).fields().unwrap()[self.id] |
@@ -190,6 +196,10 @@ impl StructField { | |||
190 | .clone() | 196 | .clone() |
191 | } | 197 | } |
192 | 198 | ||
199 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, FieldSource) { | ||
200 | self.source_impl(db) | ||
201 | } | ||
202 | |||
193 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { | 203 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { |
194 | db.type_for_field(*self) | 204 | db.type_for_field(*self) |
195 | } | 205 | } |