diff options
Diffstat (limited to 'crates/ra_ide_api/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 96 |
1 files changed, 94 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index dd5f9f31c..d4e10b69c 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -121,8 +121,12 @@ pub(crate) fn reference_definition( | |||
121 | Some(Resolution::GenericParam(..)) => { | 121 | Some(Resolution::GenericParam(..)) => { |
122 | // TODO: go to the generic param def | 122 | // TODO: go to the generic param def |
123 | } | 123 | } |
124 | Some(Resolution::SelfType(_impl_block)) => { | 124 | Some(Resolution::SelfType(impl_block)) => { |
125 | // TODO: go to the implemented type | 125 | let ty = impl_block.target_ty(db); |
126 | |||
127 | if let hir::Ty::Adt { def_id, .. } = ty { | ||
128 | return Exact(NavigationTarget::from_adt_def(db, def_id)); | ||
129 | } | ||
126 | } | 130 | } |
127 | None => { | 131 | None => { |
128 | // If we failed to resolve then check associated items | 132 | // If we failed to resolve then check associated items |
@@ -337,6 +341,94 @@ mod tests { | |||
337 | "spam NAMED_FIELD_DEF FileId(1) [17; 26) [17; 21)", | 341 | "spam NAMED_FIELD_DEF FileId(1) [17; 26) [17; 21)", |
338 | ); | 342 | ); |
339 | } | 343 | } |
344 | #[test] | ||
345 | fn goto_definition_on_self() { | ||
346 | check_goto( | ||
347 | " | ||
348 | //- /lib.rs | ||
349 | struct Foo; | ||
350 | impl Foo { | ||
351 | pub fn new() -> Self { | ||
352 | Self<|> {} | ||
353 | } | ||
354 | } | ||
355 | ", | ||
356 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | ||
357 | ); | ||
358 | |||
359 | check_goto( | ||
360 | " | ||
361 | //- /lib.rs | ||
362 | struct Foo; | ||
363 | impl Foo { | ||
364 | pub fn new() -> Self<|> { | ||
365 | Self {} | ||
366 | } | ||
367 | } | ||
368 | ", | ||
369 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | ||
370 | ); | ||
371 | |||
372 | check_goto( | ||
373 | " | ||
374 | //- /lib.rs | ||
375 | enum Foo { A } | ||
376 | impl Foo { | ||
377 | pub fn new() -> Self<|> { | ||
378 | Foo::A | ||
379 | } | ||
380 | } | ||
381 | ", | ||
382 | "Foo ENUM_DEF FileId(1) [0; 14) [5; 8)", | ||
383 | ); | ||
384 | |||
385 | check_goto( | ||
386 | " | ||
387 | //- /lib.rs | ||
388 | enum Foo { A } | ||
389 | impl Foo { | ||
390 | pub fn thing(a: &Self<|>) { | ||
391 | } | ||
392 | } | ||
393 | ", | ||
394 | "Foo ENUM_DEF FileId(1) [0; 14) [5; 8)", | ||
395 | ); | ||
396 | } | ||
397 | |||
398 | #[test] | ||
399 | fn goto_definition_on_self_in_trait_impl() { | ||
400 | check_goto( | ||
401 | " | ||
402 | //- /lib.rs | ||
403 | struct Foo; | ||
404 | trait Make { | ||
405 | fn new() -> Self; | ||
406 | } | ||
407 | impl Make for Foo { | ||
408 | fn new() -> Self { | ||
409 | Self<|> {} | ||
410 | } | ||
411 | } | ||
412 | ", | ||
413 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | ||
414 | ); | ||
415 | |||
416 | check_goto( | ||
417 | " | ||
418 | //- /lib.rs | ||
419 | struct Foo; | ||
420 | trait Make { | ||
421 | fn new() -> Self; | ||
422 | } | ||
423 | impl Make for Foo { | ||
424 | fn new() -> Self<|> { | ||
425 | Self{} | ||
426 | } | ||
427 | } | ||
428 | ", | ||
429 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | ||
430 | ); | ||
431 | } | ||
340 | 432 | ||
341 | #[test] | 433 | #[test] |
342 | fn goto_definition_works_when_used_on_definition_name_itself() { | 434 | fn goto_definition_works_when_used_on_definition_name_itself() { |