aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2018-12-25 14:15:40 +0000
committerFlorian Diebold <[email protected]>2018-12-25 14:27:15 +0000
commitab0b63992be0cec4999810096a53b40f63f90349 (patch)
tree5e6dca70c4e842bc87e6e1287cca176031ecc92f /crates/ra_hir
parent0d724ea572a5dd26acbbf2eb4538eabe454fb894 (diff)
Implement basic completion for fields
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/adt.rs14
-rw-r--r--crates/ra_hir/src/lib.rs1
-rw-r--r--crates/ra_hir/src/ty.rs5
3 files changed, 17 insertions, 3 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 03770ed7d..e65f8deb8 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -124,6 +124,15 @@ pub struct StructField {
124 ty: Ty, 124 ty: Ty,
125} 125}
126 126
127impl StructField {
128 pub fn name(&self) -> SmolStr {
129 self.name.clone()
130 }
131 pub fn ty(&self) -> Ty {
132 self.ty.clone()
133 }
134}
135
127/// Fields of an enum variant or struct 136/// Fields of an enum variant or struct
128#[derive(Debug, Clone, PartialEq, Eq)] 137#[derive(Debug, Clone, PartialEq, Eq)]
129pub enum VariantData { 138pub enum VariantData {
@@ -168,7 +177,10 @@ impl VariantData {
168 } 177 }
169 178
170 pub(crate) fn get_field_ty(&self, field_name: &str) -> Option<Ty> { 179 pub(crate) fn get_field_ty(&self, field_name: &str) -> Option<Ty> {
171 self.fields().iter().find(|f| f.name == field_name).map(|f| f.ty.clone()) 180 self.fields()
181 .iter()
182 .find(|f| f.name == field_name)
183 .map(|f| f.ty.clone())
172 } 184 }
173 185
174 pub fn fields(&self) -> &[StructField] { 186 pub fn fields(&self) -> &[StructField] {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 796970d8a..68fdbb7ea 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -44,6 +44,7 @@ pub use self::{
44 module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, 44 module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution},
45 function::{Function, FnScopes}, 45 function::{Function, FnScopes},
46 adt::{Struct, Enum}, 46 adt::{Struct, Enum},
47 ty::Ty,
47}; 48};
48 49
49pub use self::function::FnSignatureInfo; 50pub use self::function::FnSignatureInfo;
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index f931f3c87..83da13f1a 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -574,7 +574,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
574 match receiver_ty { 574 match receiver_ty {
575 Ty::Tuple(fields) => { 575 Ty::Tuple(fields) => {
576 let i = text.parse::<usize>().ok(); 576 let i = text.parse::<usize>().ok();
577 i.and_then(|i| fields.get(i).cloned()).unwrap_or(Ty::Unknown) 577 i.and_then(|i| fields.get(i).cloned())
578 .unwrap_or(Ty::Unknown)
578 } 579 }
579 Ty::Adt { def_id, .. } => { 580 Ty::Adt { def_id, .. } => {
580 let field_ty = match def_id.resolve(self.db)? { 581 let field_ty = match def_id.resolve(self.db)? {
@@ -589,7 +590,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
589 } else { 590 } else {
590 Ty::Unknown 591 Ty::Unknown
591 } 592 }
592 }, 593 }
593 ast::Expr::TryExpr(e) => { 594 ast::Expr::TryExpr(e) => {
594 let _inner_ty = if let Some(e) = e.expr() { 595 let _inner_ty = if let Some(e) = e.expr() {
595 self.infer_expr(e)? 596 self.infer_expr(e)?