From 9fe09db771aa3890ac8a0eeb1d9e6097060fad06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Jan 2019 12:41:08 +0300 Subject: encapsulate hir locations --- crates/ra_ide_api/src/db.rs | 36 ++++++++---------------------------- crates/ra_ide_api/src/status.rs | 4 ++-- 2 files changed, 10 insertions(+), 30 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index a1b666899..ba0eb1cb8 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -1,7 +1,7 @@ -use std::{fmt, sync::Arc}; +use std::sync::Arc; use ra_db::{ - LocationIntener, BaseDatabase, FileId, Canceled, + BaseDatabase, FileId, Canceled, salsa::{self, Database}, }; @@ -10,21 +10,7 @@ use crate::{symbol_index, LineIndex}; #[derive(Debug)] pub(crate) struct RootDatabase { runtime: salsa::Runtime, - id_maps: Arc, -} - -#[derive(Default)] -struct IdMaps { - defs: LocationIntener, - macros: 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() - } + interner: Arc, } impl salsa::Database for RootDatabase { @@ -40,7 +26,7 @@ impl Default for RootDatabase { fn default() -> RootDatabase { let mut db = RootDatabase { runtime: salsa::Runtime::default(), - id_maps: Default::default(), + interner: Default::default(), }; db.query_mut(ra_db::CrateGraphQuery) .set((), Default::default()); @@ -56,22 +42,16 @@ impl salsa::ParallelDatabase for RootDatabase { fn snapshot(&self) -> salsa::Snapshot { salsa::Snapshot::new(RootDatabase { runtime: self.runtime.snapshot(self), - id_maps: self.id_maps.clone(), + interner: Arc::clone(&self.interner), }) } } impl BaseDatabase for RootDatabase {} -impl AsRef> for RootDatabase { - fn as_ref(&self) -> &LocationIntener { - &self.id_maps.defs - } -} - -impl AsRef> for RootDatabase { - fn as_ref(&self) -> &LocationIntener { - &self.id_maps.macros +impl AsRef for RootDatabase { + fn as_ref(&self) -> &hir::HirInterner { + &self.interner } } diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index d3e04be23..5c14cbdeb 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs @@ -1,5 +1,5 @@ use ra_db::{ - LocationIntener, SourceFileQuery, + SourceFileQuery, salsa::{Database, debug::DebugQueryTable}, }; @@ -8,7 +8,7 @@ use crate::db::RootDatabase; pub(crate) fn status(db: &RootDatabase) -> String { let n_parsed_files = db.query(SourceFileQuery).keys::>().len(); let n_defs = { - let interner: &LocationIntener = db.as_ref(); + let interner: &hir::HirInterner = db.as_ref(); interner.len() }; format!("#n_parsed_files {}\n#n_defs {}\n", n_parsed_files, n_defs) -- cgit v1.2.3