diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-25 11:25:00 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-25 11:25:00 +0000 |
| commit | b7414fa14a85f4acd37b5bdfdc2a4ab97a072bd2 (patch) | |
| tree | 06a55af22e32a059cd34e8558a79b69960faaf9f | |
| parent | b250d5e6bfab92c1fe21635536c89e556b8f72d4 (diff) | |
| parent | ff585e4730a867e7bb68c65ff45867a501841ae4 (diff) | |
| download | rust-b7414fa14a85f4acd37b5bdfdc2a4ab97a072bd2.tar.gz rust-b7414fa14a85f4acd37b5bdfdc2a4ab97a072bd2.zip | |
Merge #8986
8986: Add go to type definition for struct fields within struct r=matklad a=lf-
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.
Co-authored-by: Jade <software@lfcode.ca>
| -rw-r--r-- | crates/ide/src/goto_type_definition.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs index f3284bb96a7..004d9cb688e 100644 --- a/crates/ide/src/goto_type_definition.rs +++ b/crates/ide/src/goto_type_definition.rs @@ -1,3 +1,4 @@ +use ide_db::base_db::Upcast; use ide_db::RootDatabase; use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; @@ -31,6 +32,7 @@ pub(crate) fn goto_type_definition( ast::Pat(it) => sema.type_of_pat(&it)?, ast::SelfParam(it) => sema.type_of_self(&it)?, ast::Type(it) => sema.resolve_type(&it)?, + ast::RecordField(it) => sema.to_def(&it).map(|d| d.ty(db.upcast()))?, _ => return None, } }; @@ -161,4 +163,34 @@ impl Foo$0 {} "#, ) } + + #[test] + fn goto_def_for_struct_field() { + check( + r#" +struct Bar; + //^^^ + +struct Foo { + bar$0: Bar, +} +"#, + ); + } + + #[test] + fn goto_def_for_enum_struct_field() { + check( + r#" +struct Bar; + //^^^ + +enum Foo { + Bar { + bar$0: Bar + }, +} +"#, + ); + } } |
