Skip to content

Commit ff585e4

Browse files
committed
Add go to type definition for struct fields within struct
Example: ```rust struct A; struct B { a/*<- cursor*/: A, } ``` Go to type definition used to not work on this position. It now goes to `A` as expected.
1 parent 8b049ec commit ff585e4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/ide/src/goto_type_definition.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use ide_db::base_db::Upcast;
12
use ide_db::RootDatabase;
23
use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
34

@@ -31,6 +32,7 @@ pub(crate) fn goto_type_definition(
3132
ast::Pat(it) => sema.type_of_pat(&it)?,
3233
ast::SelfParam(it) => sema.type_of_self(&it)?,
3334
ast::Type(it) => sema.resolve_type(&it)?,
35+
ast::RecordField(it) => sema.to_def(&it).map(|d| d.ty(db.upcast()))?,
3436
_ => return None,
3537
}
3638
};
@@ -161,4 +163,34 @@ impl Foo$0 {}
161163
"#,
162164
)
163165
}
166+
167+
#[test]
168+
fn goto_def_for_struct_field() {
169+
check(
170+
r#"
171+
struct Bar;
172+
//^^^
173+
174+
struct Foo {
175+
bar$0: Bar,
176+
}
177+
"#,
178+
);
179+
}
180+
181+
#[test]
182+
fn goto_def_for_enum_struct_field() {
183+
check(
184+
r#"
185+
struct Bar;
186+
//^^^
187+
188+
enum Foo {
189+
Bar {
190+
bar$0: Bar
191+
},
192+
}
193+
"#,
194+
);
195+
}
164196
}

0 commit comments

Comments
 (0)