diff options
author | Aleksey Kladov <[email protected]> | 2020-09-29 21:05:18 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-09-29 21:13:23 +0100 |
commit | af8063fe373cf06a345b0d4eee14ef1ef6873bc7 (patch) | |
tree | 8d8e459960c98fa9c491f25ef755543363dec76e /crates | |
parent | e7df0ad2fb48166937fdd061e1ae559c72a81990 (diff) |
Extend **Status** command to also show dep info for the file
This should help with troubleshooting wrong project configuration
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/status.rs | 49 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 19 | ||||
-rw-r--r-- | crates/rust-analyzer/src/lsp_ext.rs | 8 |
4 files changed, 59 insertions, 21 deletions
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 { | |||
216 | } | 216 | } |
217 | 217 | ||
218 | /// Debug info about the current state of the analysis. | 218 | /// Debug info about the current state of the analysis. |
219 | pub fn status(&self) -> Cancelable<String> { | 219 | pub fn status(&self, file_id: Option<FileId>) -> Cancelable<String> { |
220 | self.with_db(|db| status::status(&*db)) | 220 | self.with_db(|db| status::status(&*db, file_id)) |
221 | } | 221 | } |
222 | 222 | ||
223 | pub fn prime_caches(&self, files: Vec<FileId>) -> Cancelable<()> { | 223 | pub fn prime_caches(&self, files: Vec<FileId>) -> 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}; | |||
2 | 2 | ||
3 | use base_db::{ | 3 | use base_db::{ |
4 | salsa::debug::{DebugQueryTable, TableEntry}, | 4 | salsa::debug::{DebugQueryTable, TableEntry}, |
5 | FileTextQuery, SourceRootId, | 5 | CrateId, FileId, FileTextQuery, SourceDatabase, SourceRootId, |
6 | }; | 6 | }; |
7 | use hir::MacroFile; | 7 | use hir::MacroFile; |
8 | use ide_db::{ | 8 | use ide_db::{ |
9 | symbol_index::{LibrarySymbolsQuery, SymbolIndex}, | 9 | symbol_index::{LibrarySymbolsQuery, SymbolIndex}, |
10 | RootDatabase, | 10 | RootDatabase, |
11 | }; | 11 | }; |
12 | use itertools::Itertools; | ||
12 | use profile::{memory_usage, Bytes}; | 13 | use profile::{memory_usage, Bytes}; |
13 | use rustc_hash::FxHashMap; | 14 | use rustc_hash::FxHashMap; |
15 | use stdx::format_to; | ||
14 | use syntax::{ast, Parse, SyntaxNode}; | 16 | use syntax::{ast, Parse, SyntaxNode}; |
15 | 17 | ||
16 | use crate::FileId; | ||
17 | |||
18 | fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { | 18 | fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { |
19 | base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>() | 19 | base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>() |
20 | } | 20 | } |
@@ -31,19 +31,36 @@ fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { | |||
31 | // | 31 | // |
32 | // | VS Code | **Rust Analyzer: Status** | 32 | // | VS Code | **Rust Analyzer: Status** |
33 | // |=== | 33 | // |=== |
34 | pub(crate) fn status(db: &RootDatabase) -> String { | 34 | pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String { |
35 | let files_stats = FileTextQuery.in_db(db).entries::<FilesStats>(); | 35 | let mut buf = String::new(); |
36 | let syntax_tree_stats = syntax_tree_stats(db); | 36 | format_to!(buf, "{}\n", FileTextQuery.in_db(db).entries::<FilesStats>()); |
37 | let macro_syntax_tree_stats = macro_syntax_tree_stats(db); | 37 | format_to!(buf, "{}\n", LibrarySymbolsQuery.in_db(db).entries::<LibrarySymbolsStats>()); |
38 | let symbols_stats = LibrarySymbolsQuery.in_db(db).entries::<LibrarySymbolsStats>(); | 38 | format_to!(buf, "{}\n", syntax_tree_stats(db)); |
39 | format!( | 39 | format_to!(buf, "{} (macros)\n", macro_syntax_tree_stats(db)); |
40 | "{}\n{}\n{}\n{} (macros)\n{} total\n", | 40 | format_to!(buf, "{} total\n", memory_usage()); |
41 | files_stats, | 41 | |
42 | symbols_stats, | 42 | if let Some(file_id) = file_id { |
43 | syntax_tree_stats, | 43 | format_to!(buf, "\nfile info:\n"); |
44 | macro_syntax_tree_stats, | 44 | let krate = crate::parent_module::crate_for(db, file_id).pop(); |
45 | memory_usage(), | 45 | match krate { |
46 | ) | 46 | Some(krate) => { |
47 | let crate_graph = db.crate_graph(); | ||
48 | let display_crate = |krate: CrateId| match &crate_graph[krate].display_name { | ||
49 | Some(it) => format!("{}({:?})", it, krate), | ||
50 | None => format!("{:?}", krate), | ||
51 | }; | ||
52 | format_to!(buf, "crate: {}\n", display_crate(krate)); | ||
53 | let deps = crate_graph[krate] | ||
54 | .dependencies | ||
55 | .iter() | ||
56 | .map(|dep| format!("{}={:?}", dep.name, dep.crate_id)) | ||
57 | .format(", "); | ||
58 | format_to!(buf, "deps: {}\n", deps); | ||
59 | } | ||
60 | None => format_to!(buf, "does not belong to any crate"), | ||
61 | } | ||
62 | } | ||
63 | buf | ||
47 | } | 64 | } |
48 | 65 | ||
49 | #[derive(Default)] | 66 | #[derive(Default)] |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 7ac1a30f6..afcec63ad 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -38,10 +38,22 @@ use crate::{ | |||
38 | to_proto, LspError, Result, | 38 | to_proto, LspError, Result, |
39 | }; | 39 | }; |
40 | 40 | ||
41 | pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> { | 41 | pub(crate) fn handle_analyzer_status( |
42 | snap: GlobalStateSnapshot, | ||
43 | params: lsp_ext::AnalyzerStatusParams, | ||
44 | ) -> Result<String> { | ||
42 | let _p = profile::span("handle_analyzer_status"); | 45 | let _p = profile::span("handle_analyzer_status"); |
43 | 46 | ||
44 | let mut buf = String::new(); | 47 | let mut buf = String::new(); |
48 | |||
49 | let mut file_id = None; | ||
50 | if let Some(tdi) = params.text_document { | ||
51 | match from_proto::file_id(&snap, &tdi.uri) { | ||
52 | Ok(it) => file_id = Some(it), | ||
53 | Err(_) => format_to!(buf, "file {} not found in vfs", tdi.uri), | ||
54 | } | ||
55 | } | ||
56 | |||
45 | if snap.workspaces.is_empty() { | 57 | if snap.workspaces.is_empty() { |
46 | buf.push_str("no workspaces\n") | 58 | buf.push_str("no workspaces\n") |
47 | } else { | 59 | } else { |
@@ -52,7 +64,10 @@ pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result | |||
52 | } | 64 | } |
53 | buf.push_str("\nanalysis:\n"); | 65 | buf.push_str("\nanalysis:\n"); |
54 | buf.push_str( | 66 | buf.push_str( |
55 | &snap.analysis.status().unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()), | 67 | &snap |
68 | .analysis | ||
69 | .status(file_id) | ||
70 | .unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()), | ||
56 | ); | 71 | ); |
57 | format_to!(buf, "\n\nrequests:\n"); | 72 | format_to!(buf, "\n\nrequests:\n"); |
58 | let requests = snap.latest_requests.read(); | 73 | let requests = snap.latest_requests.read(); |
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index e1a28b1b4..43ff191da 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs | |||
@@ -11,11 +11,17 @@ use serde::{Deserialize, Serialize}; | |||
11 | pub enum AnalyzerStatus {} | 11 | pub enum AnalyzerStatus {} |
12 | 12 | ||
13 | impl Request for AnalyzerStatus { | 13 | impl Request for AnalyzerStatus { |
14 | type Params = (); | 14 | type Params = AnalyzerStatusParams; |
15 | type Result = String; | 15 | type Result = String; |
16 | const METHOD: &'static str = "rust-analyzer/analyzerStatus"; | 16 | const METHOD: &'static str = "rust-analyzer/analyzerStatus"; |
17 | } | 17 | } |
18 | 18 | ||
19 | #[derive(Deserialize, Serialize, Debug)] | ||
20 | #[serde(rename_all = "camelCase")] | ||
21 | pub struct AnalyzerStatusParams { | ||
22 | pub text_document: Option<TextDocumentIdentifier>, | ||
23 | } | ||
24 | |||
19 | pub enum MemoryUsage {} | 25 | pub enum MemoryUsage {} |
20 | 26 | ||
21 | impl Request for MemoryUsage { | 27 | impl Request for MemoryUsage { |