@@ -5,15 +5,14 @@ use crate::{
5
5
navigation_target:: { self , ToNav } ,
6
6
FilePosition , NavigationTarget , RangeInfo , TryToNav , UpmappingResult ,
7
7
} ;
8
- use hir:: { Adt , AsAssocItem , AssocItem , FileRange , InFile , MacroFileIdExt , ModuleDef , Semantics } ;
8
+ use hir:: { AsAssocItem , AssocItem , FileRange , InFile , MacroFileIdExt , ModuleDef , Semantics } ;
9
9
use ide_db:: {
10
10
base_db:: { AnchoredPath , FileLoader , SourceDatabase } ,
11
11
defs:: { Definition , IdentClass } ,
12
12
helpers:: pick_best_token,
13
13
RootDatabase , SymbolKind ,
14
14
} ;
15
15
use itertools:: Itertools ;
16
- use ide_db:: famous_defs:: FamousDefs ;
17
16
use span:: { Edition , FileId } ;
18
17
use syntax:: {
19
18
ast:: { self , HasLoopBody } ,
@@ -41,22 +40,6 @@ pub(crate) fn goto_definition(
41
40
) -> Option < RangeInfo < Vec < NavigationTarget > > > {
42
41
let sema = & Semantics :: new ( db) ;
43
42
let file = sema. parse_guess_edition ( file_id) . syntax ( ) . clone ( ) ;
44
-
45
- if let syntax:: TokenAtOffset :: Single ( tok) = file. token_at_offset ( offset) {
46
- if let Some ( module) = sema. file_to_module_def ( file_id) {
47
- let famous_defs = FamousDefs ( sema, module. krate ( ) ) ;
48
- let maybe_famous_struct = match tok. kind ( ) {
49
- T ! [ ..] => famous_defs. core_ops_Range ( ) ,
50
- T ! [ ..=] => famous_defs. core_ops_RangeInclusive ( ) ,
51
- _ => None
52
- } ;
53
- if let Some ( fstruct) = maybe_famous_struct {
54
- let target = def_to_nav ( db, Definition :: Adt ( Adt :: Struct ( fstruct) ) ) ;
55
- return Some ( RangeInfo :: new ( tok. text_range ( ) , target) ) ;
56
- }
57
- }
58
- }
59
-
60
43
let edition =
61
44
sema. attach_first_edition ( file_id) . map ( |it| it. edition ( ) ) . unwrap_or ( Edition :: CURRENT ) ;
62
45
let original_token = pick_best_token ( file. token_at_offset ( offset) , |kind| match kind {
@@ -434,10 +417,10 @@ fn expr_to_nav(
434
417
435
418
#[ cfg( test) ]
436
419
mod tests {
420
+ use crate :: fixture;
437
421
use ide_db:: FileRange ;
438
422
use itertools:: Itertools ;
439
423
use syntax:: SmolStr ;
440
- use crate :: fixture;
441
424
442
425
#[ track_caller]
443
426
fn check ( ra_fixture : & str ) {
@@ -466,9 +449,25 @@ mod tests {
466
449
assert ! ( navs. is_empty( ) , "didn't expect this to resolve anywhere: {navs:?}" )
467
450
}
468
451
452
+ #[ test]
453
+ fn goto_def_range_inclusive_0 ( ) {
454
+ let ra_fixture = r#"
455
+ //- minicore: range
456
+ fn f(a: usize, b: usize) {
457
+ for _ in a.$0.=b {
458
+
459
+ }
460
+ }
461
+ "# ;
462
+ let ( analysis, position, _) = fixture:: annotations ( ra_fixture) ;
463
+ let mut navs =
464
+ analysis. goto_definition ( position) . unwrap ( ) . expect ( "no definition found" ) . info ;
465
+ let Some ( target) = navs. pop ( ) else { panic ! ( "no target found" ) } ;
466
+ assert_eq ! ( target. name, SmolStr :: new_inline( "RangeInclusive" ) ) ;
467
+ }
469
468
470
469
#[ test]
471
- fn goto_def_range_inclusive ( ) {
470
+ fn goto_def_range_inclusive_1 ( ) {
472
471
let ra_fixture = r#"
473
472
//- minicore: range
474
473
fn f(a: usize, b: usize) {
@@ -478,13 +477,14 @@ fn f(a: usize, b: usize) {
478
477
}
479
478
"# ;
480
479
let ( analysis, position, _) = fixture:: annotations ( ra_fixture) ;
481
- let mut navs = analysis. goto_definition ( position) . unwrap ( ) . expect ( "no definition found" ) . info ;
480
+ let mut navs =
481
+ analysis. goto_definition ( position) . unwrap ( ) . expect ( "no definition found" ) . info ;
482
482
let Some ( target) = navs. pop ( ) else { panic ! ( "no target found" ) } ;
483
483
assert_eq ! ( target. name, SmolStr :: new_inline( "RangeInclusive" ) ) ;
484
484
}
485
485
486
486
#[ test]
487
- fn goto_def_range_half_open ( ) {
487
+ fn goto_def_range ( ) {
488
488
let ra_fixture = r#"
489
489
//- minicore: range
490
490
fn f(a: usize, b: usize) {
@@ -494,7 +494,8 @@ fn f(a: usize, b: usize) {
494
494
}
495
495
"# ;
496
496
let ( analysis, position, _) = fixture:: annotations ( ra_fixture) ;
497
- let mut navs = analysis. goto_definition ( position) . unwrap ( ) . expect ( "no definition found" ) . info ;
497
+ let mut navs =
498
+ analysis. goto_definition ( position) . unwrap ( ) . expect ( "no definition found" ) . info ;
498
499
let Some ( target) = navs. pop ( ) else { panic ! ( "no target found" ) } ;
499
500
assert_eq ! ( target. name, SmolStr :: new_inline( "Range" ) ) ;
500
501
}
0 commit comments