1 //! Various batch processing tasks, intended primarily for debugging.
3 pub(crate) mod load_cargo;
12 use ide::{Analysis, AnalysisHost};
13 use syntax::{AstNode, SourceFile};
17 analysis_stats::AnalysisStatsCmd,
18 diagnostics::diagnostics,
19 ssr::{apply_ssr_rules, search_for_patterns},
22 #[derive(Clone, Copy)]
31 pub fn is_verbose(self) -> bool {
32 matches!(self, Verbosity::Verbose | Verbosity::Spammy)
34 pub fn is_spammy(self) -> bool {
35 matches!(self, Verbosity::Spammy)
39 pub fn parse(no_dump: bool) -> Result<()> {
40 let _p = profile::span("parsing");
43 println!("{:#?}", file.syntax());
45 std::mem::forget(file);
49 pub fn symbols() -> Result<()> {
50 let text = read_stdin()?;
51 let (analysis, file_id) = Analysis::from_single_file(text);
52 let structure = analysis.file_structure(file_id).unwrap();
59 pub fn highlight(rainbow: bool) -> Result<()> {
60 let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
61 let html = analysis.highlight_as_html(file_id, rainbow).unwrap();
66 fn file() -> Result<SourceFile> {
67 let text = read_stdin()?;
68 Ok(SourceFile::parse(&text).tree())
71 fn read_stdin() -> Result<String> {
72 let mut buff = String::new();
73 std::io::stdin().read_to_string(&mut buff)?;
77 fn report_metric(metric: &str, value: u64, unit: &str) {
78 if std::env::var("RA_METRICS").is_err() {
81 println!("METRIC:{}:{}:{}", metric, value, unit)
84 fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
85 let mut mem = host.per_query_memory_usage();
87 let before = profile::memory_usage();
89 let vfs = before.allocated - profile::memory_usage().allocated;
90 mem.push(("VFS".into(), vfs));
92 let before = profile::memory_usage();
94 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
96 mem.push(("Remaining".into(), profile::memory_usage().allocated));
98 for (name, bytes) in mem {
99 // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
100 eprintln!("{:>8} {}", bytes, name);