diff options
Diffstat (limited to 'crates/ra_ide/src/goto_type_definition.rs')
-rw-r--r-- | crates/ra_ide/src/goto_type_definition.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs index 7eb40d637..d9cf975d4 100644 --- a/crates/ra_ide/src/goto_type_definition.rs +++ b/crates/ra_ide/src/goto_type_definition.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_ide_db::RootDatabase; | 1 | use ra_ide_db::RootDatabase; |
2 | use ra_syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset}; | 2 | use ra_syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; |
3 | 3 | ||
4 | use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo}; | 4 | use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo}; |
5 | 5 | ||
@@ -25,8 +25,9 @@ pub(crate) fn goto_type_definition( | |||
25 | let (ty, node) = sema.ancestors_with_macros(token.parent()).find_map(|node| { | 25 | let (ty, node) = sema.ancestors_with_macros(token.parent()).find_map(|node| { |
26 | let ty = match_ast! { | 26 | let ty = match_ast! { |
27 | match node { | 27 | match node { |
28 | ast::Expr(expr) => sema.type_of_expr(&expr)?, | 28 | ast::Expr(it) => sema.type_of_expr(&it)?, |
29 | ast::Pat(pat) => sema.type_of_pat(&pat)?, | 29 | ast::Pat(it) => sema.type_of_pat(&it)?, |
30 | ast::SelfParam(it) => sema.type_of_self(&it)?, | ||
30 | _ => return None, | 31 | _ => return None, |
31 | } | 32 | } |
32 | }; | 33 | }; |
@@ -44,7 +45,7 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { | |||
44 | return tokens.max_by_key(priority); | 45 | return tokens.max_by_key(priority); |
45 | fn priority(n: &SyntaxToken) -> usize { | 46 | fn priority(n: &SyntaxToken) -> usize { |
46 | match n.kind() { | 47 | match n.kind() { |
47 | IDENT | INT_NUMBER => 2, | 48 | IDENT | INT_NUMBER | T![self] => 2, |
48 | kind if kind.is_trivia() => 0, | 49 | kind if kind.is_trivia() => 0, |
49 | _ => 1, | 50 | _ => 1, |
50 | } | 51 | } |
@@ -140,4 +141,18 @@ mod tests { | |||
140 | "Foo STRUCT_DEF FileId(1) 0..11 7..10", | 141 | "Foo STRUCT_DEF FileId(1) 0..11 7..10", |
141 | ); | 142 | ); |
142 | } | 143 | } |
144 | |||
145 | #[test] | ||
146 | fn goto_def_for_self_param() { | ||
147 | check_goto( | ||
148 | r#" | ||
149 | struct Foo; | ||
150 | impl Foo { | ||
151 | //^^^ | ||
152 | fn f(&self<|>) {} | ||
153 | } | ||
154 | "#, | ||
155 | "Foo STRUCT_DEF FileId(1) 0..11 7..10", | ||
156 | ) | ||
157 | } | ||
143 | } | 158 | } |