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 load_cargo::{load_workspace, load_workspace_at, LoadCargoConfig},
20 ssr::{apply_ssr_rules, search_for_patterns},
23 #[derive(Clone, Copy)]
32 pub fn is_verbose(self) -> bool {
33 matches!(self, Verbosity::Verbose | Verbosity::Spammy)
35 pub fn is_spammy(self) -> bool {
36 matches!(self, Verbosity::Spammy)
40 pub fn parse(no_dump: bool) -> Result<()> {
41 let _p = profile::span("parsing");
44 println!("{:#?}", file.syntax());
46 std::mem::forget(file);
50 pub fn symbols() -> Result<()> {
51 let text = read_stdin()?;
52 let (analysis, file_id) = Analysis::from_single_file(text);
53 let structure = analysis.file_structure(file_id).unwrap();
60 pub fn highlight(rainbow: bool) -> Result<()> {
61 let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
62 let html = analysis.highlight_as_html(file_id, rainbow).unwrap();
67 fn file() -> Result<SourceFile> {
68 let text = read_stdin()?;
69 Ok(SourceFile::parse(&text).tree())
72 fn read_stdin() -> Result<String> {
73 let mut buff = String::new();
74 std::io::stdin().read_to_string(&mut buff)?;
78 fn report_metric(metric: &str, value: u64, unit: &str) {
79 if std::env::var("RA_METRICS").is_err() {
82 println!("METRIC:{}:{}:{}", metric, value, unit)
85 fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
86 let mut mem = host.per_query_memory_usage();
88 let before = profile::memory_usage();
90 let vfs = before.allocated - profile::memory_usage().allocated;
91 mem.push(("VFS".into(), vfs));
93 let before = profile::memory_usage();
95 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
97 mem.push(("Remaining".into(), profile::memory_usage().allocated));
99 for (name, bytes) in mem {
100 // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
101 eprintln!("{:>8} {}", bytes, name);