mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
better debug impls
This commit is contained in:
parent
aa628f4749
commit
164d53b22f
2 changed files with 17 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
use std::sync::Arc;
|
use std::{fmt, sync::Arc};
|
||||||
use salsa::{self, Database};
|
use salsa::{self, Database};
|
||||||
use ra_db::{LocationIntener, BaseDatabase};
|
use ra_db::{LocationIntener, BaseDatabase};
|
||||||
use hir::{self, DefId, DefLoc};
|
use hir::{self, DefId, DefLoc};
|
||||||
|
@ -13,11 +13,19 @@ pub(crate) struct RootDatabase {
|
||||||
id_maps: Arc<IdMaps>,
|
id_maps: Arc<IdMaps>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Default)]
|
||||||
struct IdMaps {
|
struct IdMaps {
|
||||||
defs: LocationIntener<DefLoc, DefId>,
|
defs: LocationIntener<DefLoc, DefId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
impl salsa::Database for RootDatabase {
|
||||||
fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
|
fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
|
||||||
&self.runtime
|
&self.runtime
|
||||||
|
|
|
@ -42,6 +42,10 @@ where
|
||||||
ID: NumericId,
|
ID: NumericId,
|
||||||
LOC: Clone + Eq + Hash,
|
LOC: Clone + Eq + Hash,
|
||||||
{
|
{
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.loc2id.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn loc2id(&mut self, loc: &LOC) -> ID {
|
pub fn loc2id(&mut self, loc: &LOC) -> ID {
|
||||||
match self.loc2id.get(loc) {
|
match self.loc2id.get(loc) {
|
||||||
Some(id) => return id.clone(),
|
Some(id) => return id.clone(),
|
||||||
|
@ -91,6 +95,9 @@ where
|
||||||
ID: NumericId,
|
ID: NumericId,
|
||||||
LOC: Clone + Eq + Hash,
|
LOC: Clone + Eq + Hash,
|
||||||
{
|
{
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.map.lock().len()
|
||||||
|
}
|
||||||
pub fn loc2id(&self, loc: &LOC) -> ID {
|
pub fn loc2id(&self, loc: &LOC) -> ID {
|
||||||
self.map.lock().loc2id(loc)
|
self.map.lock().loc2id(loc)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue