mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Extend **Status** command to also show dep info for the file
This should help with troubleshooting wrong project configuration
This commit is contained in:
parent
e7df0ad2fb
commit
af8063fe37
8 changed files with 85 additions and 32 deletions
|
@ -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::<SyntaxTreeStats>()
|
||||
}
|
||||
|
@ -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::<FilesStats>();
|
||||
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::<LibrarySymbolsStats>();
|
||||
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<FileId>) -> String {
|
||||
let mut buf = String::new();
|
||||
format_to!(buf, "{}\n", FileTextQuery.in_db(db).entries::<FilesStats>());
|
||||
format_to!(buf, "{}\n", LibrarySymbolsQuery.in_db(db).entries::<LibrarySymbolsStats>());
|
||||
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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue