1 //! Various batch processing tasks, intended primarily for debugging.
13 use ide::{Analysis, AnalysisHost};
14 use syntax::{AstNode, SourceFile};
18 analysis_bench::{BenchCmd, BenchWhat, Position},
19 analysis_stats::AnalysisStatsCmd,
20 diagnostics::diagnostics,
21 load_cargo::{load_workspace, load_workspace_at, LoadCargoConfig},
22 ssr::{apply_ssr_rules, search_for_patterns},
25 #[derive(Clone, Copy)]
34 pub fn is_verbose(self) -> bool {
35 matches!(self, Verbosity::Verbose | Verbosity::Spammy)
37 pub fn is_spammy(self) -> bool {
38 matches!(self, Verbosity::Spammy)
42 pub fn parse(no_dump: bool) -> Result<()> {
43 let _p = profile::span("parsing");
46 println!("{:#?}", file.syntax());
48 std::mem::forget(file);
52 pub fn symbols() -> Result<()> {
53 let text = read_stdin()?;
54 let (analysis, file_id) = Analysis::from_single_file(text);
55 let structure = analysis.file_structure(file_id).unwrap();
62 pub fn highlight(rainbow: bool) -> Result<()> {
63 let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
64 let html = analysis.highlight_as_html(file_id, rainbow).unwrap();
69 fn file() -> Result<SourceFile> {
70 let text = read_stdin()?;
71 Ok(SourceFile::parse(&text).tree())
74 fn read_stdin() -> Result<String> {
75 let mut buff = String::new();
76 std::io::stdin().read_to_string(&mut buff)?;
80 fn report_metric(metric: &str, value: u64, unit: &str) {
81 if std::env::var("RA_METRICS").is_err() {
84 println!("METRIC:{}:{}:{}", metric, value, unit)
87 fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
88 let mut mem = host.per_query_memory_usage();
90 let before = profile::memory_usage();
92 let vfs = before.allocated - profile::memory_usage().allocated;
93 mem.push(("VFS".into(), vfs));
95 let before = profile::memory_usage();
97 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
99 mem.push(("Remaining".into(), profile::memory_usage().allocated));
101 for (name, bytes) in mem {
102 // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
103 eprintln!("{:>8} {}", bytes, name);