aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-06-05 12:36:19 +0100
committerJonas Schievink <[email protected]>2020-06-05 12:36:19 +0100
commit2fb3d87bf77826f213d2876c921308e9f168ca63 (patch)
tree334e8fd8b65b90158df15a1bc265aaf596fcab39 /crates
parent8395396782e343c6fe6bd318c74e8c9884b22323 (diff)
impl Debug for ImportMap
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/import_map.rs42
1 files changed, 23 insertions, 19 deletions
diff --git a/crates/ra_hir_def/src/import_map.rs b/crates/ra_hir_def/src/import_map.rs
index 1c812a19a..70749f380 100644
--- a/crates/ra_hir_def/src/import_map.rs
+++ b/crates/ra_hir_def/src/import_map.rs
@@ -1,6 +1,6 @@
1//! A map of all publicly exported items in a crate. 1//! A map of all publicly exported items in a crate.
2 2
3use std::{collections::hash_map::Entry, sync::Arc}; 3use std::{collections::hash_map::Entry, fmt, sync::Arc};
4 4
5use ra_db::CrateId; 5use ra_db::CrateId;
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
@@ -21,7 +21,7 @@ use crate::{
21/// 21///
22/// Note that all paths are relative to the containing crate's root, so the crate name still needs 22/// Note that all paths are relative to the containing crate's root, so the crate name still needs
23/// to be prepended to the `ModPath` before the path is valid. 23/// to be prepended to the `ModPath` before the path is valid.
24#[derive(Debug, Eq, PartialEq)] 24#[derive(Eq, PartialEq)]
25pub struct ImportMap { 25pub struct ImportMap {
26 map: FxHashMap<ItemInNs, ModPath>, 26 map: FxHashMap<ItemInNs, ModPath>,
27} 27}
@@ -95,6 +95,26 @@ impl ImportMap {
95 } 95 }
96} 96}
97 97
98impl fmt::Debug for ImportMap {
99 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100 let mut importable_paths: Vec<_> = self
101 .map
102 .iter()
103 .map(|(item, modpath)| {
104 let ns = match item {
105 ItemInNs::Types(_) => "t",
106 ItemInNs::Values(_) => "v",
107 ItemInNs::Macros(_) => "m",
108 };
109 format!("- {} ({})", modpath, ns)
110 })
111 .collect();
112
113 importable_paths.sort();
114 f.write_str(&importable_paths.join("\n"))
115 }
116}
117
98#[cfg(test)] 118#[cfg(test)]
99mod tests { 119mod tests {
100 use super::*; 120 use super::*;
@@ -115,23 +135,7 @@ mod tests {
115 135
116 let map = db.import_map(krate); 136 let map = db.import_map(krate);
117 137
118 let mut importable_paths: Vec<_> = map 138 Some(format!("{}:\n{:?}", name, map))
119 .map
120 .iter()
121 .map(|(item, modpath)| {
122 let ns = match item {
123 ItemInNs::Types(_) => "t",
124 ItemInNs::Values(_) => "v",
125 ItemInNs::Macros(_) => "m",
126 };
127 format!("- {} ({})", modpath, ns)
128 })
129 .collect();
130
131 importable_paths.sort();
132 let importable_paths = importable_paths.join("\n");
133
134 Some(format!("{}:\n{}", name, importable_paths))
135 }) 139 })
136 .collect(); 140 .collect();
137 141