diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 36 |
2 files changed, 21 insertions, 21 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9baebf643..3801fce23 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -25,7 +25,7 @@ use hir_ty::{ | |||
25 | autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy, | 25 | autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy, |
26 | Canonical, InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, | 26 | Canonical, InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, |
27 | }; | 27 | }; |
28 | use ra_db::{CrateId, Edition, FileId}; | 28 | use ra_db::{CrateId, CrateName, Edition, FileId}; |
29 | use ra_prof::profile; | 29 | use ra_prof::profile; |
30 | use ra_syntax::{ | 30 | use ra_syntax::{ |
31 | ast::{self, AttrsOwner, NameOwner}, | 31 | ast::{self, AttrsOwner, NameOwner}, |
@@ -91,6 +91,10 @@ impl Crate { | |||
91 | db.crate_graph()[self.id].edition | 91 | db.crate_graph()[self.id].edition |
92 | } | 92 | } |
93 | 93 | ||
94 | pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> { | ||
95 | db.crate_graph()[self.id].display_name.as_ref().cloned() | ||
96 | } | ||
97 | |||
94 | pub fn all(db: &dyn HirDatabase) -> Vec<Crate> { | 98 | pub fn all(db: &dyn HirDatabase) -> Vec<Crate> { |
95 | db.crate_graph().iter().map(|id| Crate { id }).collect() | 99 | db.crate_graph().iter().map(|id| Crate { id }).collect() |
96 | } | 100 | } |
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 226fb4534..58ae6ce41 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -139,7 +139,7 @@ impl SourceAnalyzer { | |||
139 | &self, | 139 | &self, |
140 | db: &dyn HirDatabase, | 140 | db: &dyn HirDatabase, |
141 | field: &ast::FieldExpr, | 141 | field: &ast::FieldExpr, |
142 | ) -> Option<crate::StructField> { | 142 | ) -> Option<StructField> { |
143 | let expr_id = self.expr_id(db, &field.clone().into())?; | 143 | let expr_id = self.expr_id(db, &field.clone().into())?; |
144 | self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into()) | 144 | self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into()) |
145 | } | 145 | } |
@@ -148,21 +148,19 @@ impl SourceAnalyzer { | |||
148 | &self, | 148 | &self, |
149 | db: &dyn HirDatabase, | 149 | db: &dyn HirDatabase, |
150 | field: &ast::RecordField, | 150 | field: &ast::RecordField, |
151 | ) -> Option<(crate::StructField, Option<Local>)> { | 151 | ) -> Option<(StructField, Option<Local>)> { |
152 | let (expr_id, local) = match field.expr() { | 152 | let expr = field.expr()?; |
153 | Some(it) => (self.expr_id(db, &it)?, None), | 153 | let expr_id = self.expr_id(db, &expr)?; |
154 | None => { | 154 | let local = if field.name_ref().is_some() { |
155 | let src = InFile { file_id: self.file_id, value: field }; | 155 | None |
156 | let expr_id = self.body_source_map.as_ref()?.field_init_shorthand_expr(src)?; | 156 | } else { |
157 | let local_name = field.name_ref()?.as_name(); | 157 | let local_name = field.field_name()?.as_name(); |
158 | let path = ModPath::from_segments(PathKind::Plain, once(local_name)); | 158 | let path = ModPath::from_segments(PathKind::Plain, once(local_name)); |
159 | let local = match self.resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) { | 159 | match self.resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) { |
160 | Some(ValueNs::LocalBinding(pat_id)) => { | 160 | Some(ValueNs::LocalBinding(pat_id)) => { |
161 | Some(Local { pat_id, parent: self.resolver.body_owner()? }) | 161 | Some(Local { pat_id, parent: self.resolver.body_owner()? }) |
162 | } | 162 | } |
163 | _ => None, | 163 | _ => None, |
164 | }; | ||
165 | (expr_id, local) | ||
166 | } | 164 | } |
167 | }; | 165 | }; |
168 | let struct_field = self.infer.as_ref()?.record_field_resolution(expr_id)?; | 166 | let struct_field = self.infer.as_ref()?.record_field_resolution(expr_id)?; |
@@ -319,8 +317,7 @@ fn scope_for_offset( | |||
319 | if source.file_id != offset.file_id { | 317 | if source.file_id != offset.file_id { |
320 | return None; | 318 | return None; |
321 | } | 319 | } |
322 | let syntax_node_ptr = | 320 | let syntax_node_ptr = source.value.syntax_node_ptr(); |
323 | source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); | ||
324 | Some((syntax_node_ptr, scope)) | 321 | Some((syntax_node_ptr, scope)) |
325 | }) | 322 | }) |
326 | // find containing scope | 323 | // find containing scope |
@@ -399,8 +396,7 @@ fn adjust( | |||
399 | if source.file_id != file_id { | 396 | if source.file_id != file_id { |
400 | return None; | 397 | return None; |
401 | } | 398 | } |
402 | let syntax_node_ptr = | 399 | let syntax_node_ptr = source.value.syntax_node_ptr(); |
403 | source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); | ||
404 | Some((syntax_node_ptr, scope)) | 400 | Some((syntax_node_ptr, scope)) |
405 | }) | 401 | }) |
406 | .map(|(ptr, scope)| (ptr.range(), scope)) | 402 | .map(|(ptr, scope)| (ptr.range(), scope)) |