diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-09 15:35:21 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-09 15:35:21 +0100 |
commit | 7258523a519207a033dedde8c498debe8da4a15e (patch) | |
tree | 4d2c08f9b357040ba135fa66aa5a981058f6f55c /crates/ra_ide_api/src/db.rs | |
parent | 76f39b4b20d32b67fb60220e9d2a6ceb3f44fbb7 (diff) | |
parent | e5a8093dd497518c177d3c22404d80da44905336 (diff) |
Merge #1789
1789: Debug r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/db.rs')
-rw-r--r-- | crates/ra_ide_api/src/db.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index f2e6b8f12..4c5159d61 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -2,8 +2,9 @@ use std::{sync::Arc, time}; | |||
2 | 2 | ||
3 | use ra_db::{ | 3 | use ra_db::{ |
4 | salsa::{self, Database, Durability}, | 4 | salsa::{self, Database, Durability}, |
5 | Canceled, CheckCanceled, FileId, SourceDatabase, | 5 | Canceled, CheckCanceled, CrateId, FileId, SourceDatabase, SourceRootId, |
6 | }; | 6 | }; |
7 | use rustc_hash::FxHashMap; | ||
7 | 8 | ||
8 | use crate::{ | 9 | use crate::{ |
9 | symbol_index::{self, SymbolsDatabase}, | 10 | symbol_index::{self, SymbolsDatabase}, |
@@ -23,10 +24,23 @@ use crate::{ | |||
23 | pub(crate) struct RootDatabase { | 24 | pub(crate) struct RootDatabase { |
24 | runtime: salsa::Runtime<RootDatabase>, | 25 | runtime: salsa::Runtime<RootDatabase>, |
25 | pub(crate) feature_flags: Arc<FeatureFlags>, | 26 | pub(crate) feature_flags: Arc<FeatureFlags>, |
27 | pub(crate) debug_data: Arc<DebugData>, | ||
26 | pub(crate) last_gc: time::Instant, | 28 | pub(crate) last_gc: time::Instant, |
27 | pub(crate) last_gc_check: time::Instant, | 29 | pub(crate) last_gc_check: time::Instant, |
28 | } | 30 | } |
29 | 31 | ||
32 | impl hir::debug::HirDebugHelper for RootDatabase { | ||
33 | fn crate_name(&self, krate: CrateId) -> Option<String> { | ||
34 | self.debug_data.crate_names.get(&krate).cloned() | ||
35 | } | ||
36 | fn file_path(&self, file_id: FileId) -> Option<String> { | ||
37 | let source_root_id = self.file_source_root(file_id); | ||
38 | let source_root_path = self.debug_data.root_paths.get(&source_root_id)?; | ||
39 | let file_path = self.file_relative_path(file_id); | ||
40 | Some(format!("{}/{}", source_root_path, file_path.display())) | ||
41 | } | ||
42 | } | ||
43 | |||
30 | impl salsa::Database for RootDatabase { | 44 | impl salsa::Database for RootDatabase { |
31 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | 45 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { |
32 | &self.runtime | 46 | &self.runtime |
@@ -58,6 +72,7 @@ impl RootDatabase { | |||
58 | last_gc: time::Instant::now(), | 72 | last_gc: time::Instant::now(), |
59 | last_gc_check: time::Instant::now(), | 73 | last_gc_check: time::Instant::now(), |
60 | feature_flags: Arc::new(feature_flags), | 74 | feature_flags: Arc::new(feature_flags), |
75 | debug_data: Default::default(), | ||
61 | }; | 76 | }; |
62 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); | 77 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); |
63 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); | 78 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); |
@@ -77,6 +92,7 @@ impl salsa::ParallelDatabase for RootDatabase { | |||
77 | last_gc: self.last_gc, | 92 | last_gc: self.last_gc, |
78 | last_gc_check: self.last_gc_check, | 93 | last_gc_check: self.last_gc_check, |
79 | feature_flags: Arc::clone(&self.feature_flags), | 94 | feature_flags: Arc::clone(&self.feature_flags), |
95 | debug_data: Arc::clone(&self.debug_data), | ||
80 | }) | 96 | }) |
81 | } | 97 | } |
82 | } | 98 | } |
@@ -90,3 +106,16 @@ fn line_index(db: &impl ra_db::SourceDatabase, file_id: FileId) -> Arc<LineIndex | |||
90 | let text = db.file_text(file_id); | 106 | let text = db.file_text(file_id); |
91 | Arc::new(LineIndex::new(&*text)) | 107 | Arc::new(LineIndex::new(&*text)) |
92 | } | 108 | } |
109 | |||
110 | #[derive(Debug, Default, Clone)] | ||
111 | pub(crate) struct DebugData { | ||
112 | pub(crate) root_paths: FxHashMap<SourceRootId, String>, | ||
113 | pub(crate) crate_names: FxHashMap<CrateId, String>, | ||
114 | } | ||
115 | |||
116 | impl DebugData { | ||
117 | pub(crate) fn merge(&mut self, other: DebugData) { | ||
118 | self.root_paths.extend(other.root_paths.into_iter()); | ||
119 | self.crate_names.extend(other.crate_names.into_iter()); | ||
120 | } | ||
121 | } | ||