diff options
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_type_definition.rs | 16 |
2 files changed, 28 insertions, 4 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index cfe62037f..96a73675f 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use hir::{db::AstDatabase, InFile}; | 3 | use hir::{db::AstDatabase, InFile}; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | ast::{self, DocCommentsOwner}, | 5 | ast::{self, DocCommentsOwner}, |
6 | match_ast, AstNode, SyntaxNode, | 6 | match_ast, AstNode, SyntaxKind, SyntaxNode, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
@@ -20,7 +20,7 @@ pub(crate) fn goto_definition( | |||
20 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 20 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
21 | let file = db.parse_or_expand(position.file_id.into())?; | 21 | let file = db.parse_or_expand(position.file_id.into())?; |
22 | let original_token = | 22 | let original_token = |
23 | file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; | 23 | file.token_at_offset(position.offset).find(|it| it.kind() == SyntaxKind::IDENT)?; |
24 | let token = descend_into_macros(db, position.file_id, original_token.clone()); | 24 | let token = descend_into_macros(db, position.file_id, original_token.clone()); |
25 | 25 | ||
26 | let nav_targets = match_ast! { | 26 | let nav_targets = match_ast! { |
@@ -235,6 +235,18 @@ mod tests { | |||
235 | } | 235 | } |
236 | 236 | ||
237 | #[test] | 237 | #[test] |
238 | fn goto_definition_works_at_start_of_item() { | ||
239 | check_goto( | ||
240 | " | ||
241 | //- /lib.rs | ||
242 | struct Foo; | ||
243 | enum E { X(<|>Foo) } | ||
244 | ", | ||
245 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | ||
246 | ); | ||
247 | } | ||
248 | |||
249 | #[test] | ||
238 | fn goto_definition_resolves_correct_name() { | 250 | fn goto_definition_resolves_correct_name() { |
239 | check_goto( | 251 | check_goto( |
240 | " | 252 | " |
diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs index 992a08809..cc1b90925 100644 --- a/crates/ra_ide/src/goto_type_definition.rs +++ b/crates/ra_ide/src/goto_type_definition.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::db::AstDatabase; | 3 | use hir::db::AstDatabase; |
4 | use ra_syntax::{ast, AstNode}; | 4 | use ra_syntax::{ast, AstNode, SyntaxKind}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | db::RootDatabase, display::ToNav, expand::descend_into_macros, FilePosition, NavigationTarget, | 7 | db::RootDatabase, display::ToNav, expand::descend_into_macros, FilePosition, NavigationTarget, |
@@ -13,7 +13,7 @@ pub(crate) fn goto_type_definition( | |||
13 | position: FilePosition, | 13 | position: FilePosition, |
14 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 14 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
15 | let file = db.parse_or_expand(position.file_id.into())?; | 15 | let file = db.parse_or_expand(position.file_id.into())?; |
16 | let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; | 16 | let token = file.token_at_offset(position.offset).find(|it| it.kind() == SyntaxKind::IDENT)?; |
17 | let token = descend_into_macros(db, position.file_id, token); | 17 | let token = descend_into_macros(db, position.file_id, token); |
18 | 18 | ||
19 | let node = token.value.ancestors().find_map(|token| { | 19 | let node = token.value.ancestors().find_map(|token| { |
@@ -102,4 +102,16 @@ mod tests { | |||
102 | "Foo STRUCT_DEF FileId(1) [52; 65) [59; 62)", | 102 | "Foo STRUCT_DEF FileId(1) [52; 65) [59; 62)", |
103 | ); | 103 | ); |
104 | } | 104 | } |
105 | |||
106 | #[test] | ||
107 | fn goto_type_definition_works_param() { | ||
108 | check_goto( | ||
109 | " | ||
110 | //- /lib.rs | ||
111 | struct Foo; | ||
112 | fn foo(<|>f: Foo) {} | ||
113 | ", | ||
114 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | ||
115 | ); | ||
116 | } | ||
105 | } | 117 | } |