aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/import_map.rs46
1 files changed, 31 insertions, 15 deletions
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index fcbb3ac14..fdc681d6c 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -432,7 +432,7 @@ mod tests {
432 use base_db::{fixture::WithFixture, SourceDatabase, Upcast}; 432 use base_db::{fixture::WithFixture, SourceDatabase, Upcast};
433 use expect_test::{expect, Expect}; 433 use expect_test::{expect, Expect};
434 434
435 use crate::{test_db::TestDB, AssocContainerId, Lookup}; 435 use crate::{data::FunctionData, test_db::TestDB, AssocContainerId, Lookup};
436 436
437 use super::*; 437 use super::*;
438 438
@@ -451,14 +451,31 @@ mod tests {
451 .into_iter() 451 .into_iter()
452 .filter_map(|item| { 452 .filter_map(|item| {
453 let mark = match item { 453 let mark = match item {
454 ItemInNs::Types(ModuleDefId::FunctionId(_))
455 | ItemInNs::Values(ModuleDefId::FunctionId(_)) => "f",
454 ItemInNs::Types(_) => "t", 456 ItemInNs::Types(_) => "t",
455 ItemInNs::Values(_) => "v", 457 ItemInNs::Values(_) => "v",
456 ItemInNs::Macros(_) => "m", 458 ItemInNs::Macros(_) => "m",
457 }; 459 };
458 let item = assoc_to_trait(&db, item);
459 item.krate(db.upcast()).map(|krate| { 460 item.krate(db.upcast()).map(|krate| {
460 let map = db.import_map(krate); 461 let map = db.import_map(krate);
461 let path = map.path_of(item).unwrap(); 462
463 let path = match assoc_to_trait(&db, item) {
464 Some(trait_) => {
465 let mut full_path = map.path_of(trait_).unwrap().to_string();
466 if let ItemInNs::Types(ModuleDefId::FunctionId(function_id))
467 | ItemInNs::Values(ModuleDefId::FunctionId(function_id)) = item
468 {
469 full_path += &format!(
470 "::{}",
471 FunctionData::fn_data_query(&db, function_id).name
472 );
473 }
474 full_path
475 }
476 None => map.path_of(item).unwrap().to_string(),
477 };
478
462 format!( 479 format!(
463 "{}::{} ({})\n", 480 "{}::{} ({})\n",
464 crate_graph[krate].display_name.as_ref().unwrap(), 481 crate_graph[krate].display_name.as_ref().unwrap(),
@@ -471,15 +488,15 @@ mod tests {
471 expect.assert_eq(&actual) 488 expect.assert_eq(&actual)
472 } 489 }
473 490
474 fn assoc_to_trait(db: &dyn DefDatabase, item: ItemInNs) -> ItemInNs { 491 fn assoc_to_trait(db: &dyn DefDatabase, item: ItemInNs) -> Option<ItemInNs> {
475 let assoc: AssocItemId = match item { 492 let assoc: AssocItemId = match item {
476 ItemInNs::Types(it) | ItemInNs::Values(it) => match it { 493 ItemInNs::Types(it) | ItemInNs::Values(it) => match it {
477 ModuleDefId::TypeAliasId(it) => it.into(), 494 ModuleDefId::TypeAliasId(it) => it.into(),
478 ModuleDefId::FunctionId(it) => it.into(), 495 ModuleDefId::FunctionId(it) => it.into(),
479 ModuleDefId::ConstId(it) => it.into(), 496 ModuleDefId::ConstId(it) => it.into(),
480 _ => return item, 497 _ => return None,
481 }, 498 },
482 _ => return item, 499 _ => return None,
483 }; 500 };
484 501
485 let container = match assoc { 502 let container = match assoc {
@@ -489,8 +506,8 @@ mod tests {
489 }; 506 };
490 507
491 match container { 508 match container {
492 AssocContainerId::TraitId(it) => ItemInNs::Types(it.into()), 509 AssocContainerId::TraitId(it) => Some(ItemInNs::Types(it.into())),
493 _ => item, 510 _ => None,
494 } 511 }
495 } 512 }
496 513
@@ -764,8 +781,8 @@ mod tests {
764 dep::Fmt (v) 781 dep::Fmt (v)
765 dep::Fmt (m) 782 dep::Fmt (m)
766 dep::fmt::Display (t) 783 dep::fmt::Display (t)
767 dep::format (v) 784 dep::format (f)
768 dep::fmt::Display (t) 785 dep::fmt::Display::fmt (f)
769 "#]], 786 "#]],
770 ); 787 );
771 788
@@ -778,7 +795,7 @@ mod tests {
778 dep::Fmt (t) 795 dep::Fmt (t)
779 dep::Fmt (v) 796 dep::Fmt (v)
780 dep::Fmt (m) 797 dep::Fmt (m)
781 dep::fmt::Display (t) 798 dep::fmt::Display::fmt (f)
782 "#]], 799 "#]],
783 ); 800 );
784 801
@@ -792,7 +809,7 @@ mod tests {
792 dep::Fmt (v) 809 dep::Fmt (v)
793 dep::Fmt (m) 810 dep::Fmt (m)
794 dep::fmt::Display (t) 811 dep::fmt::Display (t)
795 dep::fmt::Display (t) 812 dep::fmt::Display::fmt (f)
796 "#]], 813 "#]],
797 ); 814 );
798 } 815 }
@@ -833,11 +850,10 @@ mod tests {
833 dep::Fmt (v) 850 dep::Fmt (v)
834 dep::Fmt (m) 851 dep::Fmt (m)
835 dep::fmt::Display (t) 852 dep::fmt::Display (t)
836 dep::fmt::Display (t) 853 dep::fmt::Display::fmt (f)
837 "#]], 854 "#]],
838 ); 855 );
839 856
840 // TODO kb where does this duplicate `dep::fmt::Display (t)` come from?
841 check_search( 857 check_search(
842 ra_fixture, 858 ra_fixture,
843 "main", 859 "main",
@@ -847,7 +863,7 @@ mod tests {
847 dep::Fmt (t) 863 dep::Fmt (t)
848 dep::Fmt (v) 864 dep::Fmt (v)
849 dep::Fmt (m) 865 dep::Fmt (m)
850 dep::fmt::Display (t) 866 dep::fmt::Display::fmt (f)
851 "#]], 867 "#]],
852 ); 868 );
853 } 869 }