diff options
author | succcubbus <[email protected]> | 2019-12-13 18:20:02 +0000 |
---|---|---|
committer | succcubbus <[email protected]> | 2019-12-13 18:20:02 +0000 |
commit | 4df741ecb2d00c3d8cdbc37d734ff5514dd5e7b0 (patch) | |
tree | d8a4177f80d4024a8de2622426cfcb3b795c2683 /crates/ra_ide/src/goto_definition.rs | |
parent | ebc95af2b5b91239fc1d8a5fc8344ded6f6ef3e4 (diff) |
fix goto definition when inbetween tokens
fixes both goto_definition and goto_type_definition.
before, when running goto between some non-trivia token and an
identifier, goto would be attempted for the non-trivia token.
but this does not make sense for e.g. L_PAREN or COLONCOLON only for
IDENTs. now only IDENTs will be searched for in goto actions.
Diffstat (limited to 'crates/ra_ide/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 16 |
1 files changed, 14 insertions, 2 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 | " |