From af8063fe373cf06a345b0d4eee14ef1ef6873bc7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 29 Sep 2020 22:05:18 +0200 Subject: Extend **Status** command to also show dep info for the file This should help with troubleshooting wrong project configuration --- crates/ide/src/lib.rs | 4 ++-- crates/ide/src/status.rs | 49 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 18 deletions(-) (limited to 'crates/ide/src') 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 { } /// Debug info about the current state of the analysis. - pub fn status(&self) -> Cancelable { - self.with_db(|db| status::status(&*db)) + pub fn status(&self, file_id: Option) -> Cancelable { + self.with_db(|db| status::status(&*db, file_id)) } pub fn prime_caches(&self, files: Vec) -> 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}; use base_db::{ salsa::debug::{DebugQueryTable, TableEntry}, - FileTextQuery, SourceRootId, + CrateId, FileId, FileTextQuery, SourceDatabase, SourceRootId, }; use hir::MacroFile; use ide_db::{ symbol_index::{LibrarySymbolsQuery, SymbolIndex}, RootDatabase, }; +use itertools::Itertools; use profile::{memory_usage, Bytes}; use rustc_hash::FxHashMap; +use stdx::format_to; use syntax::{ast, Parse, SyntaxNode}; -use crate::FileId; - fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { base_db::ParseQuery.in_db(db).entries::() } @@ -31,19 +31,36 @@ fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { // // | VS Code | **Rust Analyzer: Status** // |=== -pub(crate) fn status(db: &RootDatabase) -> String { - let files_stats = FileTextQuery.in_db(db).entries::(); - let syntax_tree_stats = syntax_tree_stats(db); - let macro_syntax_tree_stats = macro_syntax_tree_stats(db); - let symbols_stats = LibrarySymbolsQuery.in_db(db).entries::(); - format!( - "{}\n{}\n{}\n{} (macros)\n{} total\n", - files_stats, - symbols_stats, - syntax_tree_stats, - macro_syntax_tree_stats, - memory_usage(), - ) +pub(crate) fn status(db: &RootDatabase, file_id: Option) -> String { + let mut buf = String::new(); + format_to!(buf, "{}\n", FileTextQuery.in_db(db).entries::()); + format_to!(buf, "{}\n", LibrarySymbolsQuery.in_db(db).entries::()); + format_to!(buf, "{}\n", syntax_tree_stats(db)); + format_to!(buf, "{} (macros)\n", macro_syntax_tree_stats(db)); + format_to!(buf, "{} total\n", memory_usage()); + + if let Some(file_id) = file_id { + format_to!(buf, "\nfile info:\n"); + let krate = crate::parent_module::crate_for(db, file_id).pop(); + match krate { + Some(krate) => { + let crate_graph = db.crate_graph(); + let display_crate = |krate: CrateId| match &crate_graph[krate].display_name { + Some(it) => format!("{}({:?})", it, krate), + None => format!("{:?}", krate), + }; + format_to!(buf, "crate: {}\n", display_crate(krate)); + let deps = crate_graph[krate] + .dependencies + .iter() + .map(|dep| format!("{}={:?}", dep.name, dep.crate_id)) + .format(", "); + format_to!(buf, "deps: {}\n", deps); + } + None => format_to!(buf, "does not belong to any crate"), + } + } + buf } #[derive(Default)] -- cgit v1.2.3