aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-09-29 21:05:18 +0100
committerAleksey Kladov <[email protected]>2020-09-29 21:13:23 +0100
commitaf8063fe373cf06a345b0d4eee14ef1ef6873bc7 (patch)
tree8d8e459960c98fa9c491f25ef755543363dec76e /crates/ide/src
parente7df0ad2fb48166937fdd061e1ae559c72a81990 (diff)
Extend **Status** command to also show dep info for the file
This should help with troubleshooting wrong project configuration
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/lib.rs4
-rw-r--r--crates/ide/src/status.rs49
2 files changed, 35 insertions, 18 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 96dae9ee0..6d5fd1a55 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -216,8 +216,8 @@ impl Analysis {
216 } 216 }
217 217
218 /// Debug info about the current state of the analysis. 218 /// Debug info about the current state of the analysis.
219 pub fn status(&self) -> Cancelable<String> { 219 pub fn status(&self, file_id: Option<FileId>) -> Cancelable<String> {
220 self.with_db(|db| status::status(&*db)) 220 self.with_db(|db| status::status(&*db, file_id))
221 } 221 }
222 222
223 pub fn prime_caches(&self, files: Vec<FileId>) -> Cancelable<()> { 223 pub fn prime_caches(&self, files: Vec<FileId>) -> Cancelable<()> {
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index 1427c50cf..0af84daa0 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -2,19 +2,19 @@ use std::{fmt, iter::FromIterator, sync::Arc};
2 2
3use base_db::{ 3use base_db::{
4 salsa::debug::{DebugQueryTable, TableEntry}, 4 salsa::debug::{DebugQueryTable, TableEntry},
5 FileTextQuery, SourceRootId, 5 CrateId, FileId, FileTextQuery, SourceDatabase, SourceRootId,
6}; 6};
7use hir::MacroFile; 7use hir::MacroFile;
8use ide_db::{ 8use ide_db::{
9 symbol_index::{LibrarySymbolsQuery, SymbolIndex}, 9 symbol_index::{LibrarySymbolsQuery, SymbolIndex},
10 RootDatabase, 10 RootDatabase,
11}; 11};
12use itertools::Itertools;
12use profile::{memory_usage, Bytes}; 13use profile::{memory_usage, Bytes};
13use rustc_hash::FxHashMap; 14use rustc_hash::FxHashMap;
15use stdx::format_to;
14use syntax::{ast, Parse, SyntaxNode}; 16use syntax::{ast, Parse, SyntaxNode};
15 17
16use crate::FileId;
17
18fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { 18fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
19 base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>() 19 base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>()
20} 20}
@@ -31,19 +31,36 @@ fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
31// 31//
32// | VS Code | **Rust Analyzer: Status** 32// | VS Code | **Rust Analyzer: Status**
33// |=== 33// |===
34pub(crate) fn status(db: &RootDatabase) -> String { 34pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
35 let files_stats = FileTextQuery.in_db(db).entries::<FilesStats>(); 35 let mut buf = String::new();
36 let syntax_tree_stats = syntax_tree_stats(db); 36 format_to!(buf, "{}\n", FileTextQuery.in_db(db).entries::<FilesStats>());
37 let macro_syntax_tree_stats = macro_syntax_tree_stats(db); 37 format_to!(buf, "{}\n", LibrarySymbolsQuery.in_db(db).entries::<LibrarySymbolsStats>());
38 let symbols_stats = LibrarySymbolsQuery.in_db(db).entries::<LibrarySymbolsStats>(); 38 format_to!(buf, "{}\n", syntax_tree_stats(db));
39 format!( 39 format_to!(buf, "{} (macros)\n", macro_syntax_tree_stats(db));
40 "{}\n{}\n{}\n{} (macros)\n{} total\n", 40 format_to!(buf, "{} total\n", memory_usage());
41 files_stats, 41
42 symbols_stats, 42 if let Some(file_id) = file_id {
43 syntax_tree_stats, 43 format_to!(buf, "\nfile info:\n");
44 macro_syntax_tree_stats, 44 let krate = crate::parent_module::crate_for(db, file_id).pop();
45 memory_usage(), 45 match krate {
46 ) 46 Some(krate) => {
47 let crate_graph = db.crate_graph();
48 let display_crate = |krate: CrateId| match &crate_graph[krate].display_name {
49 Some(it) => format!("{}({:?})", it, krate),
50 None => format!("{:?}", krate),
51 };
52 format_to!(buf, "crate: {}\n", display_crate(krate));
53 let deps = crate_graph[krate]
54 .dependencies
55 .iter()
56 .map(|dep| format!("{}={:?}", dep.name, dep.crate_id))
57 .format(", ");
58 format_to!(buf, "deps: {}\n", deps);
59 }
60 None => format_to!(buf, "does not belong to any crate"),
61 }
62 }
63 buf
47} 64}
48 65
49#[derive(Default)] 66#[derive(Default)]