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
|
|
@ -216,8 +216,8 @@ impl Analysis {
|
|||
}
|
||||
|
||||
/// Debug info about the current state of the analysis.
|
||||
pub fn status(&self) -> Cancelable<String> {
|
||||
self.with_db(|db| status::status(&*db))
|
||||
pub fn status(&self, file_id: Option<FileId>) -> Cancelable<String> {
|
||||
self.with_db(|db| status::status(&*db, file_id))
|
||||
}
|
||||
|
||||
pub fn prime_caches(&self, files: Vec<FileId>) -> Cancelable<()> {
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -38,10 +38,22 @@ use crate::{
|
|||
to_proto, LspError, Result,
|
||||
};
|
||||
|
||||
pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> {
|
||||
pub(crate) fn handle_analyzer_status(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_ext::AnalyzerStatusParams,
|
||||
) -> Result<String> {
|
||||
let _p = profile::span("handle_analyzer_status");
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
let mut file_id = None;
|
||||
if let Some(tdi) = params.text_document {
|
||||
match from_proto::file_id(&snap, &tdi.uri) {
|
||||
Ok(it) => file_id = Some(it),
|
||||
Err(_) => format_to!(buf, "file {} not found in vfs", tdi.uri),
|
||||
}
|
||||
}
|
||||
|
||||
if snap.workspaces.is_empty() {
|
||||
buf.push_str("no workspaces\n")
|
||||
} else {
|
||||
|
|
@ -52,7 +64,10 @@ pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result
|
|||
}
|
||||
buf.push_str("\nanalysis:\n");
|
||||
buf.push_str(
|
||||
&snap.analysis.status().unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()),
|
||||
&snap
|
||||
.analysis
|
||||
.status(file_id)
|
||||
.unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()),
|
||||
);
|
||||
format_to!(buf, "\n\nrequests:\n");
|
||||
let requests = snap.latest_requests.read();
|
||||
|
|
|
|||
|
|
@ -11,11 +11,17 @@ use serde::{Deserialize, Serialize};
|
|||
pub enum AnalyzerStatus {}
|
||||
|
||||
impl Request for AnalyzerStatus {
|
||||
type Params = ();
|
||||
type Params = AnalyzerStatusParams;
|
||||
type Result = String;
|
||||
const METHOD: &'static str = "rust-analyzer/analyzerStatus";
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AnalyzerStatusParams {
|
||||
pub text_document: Option<TextDocumentIdentifier>,
|
||||
}
|
||||
|
||||
pub enum MemoryUsage {}
|
||||
|
||||
impl Request for MemoryUsage {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue