2020-02-18 12:11:32 +01:00
|
|
|
//! Various batch processing tasks, intended primarily for debugging.
|
2020-02-17 19:03:03 +01:00
|
|
|
|
|
|
|
mod load_cargo;
|
|
|
|
mod analysis_stats;
|
|
|
|
mod analysis_bench;
|
2020-04-13 05:44:35 -07:00
|
|
|
mod diagnostics;
|
2020-02-17 19:03:03 +01:00
|
|
|
mod progress_report;
|
2020-06-27 17:31:50 +10:00
|
|
|
mod ssr;
|
2020-02-17 19:03:03 +01:00
|
|
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
2020-07-16 18:13:43 +02:00
|
|
|
use ra_ide::Analysis;
|
2020-08-12 18:26:51 +02:00
|
|
|
use syntax::{AstNode, SourceFile};
|
2020-02-17 19:03:03 +01:00
|
|
|
|
2020-07-30 22:38:24 +02:00
|
|
|
pub use analysis_bench::{BenchCmd, BenchWhat, Position};
|
|
|
|
pub use analysis_stats::AnalysisStatsCmd;
|
2020-04-13 05:44:35 -07:00
|
|
|
pub use diagnostics::diagnostics;
|
2020-04-24 21:57:10 +02:00
|
|
|
pub use load_cargo::load_cargo;
|
2020-06-30 15:55:20 +10:00
|
|
|
pub use ssr::{apply_ssr_rules, search_for_patterns};
|
2020-04-13 05:44:35 -07:00
|
|
|
|
2020-02-17 19:03:03 +01:00
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub enum Verbosity {
|
|
|
|
Spammy,
|
|
|
|
Verbose,
|
|
|
|
Normal,
|
|
|
|
Quiet,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Verbosity {
|
|
|
|
pub fn is_verbose(self) -> bool {
|
2020-06-28 04:02:03 +03:00
|
|
|
matches!(self, Verbosity::Verbose | Verbosity::Spammy)
|
2020-02-17 19:03:03 +01:00
|
|
|
}
|
|
|
|
pub fn is_spammy(self) -> bool {
|
2020-06-28 04:02:03 +03:00
|
|
|
matches!(self, Verbosity::Spammy)
|
2020-02-17 19:03:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse(no_dump: bool) -> Result<()> {
|
2020-08-12 16:32:36 +02:00
|
|
|
let _p = profile::span("parsing");
|
2020-02-17 19:03:03 +01:00
|
|
|
let file = file()?;
|
|
|
|
if !no_dump {
|
|
|
|
println!("{:#?}", file.syntax());
|
|
|
|
}
|
|
|
|
std::mem::forget(file);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn symbols() -> Result<()> {
|
2020-07-16 18:13:43 +02:00
|
|
|
let text = read_stdin()?;
|
|
|
|
let (analysis, file_id) = Analysis::from_single_file(text);
|
|
|
|
let structure = analysis.file_structure(file_id).unwrap();
|
|
|
|
for s in structure {
|
2020-02-17 19:03:03 +01:00
|
|
|
println!("{:?}", s);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
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 file() -> Result<SourceFile> {
|
|
|
|
let text = read_stdin()?;
|
|
|
|
Ok(SourceFile::parse(&text).tree())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_stdin() -> Result<String> {
|
|
|
|
let mut buff = String::new();
|
|
|
|
std::io::stdin().read_to_string(&mut buff)?;
|
|
|
|
Ok(buff)
|
|
|
|
}
|
2020-07-25 10:35:45 +02:00
|
|
|
|
|
|
|
fn report_metric(metric: &str, value: u64, unit: &str) {
|
|
|
|
if std::env::var("RA_METRICS").is_err() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
println!("METRIC:{}:{}:{}", metric, value, unit)
|
|
|
|
}
|