diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-09-29 21:13:53 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-29 21:13:53 +0100 |
commit | 7c9ae771bca39d511a0ea7395da2b4b91b44ee12 (patch) | |
tree | 8d8e459960c98fa9c491f25ef755543363dec76e /crates/ide/src | |
parent | 80b0b0ea03a36451210c6f1beec66aa1150f194f (diff) | |
parent | af8063fe373cf06a345b0d4eee14ef1ef6873bc7 (diff) |
Merge #6096
6096: Extend **Status** command to also show dep info for the file r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/status.rs | 49 |
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 | ||
3 | use base_db::{ | 3 | use base_db::{ |
4 | salsa::debug::{DebugQueryTable, TableEntry}, | 4 | salsa::debug::{DebugQueryTable, TableEntry}, |
5 | FileTextQuery, SourceRootId, | 5 | CrateId, FileId, FileTextQuery, SourceDatabase, SourceRootId, |
6 | }; | 6 | }; |
7 | use hir::MacroFile; | 7 | use hir::MacroFile; |
8 | use ide_db::{ | 8 | use ide_db::{ |
9 | symbol_index::{LibrarySymbolsQuery, SymbolIndex}, | 9 | symbol_index::{LibrarySymbolsQuery, SymbolIndex}, |
10 | RootDatabase, | 10 | RootDatabase, |
11 | }; | 11 | }; |
12 | use itertools::Itertools; | ||
12 | use profile::{memory_usage, Bytes}; | 13 | use profile::{memory_usage, Bytes}; |
13 | use rustc_hash::FxHashMap; | 14 | use rustc_hash::FxHashMap; |
15 | use stdx::format_to; | ||
14 | use syntax::{ast, Parse, SyntaxNode}; | 16 | use syntax::{ast, Parse, SyntaxNode}; |
15 | 17 | ||
16 | use crate::FileId; | ||
17 | |||
18 | fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { | 18 | fn 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 | // |=== |
34 | pub(crate) fn status(db: &RootDatabase) -> String { | 34 | pub(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)] |