mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-01 09:33:26 +00:00
Cleanup
This commit is contained in:
parent
06e37b273e
commit
8e86d12771
@ -1,11 +1,6 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
time::Instant,
|
||||
};
|
||||
use std::{path::Path, sync::Arc, time::Instant};
|
||||
|
||||
use ra_db::{
|
||||
salsa::{Database, Durability},
|
||||
@ -13,35 +8,9 @@ use ra_db::{
|
||||
};
|
||||
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
|
||||
|
||||
use crate::{load_cargo::load_cargo, Result, Verbosity};
|
||||
use crate::{load_cargo::load_cargo, BenchWhat, Result, Verbosity};
|
||||
|
||||
pub(crate) struct Position {
|
||||
path: PathBuf,
|
||||
line: u32,
|
||||
column: u32,
|
||||
}
|
||||
|
||||
impl FromStr for Position {
|
||||
type Err = Box<dyn std::error::Error + Send + Sync>;
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
let (path_line, column) = rsplit_at_char(s, ':')?;
|
||||
let (path, line) = rsplit_at_char(path_line, ':')?;
|
||||
Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? })
|
||||
}
|
||||
}
|
||||
|
||||
fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
|
||||
let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?;
|
||||
Ok((&s[..idx], &s[idx + 1..]))
|
||||
}
|
||||
|
||||
pub(crate) enum Op {
|
||||
Highlight { path: PathBuf },
|
||||
Complete(Position),
|
||||
GotoDef(Position),
|
||||
}
|
||||
|
||||
pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> {
|
||||
pub(crate) fn run(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Result<()> {
|
||||
ra_prof::init();
|
||||
|
||||
let start = Instant::now();
|
||||
@ -51,9 +20,9 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> {
|
||||
eprintln!("{:?}\n", start.elapsed());
|
||||
|
||||
let file_id = {
|
||||
let path = match &op {
|
||||
Op::Highlight { path } => path,
|
||||
Op::Complete(pos) | Op::GotoDef(pos) => &pos.path,
|
||||
let path = match &what {
|
||||
BenchWhat::Highlight { path } => path,
|
||||
BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path,
|
||||
};
|
||||
let path = std::env::current_dir()?.join(path).canonicalize()?;
|
||||
roots
|
||||
@ -73,8 +42,8 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> {
|
||||
.ok_or_else(|| format!("Can't find {:?}", path))?
|
||||
};
|
||||
|
||||
match &op {
|
||||
Op::Highlight { .. } => {
|
||||
match &what {
|
||||
BenchWhat::Highlight { .. } => {
|
||||
let res = do_work(&mut host, file_id, |analysis| {
|
||||
analysis.diagnostics(file_id).unwrap();
|
||||
analysis.highlight_as_html(file_id, false).unwrap()
|
||||
@ -83,9 +52,9 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> {
|
||||
println!("\n{}", res);
|
||||
}
|
||||
}
|
||||
Op::Complete(pos) | Op::GotoDef(pos) => {
|
||||
let is_completion = match op {
|
||||
Op::Complete(..) => true,
|
||||
BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => {
|
||||
let is_completion = match what {
|
||||
BenchWhat::Complete(..) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@ mod analysis_stats;
|
||||
mod analysis_bench;
|
||||
mod progress_report;
|
||||
|
||||
use std::{error::Error, fmt::Write, io::Read, path::PathBuf};
|
||||
use std::{error::Error, fmt::Write, io::Read, path::PathBuf, str::FromStr};
|
||||
|
||||
use pico_args::Arguments;
|
||||
use ra_ide::{file_structure, Analysis};
|
||||
@ -51,14 +51,37 @@ fn main() -> Result<()> {
|
||||
randomize,
|
||||
)?;
|
||||
}
|
||||
Command::Bench { verbosity, path, op } => {
|
||||
analysis_bench::run(verbosity, path.as_ref(), op)?;
|
||||
Command::Bench { verbosity, path, what } => {
|
||||
analysis_bench::run(verbosity, path.as_ref(), what)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
enum Command {
|
||||
Parse {
|
||||
no_dump: bool,
|
||||
},
|
||||
Symbols,
|
||||
Highlight {
|
||||
rainbow: bool,
|
||||
},
|
||||
Stats {
|
||||
verbosity: Verbosity,
|
||||
randomize: bool,
|
||||
memory_usage: bool,
|
||||
only: Option<String>,
|
||||
with_deps: bool,
|
||||
path: PathBuf,
|
||||
},
|
||||
Bench {
|
||||
verbosity: Verbosity,
|
||||
path: PathBuf,
|
||||
what: BenchWhat,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Verbosity {
|
||||
Spammy,
|
||||
@ -82,27 +105,30 @@ impl Verbosity {
|
||||
}
|
||||
}
|
||||
|
||||
enum Command {
|
||||
Parse {
|
||||
no_dump: bool,
|
||||
},
|
||||
Symbols,
|
||||
Highlight {
|
||||
rainbow: bool,
|
||||
},
|
||||
Stats {
|
||||
verbosity: Verbosity,
|
||||
randomize: bool,
|
||||
memory_usage: bool,
|
||||
only: Option<String>,
|
||||
with_deps: bool,
|
||||
path: PathBuf,
|
||||
},
|
||||
Bench {
|
||||
verbosity: Verbosity,
|
||||
path: PathBuf,
|
||||
op: analysis_bench::Op,
|
||||
},
|
||||
enum BenchWhat {
|
||||
Highlight { path: PathBuf },
|
||||
Complete(Position),
|
||||
GotoDef(Position),
|
||||
}
|
||||
|
||||
pub(crate) struct Position {
|
||||
path: PathBuf,
|
||||
line: u32,
|
||||
column: u32,
|
||||
}
|
||||
|
||||
impl FromStr for Position {
|
||||
type Err = Box<dyn std::error::Error + Send + Sync>;
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
let (path_line, column) = rsplit_at_char(s, ':')?;
|
||||
let (path, line) = rsplit_at_char(path_line, ':')?;
|
||||
Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? })
|
||||
}
|
||||
}
|
||||
|
||||
fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
|
||||
let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?;
|
||||
Ok((&s[..idx], &s[idx + 1..]))
|
||||
}
|
||||
|
||||
struct HelpPrinted;
|
||||
@ -248,17 +274,17 @@ ARGS:
|
||||
|
||||
let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default();
|
||||
let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?;
|
||||
let complete_path: Option<String> = matches.opt_value_from_str("--complete")?;
|
||||
let goto_def_path: Option<String> = matches.opt_value_from_str("--goto-def")?;
|
||||
let op = match (highlight_path, complete_path, goto_def_path) {
|
||||
(Some(path), None, None) => analysis_bench::Op::Highlight { path: path.into() },
|
||||
(None, Some(position), None) => analysis_bench::Op::Complete(position.parse()?),
|
||||
(None, None, Some(position)) => analysis_bench::Op::GotoDef(position.parse()?),
|
||||
let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?;
|
||||
let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?;
|
||||
let what = match (highlight_path, complete_path, goto_def_path) {
|
||||
(Some(path), None, None) => BenchWhat::Highlight { path: path.into() },
|
||||
(None, Some(position), None) => BenchWhat::Complete(position),
|
||||
(None, None, Some(position)) => BenchWhat::GotoDef(position),
|
||||
_ => panic!(
|
||||
"exactly one of `--highlight`, `--complete` or `--goto-def` must be set"
|
||||
),
|
||||
};
|
||||
Command::Bench { verbosity, path, op }
|
||||
Command::Bench { verbosity, path, what }
|
||||
}
|
||||
_ => {
|
||||
eprintln!(
|
||||
|
Loading…
Reference in New Issue
Block a user