diff options
author | Aleksey Kladov <[email protected]> | 2019-09-08 07:48:45 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-09 10:32:16 +0100 |
commit | ef2b84ddf119c950272c5f1eb321f3f9e90bedd4 (patch) | |
tree | d746c95cef14b27f67f1e5fd32d289e6d20b4d57 /crates/ra_ide_api/src/change.rs | |
parent | 734a43e95afc97773c234956a95b78caed88f2a3 (diff) |
introduce hir debugging infra
This is to make debugging rust-analyzer easier.
The idea is that `dbg!(krate.debug(db))` will print the actual, fuzzy
crate name, instead of precise ID. Debug printing infra is a separate
thing, to make sure that the actual hir doesn't have access to global
information.
Do not use `.debug` for `log::` logging: debugging executes queries,
and might introduce unneded dependencies to the crate graph
Diffstat (limited to 'crates/ra_ide_api/src/change.rs')
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 89631935a..0d52f5ffb 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -2,7 +2,7 @@ use std::{fmt, sync::Arc, time}; | |||
2 | 2 | ||
3 | use ra_db::{ | 3 | use ra_db::{ |
4 | salsa::{Database, Durability, SweepStrategy}, | 4 | salsa::{Database, Durability, SweepStrategy}, |
5 | CrateGraph, FileId, SourceDatabase, SourceRoot, SourceRootId, | 5 | CrateGraph, CrateId, FileId, SourceDatabase, SourceRoot, SourceRootId, |
6 | }; | 6 | }; |
7 | use ra_prof::{memory_usage, profile, Bytes}; | 7 | use ra_prof::{memory_usage, profile, Bytes}; |
8 | use ra_syntax::SourceFile; | 8 | use ra_syntax::SourceFile; |
@@ -11,7 +11,7 @@ use relative_path::RelativePathBuf; | |||
11 | use rustc_hash::FxHashMap; | 11 | use rustc_hash::FxHashMap; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | db::RootDatabase, | 14 | db::{DebugData, RootDatabase}, |
15 | status::syntax_tree_stats, | 15 | status::syntax_tree_stats, |
16 | symbol_index::{SymbolIndex, SymbolsDatabase}, | 16 | symbol_index::{SymbolIndex, SymbolsDatabase}, |
17 | }; | 17 | }; |
@@ -23,6 +23,7 @@ pub struct AnalysisChange { | |||
23 | files_changed: Vec<(FileId, Arc<String>)>, | 23 | files_changed: Vec<(FileId, Arc<String>)>, |
24 | libraries_added: Vec<LibraryData>, | 24 | libraries_added: Vec<LibraryData>, |
25 | crate_graph: Option<CrateGraph>, | 25 | crate_graph: Option<CrateGraph>, |
26 | debug_data: DebugData, | ||
26 | } | 27 | } |
27 | 28 | ||
28 | impl fmt::Debug for AnalysisChange { | 29 | impl fmt::Debug for AnalysisChange { |
@@ -83,6 +84,14 @@ impl AnalysisChange { | |||
83 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { | 84 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { |
84 | self.crate_graph = Some(graph); | 85 | self.crate_graph = Some(graph); |
85 | } | 86 | } |
87 | |||
88 | pub fn set_debug_crate_name(&mut self, crate_id: CrateId, name: String) { | ||
89 | self.debug_data.crate_names.insert(crate_id, name); | ||
90 | } | ||
91 | |||
92 | pub fn set_debug_root_path(&mut self, source_root_id: SourceRootId, path: String) { | ||
93 | self.debug_data.root_paths.insert(source_root_id, path); | ||
94 | } | ||
86 | } | 95 | } |
87 | 96 | ||
88 | #[derive(Debug)] | 97 | #[derive(Debug)] |
@@ -200,6 +209,8 @@ impl RootDatabase { | |||
200 | if let Some(crate_graph) = change.crate_graph { | 209 | if let Some(crate_graph) = change.crate_graph { |
201 | self.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH) | 210 | self.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH) |
202 | } | 211 | } |
212 | |||
213 | Arc::make_mut(&mut self.debug_data).merge(change.debug_data) | ||
203 | } | 214 | } |
204 | 215 | ||
205 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { | 216 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { |