Skip to content

Commit

Permalink
Merge #9269
Browse files Browse the repository at this point in the history
9269: Recreate status page r=lnicola a=Milo123459

I'm working on redesigning the status page.

Co-authored-by: Milo <50248166+Milo123459@users.noreply.github.com>
  • Loading branch information
bors[bot] and Milo123459 committed Jun 29, 2021
2 parents 1b9b2d1 + 4d8fe62 commit 11b9233
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
25 changes: 14 additions & 11 deletions crates/ide/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ide_db::{
use itertools::Itertools;
use profile::{memory_usage, Bytes};
use rustc_hash::FxHashMap;
use std::env;
use stdx::format_to;
use syntax::{ast, Parse, SyntaxNode};

Expand All @@ -37,12 +38,14 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
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());
format_to!(buf, "\ncounts:\n{}", profile::countme::get_all());
format_to!(buf, "{} (Macros)\n", macro_syntax_tree_stats(db));
format_to!(buf, "{} in total\n", memory_usage());
if env::var("RA_COUNT").is_ok() {
format_to!(buf, "\nCounts:\n{}", profile::countme::get_all());
}

if let Some(file_id) = file_id {
format_to!(buf, "\nfile info:\n");
format_to!(buf, "\nFile info:\n");
let krate = crate::parent_module::crate_for(db, file_id).pop();
match krate {
Some(krate) => {
Expand All @@ -51,19 +54,19 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
Some(it) => format!("{}({:?})", it, krate),
None => format!("{:?}", krate),
};
format_to!(buf, "crate: {}\n", display_crate(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);
format_to!(buf, "Dependencies: {}\n", deps);
}
None => format_to!(buf, "does not belong to any crate"),
None => format_to!(buf, "Does not belong to any crate"),
}
}

buf
buf.trim().to_string()
}

#[derive(Default)]
Expand All @@ -74,7 +77,7 @@ struct FilesStats {

impl fmt::Display for FilesStats {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{} ({}) files", self.total, self.size)
write!(fmt, "{} of files", self.size)
}
}

Expand All @@ -100,7 +103,7 @@ pub(crate) struct SyntaxTreeStats {

impl fmt::Display for SyntaxTreeStats {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{} trees, {} retained", self.total, self.retained)
write!(fmt, "{} trees, {} preserved", self.total, self.retained)
}
}

Expand Down Expand Up @@ -142,7 +145,7 @@ struct LibrarySymbolsStats {

impl fmt::Display for LibrarySymbolsStats {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{} ({}) index symbols", self.total, self.size)
write!(fmt, "{} of index symbols ({})", self.size, self.total)
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ tracing = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
tracing-tree = { version = "0.1.4" }
always-assert = "0.1"

stdx = { path = "../stdx", version = "0.0.0" }
flycheck = { path = "../flycheck", version = "0.0.0" }
ide = { path = "../ide", version = "0.0.0" }
Expand Down
18 changes: 11 additions & 7 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,25 @@ pub(crate) fn handle_analyzer_status(
}

if snap.workspaces.is_empty() {
buf.push_str("no workspaces\n")
buf.push_str("No workspaces\n")
} else {
buf.push_str("workspaces:\n");
for w in snap.workspaces.iter() {
format_to!(buf, "{} packages loaded\n", w.n_packages());
}
buf.push_str("Workspaces:\n");
format_to!(
buf,
"Loaded {:?} packages across {} workspace{}.\n",
snap.workspaces.iter().map(|w| w.n_packages()).sum::<usize>(),
snap.workspaces.len(),
if snap.workspaces.len() == 1 { "" } else { "s" }
);
}
buf.push_str("\nanalysis:\n");
buf.push_str("\nAnalysis:\n");
buf.push_str(
&snap
.analysis
.status(file_id)
.unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()),
);
format_to!(buf, "\n\nrequests:\n");
format_to!(buf, "\n\nRequests:\n");
let requests = snap.latest_requests.read();
for (is_last, r) in requests.iter() {
let mark = if is_last { "*" } else { " " };
Expand Down

0 comments on commit 11b9233

Please sign in to comment.