]> git.lizzy.rs Git - rust.git/blobdiff - crates/rust-analyzer/src/cli.rs
Replaced fold with for loop
[rust.git] / crates / rust-analyzer / src / cli.rs
index 6863f100b64024562d6348946add1cb8049dc49c..6ccdaa86dd628786d33a9142e3b199f2dbd5bfa2 100644 (file)
@@ -1,24 +1,22 @@
 //! Various batch processing tasks, intended primarily for debugging.
 
-mod load_cargo;
+pub mod flags;
+pub mod load_cargo;
+mod parse;
+mod symbols;
+mod highlight;
 mod analysis_stats;
-mod analysis_bench;
 mod diagnostics;
-mod progress_report;
 mod ssr;
+mod lsif;
+
+mod progress_report;
 
 use std::io::Read;
 
 use anyhow::Result;
-use ra_ide::{file_structure, Analysis};
-use ra_prof::profile;
-use ra_syntax::{AstNode, SourceFile};
-
-pub use analysis_bench::{analysis_bench, BenchWhat, Position};
-pub use analysis_stats::analysis_stats;
-pub use diagnostics::diagnostics;
-pub use load_cargo::load_cargo;
-pub use ssr::{apply_ssr_rules, search_for_patterns};
+use ide::AnalysisHost;
+use vfs::Vfs;
 
 #[derive(Clone, Copy)]
 pub enum Verbosity {
@@ -37,38 +35,35 @@ pub fn is_spammy(self) -> bool {
     }
 }
 
-pub fn parse(no_dump: bool) -> Result<()> {
-    let _p = profile("parsing");
-    let file = file()?;
-    if !no_dump {
-        println!("{:#?}", file.syntax());
-    }
-    std::mem::forget(file);
-    Ok(())
+fn read_stdin() -> Result<String> {
+    let mut buff = String::new();
+    std::io::stdin().read_to_string(&mut buff)?;
+    Ok(buff)
 }
 
-pub fn symbols() -> Result<()> {
-    let file = file()?;
-    for s in file_structure(&file) {
-        println!("{:?}", s);
+fn report_metric(metric: &str, value: u64, unit: &str) {
+    if std::env::var("RA_METRICS").is_err() {
+        return;
     }
-    Ok(())
+    println!("METRIC:{}:{}:{}", metric, value, unit)
 }
 
-pub fn highlight(rainbow: bool) -> Result<()> {
-    let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
-    let html = analysis.highlight_as_html(file_id, rainbow).unwrap();
-    println!("{}", html);
-    Ok(())
-}
+fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
+    let mut mem = host.per_query_memory_usage();
 
-fn file() -> Result<SourceFile> {
-    let text = read_stdin()?;
-    Ok(SourceFile::parse(&text).tree())
-}
+    let before = profile::memory_usage();
+    drop(vfs);
+    let vfs = before.allocated - profile::memory_usage().allocated;
+    mem.push(("VFS".into(), vfs));
 
-fn read_stdin() -> Result<String> {
-    let mut buff = String::new();
-    std::io::stdin().read_to_string(&mut buff)?;
-    Ok(buff)
+    let before = profile::memory_usage();
+    drop(host);
+    mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
+
+    mem.push(("Remaining".into(), profile::memory_usage().allocated));
+
+    for (name, bytes) in mem {
+        // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
+        eprintln!("{:>8} {}", bytes, name);
+    }
 }