diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-15 12:13:01 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-15 12:13:01 +0000 |
commit | b4446cdd06caa32e1e9e255312a15feb770d4935 (patch) | |
tree | 5a9d98a215a2adf82dbd2d3c9b74602e0c7debf8 | |
parent | 5138baf2ac742de601f29d22fc64e386da56c4c2 (diff) | |
parent | af2366acdf1321702e54e01c88052ed5a674716c (diff) |
Merge #8025
8025: Goto definition works for `S { a: }` case r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/hir/src/source_analyzer.rs | 25 | ||||
-rw-r--r-- | crates/ide/src/goto_definition.rs | 11 |
2 files changed, 33 insertions, 3 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index d546512cb..055a3e5d0 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs | |||
@@ -24,7 +24,7 @@ use hir_ty::{ | |||
24 | }; | 24 | }; |
25 | use syntax::{ | 25 | use syntax::{ |
26 | ast::{self, AstNode}, | 26 | ast::{self, AstNode}, |
27 | SyntaxNode, TextRange, TextSize, | 27 | AstPtr, SyntaxNode, TextRange, TextSize, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | use crate::{ | 30 | use crate::{ |
@@ -161,8 +161,27 @@ impl SourceAnalyzer { | |||
161 | db: &dyn HirDatabase, | 161 | db: &dyn HirDatabase, |
162 | field: &ast::RecordExprField, | 162 | field: &ast::RecordExprField, |
163 | ) -> Option<(Field, Option<Local>)> { | 163 | ) -> Option<(Field, Option<Local>)> { |
164 | let expr = field.expr()?; | 164 | let expr_id = { |
165 | let expr_id = self.expr_id(db, &expr)?; | 165 | let record_lit = field.parent_record_lit(); |
166 | let record_lit_expr = self.expr_id(db, &ast::Expr::from(record_lit))?; | ||
167 | let body = self.body.as_ref()?; | ||
168 | let body_source_map = self.body_source_map.as_ref()?; | ||
169 | match &body[record_lit_expr] { | ||
170 | hir_def::expr::Expr::RecordLit { fields, .. } => { | ||
171 | let field_ptr = InFile::new(self.file_id, AstPtr::new(field)); | ||
172 | fields.iter().enumerate().find_map(|(i, f)| { | ||
173 | let ptr = body_source_map.field_syntax(record_lit_expr, i); | ||
174 | if ptr == field_ptr { | ||
175 | Some(f.expr) | ||
176 | } else { | ||
177 | None | ||
178 | } | ||
179 | })? | ||
180 | } | ||
181 | _ => return None, | ||
182 | } | ||
183 | }; | ||
184 | |||
166 | let local = if field.name_ref().is_some() { | 185 | let local = if field.name_ref().is_some() { |
167 | None | 186 | None |
168 | } else { | 187 | } else { |
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index abed1969e..e8f31e4b1 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs | |||
@@ -1161,4 +1161,15 @@ struct S; | |||
1161 | "#, | 1161 | "#, |
1162 | ) | 1162 | ) |
1163 | } | 1163 | } |
1164 | |||
1165 | #[test] | ||
1166 | fn goto_incomplete_field() { | ||
1167 | check( | ||
1168 | r#" | ||
1169 | struct A { a: u32 } | ||
1170 | //^ | ||
1171 | fn foo() { A { a$0: }; } | ||
1172 | "#, | ||
1173 | ) | ||
1174 | } | ||
1164 | } | 1175 | } |