Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/status.rs')
-rw-r--r--crates/ide/src/status.rs254
1 files changed, 22 insertions, 232 deletions
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index a44be67668..55a0db2d82 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -1,29 +1,8 @@
-use std::{fmt, marker::PhantomData};
-
-use hir::{
- db::{AstIdMapQuery, AttrsQuery, BlockDefMapQuery, ParseMacroExpansionQuery},
- Attr, Attrs, ExpandResult, MacroFileId, Module,
-};
-use ide_db::{
- base_db::{
- ra_salsa::{
- debug::{DebugQueryTable, TableEntry},
- Query, QueryTable,
- },
- CompressedFileTextQuery, CrateData, ParseQuery, SourceDatabase, SourceRootId,
- },
- symbol_index::ModuleSymbolsQuery,
-};
-use ide_db::{
- symbol_index::{LibrarySymbolsQuery, SymbolIndex},
- RootDatabase,
-};
+use ide_db::RootDatabase;
+use ide_db::base_db::{BuiltCrateData, ExtraCrateData};
use itertools::Itertools;
-use profile::{memory_usage, Bytes};
-use span::{EditionedFileId, FileId};
+use span::FileId;
use stdx::format_to;
-use syntax::{ast, Parse, SyntaxNode};
-use triomphe::Arc;
// Feature: Status
//
@@ -37,17 +16,17 @@ use triomphe::Arc;
pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
let mut buf = String::new();
- format_to!(buf, "{}\n", collect_query(CompressedFileTextQuery.in_db(db)));
- format_to!(buf, "{}\n", collect_query(ParseQuery.in_db(db)));
- format_to!(buf, "{}\n", collect_query(ParseMacroExpansionQuery.in_db(db)));
- format_to!(buf, "{}\n", collect_query(LibrarySymbolsQuery.in_db(db)));
- format_to!(buf, "{}\n", collect_query(ModuleSymbolsQuery.in_db(db)));
- format_to!(buf, "{} in total\n", memory_usage());
+ // format_to!(buf, "{}\n", collect_query(CompressedFileTextQuery.in_db(db)));
+ // format_to!(buf, "{}\n", collect_query(ParseQuery.in_db(db)));
+ // format_to!(buf, "{}\n", collect_query(ParseMacroExpansionQuery.in_db(db)));
+ // format_to!(buf, "{}\n", collect_query(LibrarySymbolsQuery.in_db(db)));
+ // format_to!(buf, "{}\n", collect_query(ModuleSymbolsQuery.in_db(db)));
+ // format_to!(buf, "{} in total\n", memory_usage());
- format_to!(buf, "\nDebug info:\n");
- format_to!(buf, "{}\n", collect_query(AttrsQuery.in_db(db)));
- format_to!(buf, "{} ast id maps\n", collect_query_count(AstIdMapQuery.in_db(db)));
- format_to!(buf, "{} block def maps\n", collect_query_count(BlockDefMapQuery.in_db(db)));
+ // format_to!(buf, "\nDebug info:\n");
+ // format_to!(buf, "{}\n", collect_query(AttrsQuery.in_db(db)));
+ // format_to!(buf, "{} ast id maps\n", collect_query_count(AstIdMapQuery.in_db(db)));
+ // format_to!(buf, "{} block def maps\n", collect_query_count(BlockDefMapQuery.in_db(db)));
if let Some(file_id) = file_id {
format_to!(buf, "\nCrates for file {}:\n", file_id.index());
@@ -55,27 +34,25 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
if crates.is_empty() {
format_to!(buf, "Does not belong to any crate");
}
- let crate_graph = db.crate_graph();
for crate_id in crates {
- let CrateData {
+ let BuiltCrateData {
root_file_id,
edition,
- version,
- display_name,
- cfg_options,
- potential_cfg_options,
- env,
dependencies,
origin,
is_proc_macro,
proc_macro_cwd,
- } = &crate_graph[crate_id];
+ } = crate_id.data(db);
+ let ExtraCrateData { version, display_name, potential_cfg_options } =
+ crate_id.extra_data(db);
+ let cfg_options = crate_id.cfg_options(db);
+ let env = crate_id.env(db);
format_to!(
buf,
"Crate: {}\n",
match display_name {
- Some(it) => format!("{it}({})", crate_id.into_raw()),
- None => format!("{}", crate_id.into_raw()),
+ Some(it) => format!("{it}({:?})", crate_id),
+ None => format!("{:?}", crate_id),
}
);
format_to!(buf, " Root module file id: {}\n", root_file_id.index());
@@ -89,7 +66,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
format_to!(buf, " Proc macro cwd: {:?}\n", proc_macro_cwd);
let deps = dependencies
.iter()
- .map(|dep| format!("{}={}", dep.name, dep.crate_id.into_raw()))
+ .map(|dep| format!("{}={:?}", dep.name, dep.crate_id))
.format(", ");
format_to!(buf, " Dependencies: {}\n", deps);
}
@@ -97,190 +74,3 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
buf.trim().to_owned()
}
-
-fn collect_query<'q, Q>(table: QueryTable<'q, Q>) -> <Q as QueryCollect>::Collector
-where
- QueryTable<'q, Q>: DebugQueryTable,
- Q: QueryCollect,
- <Q as Query>::Storage: 'q,
- <Q as QueryCollect>::Collector: StatCollect<
- <QueryTable<'q, Q> as DebugQueryTable>::Key,
- <QueryTable<'q, Q> as DebugQueryTable>::Value,
- >,
-{
- struct StatCollectorWrapper<C>(C);
- impl<C: StatCollect<K, V>, K, V> FromIterator<TableEntry<K, V>> for StatCollectorWrapper<C> {
- fn from_iter<T>(iter: T) -> StatCollectorWrapper<C>
- where
- T: IntoIterator<Item = TableEntry<K, V>>,
- {
- let mut res = C::default();
- for entry in iter {
- res.collect_entry(entry.key, entry.value);
- }
- StatCollectorWrapper(res)
- }
- }
- table.entries::<StatCollectorWrapper<<Q as QueryCollect>::Collector>>().0
-}
-
-fn collect_query_count<'q, Q>(table: QueryTable<'q, Q>) -> usize
-where
- QueryTable<'q, Q>: DebugQueryTable,
- Q: Query,
- <Q as Query>::Storage: 'q,
-{
- struct EntryCounter(usize);
- impl<K, V> FromIterator<TableEntry<K, V>> for EntryCounter {
- fn from_iter<T>(iter: T) -> EntryCounter
- where
- T: IntoIterator<Item = TableEntry<K, V>>,
- {
- EntryCounter(iter.into_iter().count())
- }
- }
- table.entries::<EntryCounter>().0
-}
-
-trait QueryCollect: Query {
- type Collector;
-}
-
-impl QueryCollect for LibrarySymbolsQuery {
- type Collector = SymbolsStats<SourceRootId>;
-}
-
-impl QueryCollect for ParseQuery {
- type Collector = SyntaxTreeStats<false>;
-}
-
-impl QueryCollect for ParseMacroExpansionQuery {
- type Collector = SyntaxTreeStats<true>;
-}
-
-impl QueryCollect for CompressedFileTextQuery {
- type Collector = FilesStats;
-}
-
-impl QueryCollect for ModuleSymbolsQuery {
- type Collector = SymbolsStats<Module>;
-}
-
-impl QueryCollect for AttrsQuery {
- type Collector = AttrsStats;
-}
-
-trait StatCollect<K, V>: Default {
- fn collect_entry(&mut self, key: K, value: Option<V>);
-}
-
-#[derive(Default)]
-struct FilesStats {
- total: usize,
- size: Bytes,
-}
-
-impl fmt::Display for FilesStats {
- fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(fmt, "{} of files", self.size)
- }
-}
-
-impl StatCollect<FileId, Arc<[u8]>> for FilesStats {
- fn collect_entry(&mut self, _: FileId, value: Option<Arc<[u8]>>) {
- self.total += 1;
- self.size += value.unwrap().len();
- }
-}
-
-#[derive(Default)]
-pub(crate) struct SyntaxTreeStats<const MACROS: bool> {
- total: usize,
- pub(crate) retained: usize,
-}
-
-impl<const MACROS: bool> fmt::Display for SyntaxTreeStats<MACROS> {
- fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- fmt,
- "{} trees, {} preserved{}",
- self.total,
- self.retained,
- if MACROS { " (macros)" } else { "" }
- )
- }
-}
-
-impl StatCollect<EditionedFileId, Parse<ast::SourceFile>> for SyntaxTreeStats<false> {
- fn collect_entry(&mut self, _: EditionedFileId, value: Option<Parse<ast::SourceFile>>) {
- self.total += 1;
- self.retained += value.is_some() as usize;
- }
-}
-
-impl<M> StatCollect<MacroFileId, ExpandResult<(Parse<SyntaxNode>, M)>> for SyntaxTreeStats<true> {
- fn collect_entry(
- &mut self,
- _: MacroFileId,
- value: Option<ExpandResult<(Parse<SyntaxNode>, M)>>,
- ) {
- self.total += 1;
- self.retained += value.is_some() as usize;
- }
-}
-
-struct SymbolsStats<Key> {
- total: usize,
- size: Bytes,
- phantom: PhantomData<Key>,
-}
-
-impl<Key> Default for SymbolsStats<Key> {
- fn default() -> Self {
- Self { total: Default::default(), size: Default::default(), phantom: PhantomData }
- }
-}
-
-impl fmt::Display for SymbolsStats<Module> {
- fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(fmt, "{} of module index symbols ({})", self.size, self.total)
- }
-}
-impl fmt::Display for SymbolsStats<SourceRootId> {
- fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(fmt, "{} of library index symbols ({})", self.size, self.total)
- }
-}
-impl<Key> StatCollect<Key, Arc<SymbolIndex>> for SymbolsStats<Key> {
- fn collect_entry(&mut self, _: Key, value: Option<Arc<SymbolIndex>>) {
- if let Some(symbols) = value {
- self.total += symbols.len();
- self.size += symbols.memory_size();
- }
- }
-}
-
-#[derive(Default)]
-struct AttrsStats {
- entries: usize,
- total: usize,
-}
-
-impl fmt::Display for AttrsStats {
- fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- let size = self.entries * size_of::<Attrs>() + self.total * size_of::<Attr>();
- let size = Bytes::new(size as _);
- write!(
- fmt,
- "{} attribute query entries, {} total attributes ({} for storing entries)",
- self.entries, self.total, size
- )
- }
-}
-
-impl<Key> StatCollect<Key, Attrs> for AttrsStats {
- fn collect_entry(&mut self, _: Key, value: Option<Attrs>) {
- self.entries += 1;
- self.total += value.map_or(0, |it| it.len());
- }
-}