From 164d53b22f345e50c67781af545310d2193e8a5c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Dec 2018 11:48:52 +0300 Subject: better debug impls --- crates/ra_analysis/src/db.rs | 12 ++++++++++-- crates/ra_db/src/loc2id.rs | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 3d0f13f34..94729d296 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{fmt, sync::Arc}; use salsa::{self, Database}; use ra_db::{LocationIntener, BaseDatabase}; use hir::{self, DefId, DefLoc}; @@ -13,11 +13,19 @@ pub(crate) struct RootDatabase { id_maps: Arc, } -#[derive(Debug, Default)] +#[derive(Default)] struct IdMaps { defs: LocationIntener, } +impl fmt::Debug for IdMaps { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("IdMaps") + .field("n_defs", &self.defs.len()) + .finish() + } +} + impl salsa::Database for RootDatabase { fn salsa_runtime(&self) -> &salsa::Runtime { &self.runtime diff --git a/crates/ra_db/src/loc2id.rs b/crates/ra_db/src/loc2id.rs index 69ba43d0f..2dc7930d8 100644 --- a/crates/ra_db/src/loc2id.rs +++ b/crates/ra_db/src/loc2id.rs @@ -42,6 +42,10 @@ where ID: NumericId, LOC: Clone + Eq + Hash, { + pub fn len(&self) -> usize { + self.loc2id.len() + } + pub fn loc2id(&mut self, loc: &LOC) -> ID { match self.loc2id.get(loc) { Some(id) => return id.clone(), @@ -91,6 +95,9 @@ where ID: NumericId, LOC: Clone + Eq + Hash, { + pub fn len(&self) -> usize { + self.map.lock().len() + } pub fn loc2id(&self, loc: &LOC) -> ID { self.map.lock().loc2id(loc) } -- cgit v1.2.3