aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/import_map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/import_map.rs')
-rw-r--r--crates/ra_hir_def/src/import_map.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/import_map.rs b/crates/ra_hir_def/src/import_map.rs
index 299fe82a8..00a5211b1 100644
--- a/crates/ra_hir_def/src/import_map.rs
+++ b/crates/ra_hir_def/src/import_map.rs
@@ -327,7 +327,7 @@ pub fn search_dependencies<'a>(
327#[cfg(test)] 327#[cfg(test)]
328mod tests { 328mod tests {
329 use super::*; 329 use super::*;
330 use crate::test_db::TestDB; 330 use crate::{test_db::TestDB, AssocContainerId, Lookup};
331 use insta::assert_snapshot; 331 use insta::assert_snapshot;
332 use itertools::Itertools; 332 use itertools::Itertools;
333 use ra_db::fixture::WithFixture; 333 use ra_db::fixture::WithFixture;
@@ -370,6 +370,7 @@ mod tests {
370 ItemInNs::Values(_) => "v", 370 ItemInNs::Values(_) => "v",
371 ItemInNs::Macros(_) => "m", 371 ItemInNs::Macros(_) => "m",
372 }; 372 };
373 let item = assoc_to_trait(&db, item);
373 item.krate(db.upcast()).map(|krate| { 374 item.krate(db.upcast()).map(|krate| {
374 let map = db.import_map(krate); 375 let map = db.import_map(krate);
375 let path = map.path_of(item).unwrap(); 376 let path = map.path_of(item).unwrap();
@@ -384,6 +385,29 @@ mod tests {
384 .join("\n") 385 .join("\n")
385 } 386 }
386 387
388 fn assoc_to_trait(db: &dyn DefDatabase, item: ItemInNs) -> ItemInNs {
389 let assoc: AssocItemId = match item {
390 ItemInNs::Types(it) | ItemInNs::Values(it) => match it {
391 ModuleDefId::TypeAliasId(it) => it.into(),
392 ModuleDefId::FunctionId(it) => it.into(),
393 ModuleDefId::ConstId(it) => it.into(),
394 _ => return item,
395 },
396 _ => return item,
397 };
398
399 let container = match assoc {
400 AssocItemId::FunctionId(it) => it.lookup(db).container,
401 AssocItemId::ConstId(it) => it.lookup(db).container,
402 AssocItemId::TypeAliasId(it) => it.lookup(db).container,
403 };
404
405 match container {
406 AssocContainerId::TraitId(it) => ItemInNs::Types(it.into()),
407 _ => item,
408 }
409 }
410
387 #[test] 411 #[test]
388 fn smoke() { 412 fn smoke() {
389 let map = import_map( 413 let map = import_map(
@@ -641,6 +665,7 @@ mod tests {
641 dep::Fmt (m) 665 dep::Fmt (m)
642 dep::fmt::Display (t) 666 dep::fmt::Display (t)
643 dep::format (v) 667 dep::format (v)
668 dep::fmt::Display (t)
644 "###); 669 "###);
645 670
646 let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt").anchor_end()); 671 let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt").anchor_end());
@@ -649,6 +674,7 @@ mod tests {
649 dep::Fmt (t) 674 dep::Fmt (t)
650 dep::Fmt (v) 675 dep::Fmt (v)
651 dep::Fmt (m) 676 dep::Fmt (m)
677 dep::fmt::Display (t)
652 "###); 678 "###);
653 } 679 }
654 680