From e44c7ce2004913d3e928bc03df64647c6059ae0e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Oct 2019 14:27:37 +0300 Subject: remove last traces of source roots from hir --- crates/ra_hir/src/debug.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/debug.rs') diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs index 87f3180c3..48b69000b 100644 --- a/crates/ra_hir/src/debug.rs +++ b/crates/ra_hir/src/debug.rs @@ -22,7 +22,7 @@ use std::fmt; use ra_db::{CrateId, FileId}; -use crate::{db::HirDatabase, Crate, Module, Name}; +use crate::{db::HirDatabase, Crate, HirFileId, Module, Name}; impl Crate { pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { @@ -36,6 +36,12 @@ impl Module { } } +impl HirFileId { + pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { + debug_fn(move |fmt| db.debug_hir_file_id(self, fmt)) + } +} + pub trait HirDebugHelper: HirDatabase { fn crate_name(&self, _krate: CrateId) -> Option { None @@ -48,6 +54,7 @@ pub trait HirDebugHelper: HirDatabase { pub trait HirDebugDatabase { fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; + fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; } impl HirDebugDatabase for DB { @@ -62,12 +69,19 @@ impl HirDebugDatabase for DB { fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let file_id = module.definition_source(self).file_id.original_file(self); - let path = self.file_path(file_id); + let path = self.file_path(file_id).unwrap_or_else(|| "N/A".to_string()); fmt.debug_struct("Module") .field("name", &module.name(self).unwrap_or_else(Name::missing)) - .field("path", &path.unwrap_or_else(|| "N/A".to_string())) + .field("path", &path) .finish() } + + fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + let original = file_id.original_file(self); + let path = self.file_path(original).unwrap_or_else(|| "N/A".to_string()); + let is_macro = file_id != original.into(); + fmt.debug_struct("HirFileId").field("path", &path).field("macro", &is_macro).finish() + } } fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { -- cgit v1.2.3