aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/goto_definition.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/goto_definition.rs')
-rw-r--r--crates/ra_ide/src/goto_definition.rs62
1 files changed, 47 insertions, 15 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index 1dfca819d..a6c86e99c 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -1,5 +1,3 @@
1//! FIXME: write short doc here
2
3use hir::Semantics; 1use hir::Semantics;
4use ra_ide_db::{ 2use ra_ide_db::{
5 defs::{classify_name, classify_name_ref}, 3 defs::{classify_name, classify_name_ref},
@@ -17,6 +15,15 @@ use crate::{
17 FilePosition, NavigationTarget, RangeInfo, 15 FilePosition, NavigationTarget, RangeInfo,
18}; 16};
19 17
18// Feature: Go to Definition
19//
20// Navigates to the definition of an identifier.
21//
22// |===
23// | Editor | Shortcut
24//
25// | VS Code | kbd:[F12]
26// |===
20pub(crate) fn goto_definition( 27pub(crate) fn goto_definition(
21 db: &RootDatabase, 28 db: &RootDatabase,
22 position: FilePosition, 29 position: FilePosition,
@@ -93,7 +100,7 @@ pub(crate) fn reference_definition(
93 100
94#[cfg(test)] 101#[cfg(test)]
95mod tests { 102mod tests {
96 use test_utils::{assert_eq_text, covers}; 103 use test_utils::assert_eq_text;
97 104
98 use crate::mock_analysis::analysis_and_position; 105 use crate::mock_analysis::analysis_and_position;
99 106
@@ -208,7 +215,6 @@ mod tests {
208 215
209 #[test] 216 #[test]
210 fn goto_def_for_macros() { 217 fn goto_def_for_macros() {
211 covers!(ra_ide_db::goto_def_for_macros);
212 check_goto( 218 check_goto(
213 " 219 "
214 //- /lib.rs 220 //- /lib.rs
@@ -225,7 +231,6 @@ mod tests {
225 231
226 #[test] 232 #[test]
227 fn goto_def_for_macros_from_other_crates() { 233 fn goto_def_for_macros_from_other_crates() {
228 covers!(ra_ide_db::goto_def_for_macros);
229 check_goto( 234 check_goto(
230 " 235 "
231 //- /lib.rs 236 //- /lib.rs
@@ -244,6 +249,38 @@ mod tests {
244 } 249 }
245 250
246 #[test] 251 #[test]
252 fn goto_def_for_use_alias() {
253 check_goto(
254 "
255 //- /lib.rs
256 use foo as bar<|>;
257
258
259 //- /foo/lib.rs
260 #[macro_export]
261 macro_rules! foo { () => { () } }",
262 "SOURCE_FILE FileId(2) 0..50",
263 "#[macro_export]\nmacro_rules! foo { () => { () } }\n",
264 );
265 }
266
267 #[test]
268 fn goto_def_for_use_alias_foo_macro() {
269 check_goto(
270 "
271 //- /lib.rs
272 use foo::foo as bar<|>;
273
274 //- /foo/lib.rs
275 #[macro_export]
276 macro_rules! foo { () => { () } }
277 ",
278 "foo MACRO_CALL FileId(2) 0..49 29..32",
279 "#[macro_export]\nmacro_rules! foo { () => { () } }|foo",
280 );
281 }
282
283 #[test]
247 fn goto_def_for_macros_in_use_tree() { 284 fn goto_def_for_macros_in_use_tree() {
248 check_goto( 285 check_goto(
249 " 286 "
@@ -337,7 +374,6 @@ mod tests {
337 374
338 #[test] 375 #[test]
339 fn goto_def_for_methods() { 376 fn goto_def_for_methods() {
340 covers!(ra_ide_db::goto_def_for_methods);
341 check_goto( 377 check_goto(
342 " 378 "
343 //- /lib.rs 379 //- /lib.rs
@@ -357,7 +393,6 @@ mod tests {
357 393
358 #[test] 394 #[test]
359 fn goto_def_for_fields() { 395 fn goto_def_for_fields() {
360 covers!(ra_ide_db::goto_def_for_fields);
361 check_goto( 396 check_goto(
362 r" 397 r"
363 //- /lib.rs 398 //- /lib.rs
@@ -376,7 +411,6 @@ mod tests {
376 411
377 #[test] 412 #[test]
378 fn goto_def_for_record_fields() { 413 fn goto_def_for_record_fields() {
379 covers!(ra_ide_db::goto_def_for_record_fields);
380 check_goto( 414 check_goto(
381 r" 415 r"
382 //- /lib.rs 416 //- /lib.rs
@@ -397,7 +431,6 @@ mod tests {
397 431
398 #[test] 432 #[test]
399 fn goto_def_for_record_pat_fields() { 433 fn goto_def_for_record_pat_fields() {
400 covers!(ra_ide_db::goto_def_for_record_field_pats);
401 check_goto( 434 check_goto(
402 r" 435 r"
403 //- /lib.rs 436 //- /lib.rs
@@ -754,14 +787,14 @@ mod tests {
754 #[test] 787 #[test]
755 fn goto_for_type_param() { 788 fn goto_for_type_param() {
756 check_goto( 789 check_goto(
757 " 790 r#"
758 //- /lib.rs 791 //- /lib.rs
759 struct Foo<T> { 792 struct Foo<T: Clone> {
760 t: <|>T, 793 t: <|>T,
761 } 794 }
762 ", 795 "#,
763 "T TYPE_PARAM FileId(1) 11..12", 796 "T TYPE_PARAM FileId(1) 11..19 11..12",
764 "T", 797 "T: Clone|T",
765 ); 798 );
766 } 799 }
767 800
@@ -840,7 +873,6 @@ mod tests {
840 873
841 #[test] 874 #[test]
842 fn goto_def_for_field_init_shorthand() { 875 fn goto_def_for_field_init_shorthand() {
843 covers!(ra_ide_db::goto_def_for_field_init_shorthand);
844 check_goto( 876 check_goto(
845 " 877 "
846 //- /lib.rs 878 //- /lib.rs