3196: Cleanup imports r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-02-17 16:33:37 +00:00 committed by GitHub
commit 0abb7c27ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 124 additions and 143 deletions

22
Cargo.lock generated
View file

@ -917,21 +917,6 @@ dependencies = [
"test_utils",
]
[[package]]
name = "ra_batch"
version = "0.1.0"
dependencies = [
"crossbeam-channel",
"log",
"ra_db",
"ra_hir",
"ra_ide",
"ra_project_model",
"ra_vfs",
"ra_vfs_glob",
"rustc-hash",
]
[[package]]
name = "ra_cargo_watch"
version = "0.1.0"
@ -960,18 +945,23 @@ dependencies = [
name = "ra_cli"
version = "0.1.0"
dependencies = [
"crossbeam-channel",
"env_logger",
"itertools",
"log",
"pico-args",
"ra_batch",
"ra_db",
"ra_hir",
"ra_hir_def",
"ra_hir_ty",
"ra_ide",
"ra_prof",
"ra_project_model",
"ra_syntax",
"ra_vfs",
"ra_vfs_glob",
"rand",
"rustc-hash",
]
[[package]]

View file

@ -1,20 +0,0 @@
[package]
edition = "2018"
name = "ra_batch"
version = "0.1.0"
authors = ["rust-analyzer developers"]
[lib]
doctest = false
[dependencies]
log = "0.4.5"
rustc-hash = "1.0"
crossbeam-channel = "0.4.0"
ra_vfs = "0.5.0"
ra_vfs_glob = { path = "../ra_vfs_glob" }
ra_db = { path = "../ra_db" }
ra_ide = { path = "../ra_ide" }
ra_hir = { path = "../ra_hir" }
ra_project_model = { path = "../ra_project_model" }

View file

@ -6,18 +6,23 @@ authors = ["rust-analyzer developers"]
publish = false
[dependencies]
itertools = "0.8.0"
pico-args = "0.3.0"
crossbeam-channel = "0.4.0"
env_logger = { version = "0.7.1", default-features = false }
itertools = "0.8.0"
log = "0.4.5"
pico-args = "0.3.0"
rand = { version = "0.7.0", features = ["small_rng"] }
rustc-hash = "1.0"
ra_syntax = { path = "../ra_syntax" }
ra_ide = { path = "../ra_ide" }
ra_batch = { path = "../ra_batch" }
hir = { path = "../ra_hir", package = "ra_hir" }
hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" }
hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" }
ra_db = { path = "../ra_db" }
ra_ide = { path = "../ra_ide" }
ra_project_model = { path = "../ra_project_model" }
ra_syntax = { path = "../ra_syntax" }
ra_vfs = "0.5.0"
ra_vfs_glob = { path = "../ra_vfs_glob" }
[dependencies.ra_prof]
path = "../ra_prof"

View file

@ -13,7 +13,7 @@ use ra_db::{
};
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
use crate::Result;
use crate::{load_cargo::load_cargo, Result};
pub(crate) struct Position {
path: PathBuf,
@ -46,7 +46,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
let start = Instant::now();
eprint!("loading: ");
let (mut host, roots) = ra_batch::load_cargo(path)?;
let (mut host, roots) = load_cargo(path)?;
let db = host.raw_database();
eprintln!("{:?}\n", start.elapsed());

View file

@ -2,19 +2,18 @@
use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
use itertools::Itertools;
use rand::{seq::SliceRandom, thread_rng};
use hir::{
db::{DefDatabase, HirDatabase},
AssocItem, Crate, HasSource, HirDisplay, ModuleDef,
};
use hir_def::FunctionId;
use hir_ty::{Ty, TypeWalk};
use itertools::Itertools;
use ra_db::SourceDatabaseExt;
use ra_syntax::AstNode;
use rand::{seq::SliceRandom, thread_rng};
use crate::{progress_report::ProgressReport, Result, Verbosity};
use crate::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity};
pub fn run(
verbosity: Verbosity,
@ -25,7 +24,7 @@ pub fn run(
randomize: bool,
) -> Result<()> {
let db_load_time = Instant::now();
let (mut host, roots) = ra_batch::load_cargo(path)?;
let (mut host, roots) = load_cargo(path)?;
let db = host.raw_database();
println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
let analysis_time = Instant::now();

View file

@ -1,75 +0,0 @@
//! FIXME: write short doc here
pub const GLOBAL_HELP: &str = "ra-cli
USAGE:
ra_cli <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
SUBCOMMANDS:
analysis-bench
analysis-stats
highlight
parse
symbols";
pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench
USAGE:
ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
-v, --verbose
OPTIONS:
--complete <PATH:LINE:COLUMN> Compute completions at this location
--highlight <PATH> Hightlight this file
ARGS:
<PATH> Project to analyse";
pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats
USAGE:
ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
--memory-usage
-v, --verbose
-q, --quiet
OPTIONS:
-o <ONLY>
ARGS:
<PATH>";
pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help information
-r, --rainbow";
pub const SYMBOLS_HELP: &str = "ra-cli-symbols
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help inforamtion";
pub const PARSE_HELP: &str = "ra-cli-parse
USAGE:
ra_cli parse [FLAGS]
FLAGS:
-h, --help Prints help inforamtion
--no-dump";

View file

@ -139,7 +139,8 @@ pub fn load(
#[cfg(test)]
mod tests {
use super::*;
use ra_hir::Crate;
use hir::Crate;
#[test]
fn test_loading_rust_analyzer() {

View file

@ -1,8 +1,8 @@
//! FIXME: write short doc here
mod load_cargo;
mod analysis_stats;
mod analysis_bench;
mod help;
mod progress_report;
use std::{error::Error, fmt::Write, io::Read};
@ -40,21 +40,26 @@ impl Verbosity {
fn main() -> Result<()> {
env_logger::try_init()?;
let subcommand = match std::env::args_os().nth(1) {
None => {
eprintln!("{}", help::GLOBAL_HELP);
return Ok(());
}
Some(s) => s,
};
let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect());
let mut matches = Arguments::from_env();
let subcommand = matches.subcommand()?.unwrap_or_default();
match &*subcommand.to_string_lossy() {
match subcommand.as_str() {
"parse" => {
if matches.contains(["-h", "--help"]) {
eprintln!("{}", help::PARSE_HELP);
eprintln!(
"\
ra-cli-parse
USAGE:
ra_cli parse [FLAGS]
FLAGS:
-h, --help Prints help inforamtion
--no-dump"
);
return Ok(());
}
let no_dump = matches.contains("--no-dump");
matches.finish().or_else(handle_extra_flags)?;
@ -67,10 +72,21 @@ fn main() -> Result<()> {
}
"symbols" => {
if matches.contains(["-h", "--help"]) {
eprintln!("{}", help::SYMBOLS_HELP);
eprintln!(
"\
ra-cli-symbols
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help inforamtion"
);
return Ok(());
}
matches.finish().or_else(handle_extra_flags)?;
let file = file()?;
for s in file_structure(&file) {
println!("{:?}", s);
@ -78,20 +94,51 @@ fn main() -> Result<()> {
}
"highlight" => {
if matches.contains(["-h", "--help"]) {
eprintln!("{}", help::HIGHLIGHT_HELP);
eprintln!(
"\
ra-cli-highlight
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help information
-r, --rainbow"
);
return Ok(());
}
let rainbow_opt = matches.contains(["-r", "--rainbow"]);
matches.finish().or_else(handle_extra_flags)?;
let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap();
println!("{}", html);
}
"analysis-stats" => {
if matches.contains(["-h", "--help"]) {
eprintln!("{}", help::ANALYSIS_STATS_HELP);
eprintln!(
"\
ra-cli-analysis-stats
USAGE:
ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
--memory-usage
-v, --verbose
-q, --quiet
OPTIONS:
-o <ONLY>
ARGS:
<PATH>"
);
return Ok(());
}
let verbosity = match (
matches.contains(["-vv", "--spammy"]),
matches.contains(["-v", "--verbose"]),
@ -111,11 +158,11 @@ fn main() -> Result<()> {
let path = {
let mut trailing = matches.free()?;
if trailing.len() != 1 {
eprintln!("{}", help::ANALYSIS_STATS_HELP);
Err("Invalid flags")?;
}
trailing.pop().unwrap()
};
analysis_stats::run(
verbosity,
memory_usage,
@ -127,9 +174,27 @@ fn main() -> Result<()> {
}
"analysis-bench" => {
if matches.contains(["-h", "--help"]) {
eprintln!("{}", help::ANALYSIS_BENCH_HELP);
eprintln!(
"\
ra_cli-analysis-bench
USAGE:
ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
-v, --verbose
OPTIONS:
--complete <PATH:LINE:COLUMN> Compute completions at this location
--highlight <PATH> Hightlight this file
ARGS:
<PATH> Project to analyse"
);
return Ok(());
}
let verbose = matches.contains(["-v", "--verbose"]);
let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default();
let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?;
@ -144,9 +209,26 @@ fn main() -> Result<()> {
),
};
matches.finish().or_else(handle_extra_flags)?;
analysis_bench::run(verbose, path.as_ref(), op)?;
}
_ => eprintln!("{}", help::GLOBAL_HELP),
_ => eprintln!(
"\
ra-cli
USAGE:
ra_cli <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
SUBCOMMANDS:
analysis-bench
analysis-stats
highlight
parse
symbols"
),
}
Ok(())
}

View file

@ -73,7 +73,6 @@ fn no_docs_comments() {
}
let whitelist = [
"ra_batch",
"ra_cli",
"ra_db",
"ra_hir",