File tree 2 files changed +108
-1
lines changed
src/tools/rust-analyzer/crates/ide/src
2 files changed +108
-1
lines changed Original file line number Diff line number Diff line change @@ -557,12 +557,28 @@ fn goto_type_action_for_def(
557
557
. into_iter ( )
558
558
. filter ( |& it| Some ( it. into ( ) ) != sized_trait)
559
559
. for_each ( |it| push_new_def ( it. into ( ) ) ) ;
560
+ } else if let Definition :: Function ( function) = def {
561
+ walk_and_push_ty ( db, & function. ret_type ( db) , & mut push_new_def) ;
562
+
563
+ let krate = function. module ( db) . krate ( ) ;
564
+ let sized_trait =
565
+ db. lang_item ( krate. into ( ) , LangItem :: Sized ) . and_then ( |lang_item| lang_item. as_trait ( ) ) ;
566
+ for param in function. params_without_self ( db) {
567
+ if let Some ( type_param) = param. ty ( ) . as_type_param ( db) {
568
+ type_param
569
+ . trait_bounds ( db)
570
+ . into_iter ( )
571
+ . filter ( |& it| Some ( it. into ( ) ) != sized_trait)
572
+ . for_each ( |it| push_new_def ( it. into ( ) ) ) ;
573
+ } else {
574
+ walk_and_push_ty ( db, param. ty ( ) , & mut push_new_def) ;
575
+ }
576
+ }
560
577
} else {
561
578
let ty = match def {
562
579
Definition :: Local ( it) => it. ty ( db) ,
563
580
Definition :: GenericParam ( hir:: GenericParam :: ConstParam ( it) ) => it. ty ( db) ,
564
581
Definition :: Field ( field) => field. ty ( db) ,
565
- Definition :: Function ( function) => function. ret_type ( db) ,
566
582
_ => return HoverAction :: goto_type_from_targets ( db, targets, edition) ,
567
583
} ;
568
584
Original file line number Diff line number Diff line change @@ -2368,6 +2368,97 @@ fn test() {
2368
2368
) ;
2369
2369
}
2370
2370
2371
+ #[ test]
2372
+ fn test_hover_show_type_def_for_func_param ( ) {
2373
+ check_actions (
2374
+ r#"
2375
+ struct Bar;
2376
+ fn f(b: Bar) {
2377
+
2378
+ }
2379
+
2380
+ fn test() {
2381
+ let b = Bar;
2382
+ f$0(b);
2383
+ }
2384
+ "# ,
2385
+ expect ! [ [ r#"
2386
+ [
2387
+ Reference(
2388
+ FilePositionWrapper {
2389
+ file_id: FileId(
2390
+ 0,
2391
+ ),
2392
+ offset: 15,
2393
+ },
2394
+ ),
2395
+ GoToType(
2396
+ [
2397
+ HoverGotoTypeData {
2398
+ mod_path: "ra_test_fixture::Bar",
2399
+ nav: NavigationTarget {
2400
+ file_id: FileId(
2401
+ 0,
2402
+ ),
2403
+ full_range: 0..11,
2404
+ focus_range: 7..10,
2405
+ name: "Bar",
2406
+ kind: Struct,
2407
+ description: "struct Bar",
2408
+ },
2409
+ },
2410
+ ],
2411
+ ),
2412
+ ]
2413
+ "# ] ] ,
2414
+ ) ;
2415
+ }
2416
+
2417
+ #[ test]
2418
+ fn test_hover_show_type_def_for_trait_bound ( ) {
2419
+ check_actions (
2420
+ r#"
2421
+ trait Bar {}
2422
+ fn f<T: Bar>(b: T) {
2423
+
2424
+ }
2425
+
2426
+ fn test() {
2427
+ f$0();
2428
+ }
2429
+ "# ,
2430
+ expect ! [ [ r#"
2431
+ [
2432
+ Reference(
2433
+ FilePositionWrapper {
2434
+ file_id: FileId(
2435
+ 0,
2436
+ ),
2437
+ offset: 16,
2438
+ },
2439
+ ),
2440
+ GoToType(
2441
+ [
2442
+ HoverGotoTypeData {
2443
+ mod_path: "ra_test_fixture::Bar",
2444
+ nav: NavigationTarget {
2445
+ file_id: FileId(
2446
+ 0,
2447
+ ),
2448
+ full_range: 0..12,
2449
+ focus_range: 6..9,
2450
+ name: "Bar",
2451
+ kind: Trait,
2452
+ description: "trait Bar",
2453
+ },
2454
+ },
2455
+ ],
2456
+ ),
2457
+ ]
2458
+ "# ] ] ,
2459
+ ) ;
2460
+ }
2461
+
2371
2462
#[ test]
2372
2463
fn test_hover_non_ascii_space_doc ( ) {
2373
2464
check (
You can’t perform that action at this time.
0 commit comments