aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_db/src/change.rs9
-rw-r--r--crates/rust-analyzer/src/handlers.rs13
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs8
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
4 files changed, 30 insertions, 1 deletions
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index d8da3f949..84c6f40ff 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -164,6 +164,15 @@ impl RootDatabase {
164 hir::db::BodyQuery.in_db(self).sweep(sweep); 164 hir::db::BodyQuery.in_db(self).sweep(sweep);
165 } 165 }
166 166
167 // Feature: Memory Usage
168 //
169 // Clears rust-analyzer's internal database and prints memory usage statistics.
170 //
171 // |===
172 // | Editor | Action Name
173 //
174 // | VS Code | **Rust Analyzer: Memory Usage (Clears Database)**
175 // |===
167 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { 176 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
168 let mut acc: Vec<(String, Bytes)> = vec![]; 177 let mut acc: Vec<(String, Bytes)> = vec![];
169 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); 178 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index cc83a1406..f374334fe 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -32,7 +32,7 @@ use crate::{
32 cargo_target_spec::CargoTargetSpec, 32 cargo_target_spec::CargoTargetSpec,
33 config::RustfmtConfig, 33 config::RustfmtConfig,
34 from_json, from_proto, 34 from_json, from_proto,
35 global_state::GlobalStateSnapshot, 35 global_state::{GlobalState, GlobalStateSnapshot},
36 lsp_ext::{self, InlayHint, InlayHintsParams}, 36 lsp_ext::{self, InlayHint, InlayHintsParams},
37 to_proto, LspError, Result, 37 to_proto, LspError, Result,
38}; 38};
@@ -62,6 +62,17 @@ pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result
62 Ok(buf) 62 Ok(buf)
63} 63}
64 64
65pub(crate) fn handle_memory_usage(state: &mut GlobalState, _: ()) -> Result<String> {
66 let _p = profile("handle_memory_usage");
67 let mem = state.analysis_host.per_query_memory_usage();
68
69 let mut out = String::new();
70 for (name, bytes) in mem {
71 format_to!(out, "{:>8} {}\n", bytes, name);
72 }
73 Ok(out)
74}
75
65pub(crate) fn handle_syntax_tree( 76pub(crate) fn handle_syntax_tree(
66 snap: GlobalStateSnapshot, 77 snap: GlobalStateSnapshot,
67 params: lsp_ext::SyntaxTreeParams, 78 params: lsp_ext::SyntaxTreeParams,
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index d225ad5ff..ba8a0231f 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -14,6 +14,14 @@ impl Request for AnalyzerStatus {
14 const METHOD: &'static str = "rust-analyzer/analyzerStatus"; 14 const METHOD: &'static str = "rust-analyzer/analyzerStatus";
15} 15}
16 16
17pub enum MemoryUsage {}
18
19impl Request for MemoryUsage {
20 type Params = ();
21 type Result = String;
22 const METHOD: &'static str = "rust-analyzer/memoryUsage";
23}
24
17pub enum ReloadWorkspace {} 25pub enum ReloadWorkspace {}
18 26
19impl Request for ReloadWorkspace { 27impl Request for ReloadWorkspace {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index cfde55431..5900886e7 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -341,6 +341,7 @@ impl GlobalState {
341 .on_sync::<lsp_ext::MatchingBrace>(|s, p| { 341 .on_sync::<lsp_ext::MatchingBrace>(|s, p| {
342 handlers::handle_matching_brace(s.snapshot(), p) 342 handlers::handle_matching_brace(s.snapshot(), p)
343 })? 343 })?
344 .on_sync::<lsp_ext::MemoryUsage>(|s, p| handlers::handle_memory_usage(s, p))?
344 .on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)? 345 .on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)?
345 .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)? 346 .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)?
346 .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)? 347 .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)?