mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Merge #3196
3196: Cleanup imports r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
0abb7c27ac
9 changed files with 124 additions and 143 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -917,21 +917,6 @@ dependencies = [
|
||||||
"test_utils",
|
"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]]
|
[[package]]
|
||||||
name = "ra_cargo_watch"
|
name = "ra_cargo_watch"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -960,18 +945,23 @@ dependencies = [
|
||||||
name = "ra_cli"
|
name = "ra_cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"crossbeam-channel",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
"log",
|
||||||
"pico-args",
|
"pico-args",
|
||||||
"ra_batch",
|
|
||||||
"ra_db",
|
"ra_db",
|
||||||
"ra_hir",
|
"ra_hir",
|
||||||
"ra_hir_def",
|
"ra_hir_def",
|
||||||
"ra_hir_ty",
|
"ra_hir_ty",
|
||||||
"ra_ide",
|
"ra_ide",
|
||||||
"ra_prof",
|
"ra_prof",
|
||||||
|
"ra_project_model",
|
||||||
"ra_syntax",
|
"ra_syntax",
|
||||||
|
"ra_vfs",
|
||||||
|
"ra_vfs_glob",
|
||||||
"rand",
|
"rand",
|
||||||
|
"rustc-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -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" }
|
|
|
@ -6,18 +6,23 @@ authors = ["rust-analyzer developers"]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
itertools = "0.8.0"
|
crossbeam-channel = "0.4.0"
|
||||||
pico-args = "0.3.0"
|
|
||||||
env_logger = { version = "0.7.1", default-features = false }
|
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"] }
|
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 = { 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_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_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]
|
[dependencies.ra_prof]
|
||||||
path = "../ra_prof"
|
path = "../ra_prof"
|
||||||
|
|
|
@ -13,7 +13,7 @@ use ra_db::{
|
||||||
};
|
};
|
||||||
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
|
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
|
||||||
|
|
||||||
use crate::Result;
|
use crate::{load_cargo::load_cargo, Result};
|
||||||
|
|
||||||
pub(crate) struct Position {
|
pub(crate) struct Position {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
@ -46,7 +46,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
eprint!("loading: ");
|
eprint!("loading: ");
|
||||||
let (mut host, roots) = ra_batch::load_cargo(path)?;
|
let (mut host, roots) = load_cargo(path)?;
|
||||||
let db = host.raw_database();
|
let db = host.raw_database();
|
||||||
eprintln!("{:?}\n", start.elapsed());
|
eprintln!("{:?}\n", start.elapsed());
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,18 @@
|
||||||
|
|
||||||
use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
|
use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
|
||||||
|
|
||||||
use itertools::Itertools;
|
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
|
||||||
|
|
||||||
use hir::{
|
use hir::{
|
||||||
db::{DefDatabase, HirDatabase},
|
db::{DefDatabase, HirDatabase},
|
||||||
AssocItem, Crate, HasSource, HirDisplay, ModuleDef,
|
AssocItem, Crate, HasSource, HirDisplay, ModuleDef,
|
||||||
};
|
};
|
||||||
use hir_def::FunctionId;
|
use hir_def::FunctionId;
|
||||||
use hir_ty::{Ty, TypeWalk};
|
use hir_ty::{Ty, TypeWalk};
|
||||||
|
use itertools::Itertools;
|
||||||
use ra_db::SourceDatabaseExt;
|
use ra_db::SourceDatabaseExt;
|
||||||
use ra_syntax::AstNode;
|
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(
|
pub fn run(
|
||||||
verbosity: Verbosity,
|
verbosity: Verbosity,
|
||||||
|
@ -25,7 +24,7 @@ pub fn run(
|
||||||
randomize: bool,
|
randomize: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let db_load_time = Instant::now();
|
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();
|
let db = host.raw_database();
|
||||||
println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
|
println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
|
||||||
let analysis_time = Instant::now();
|
let analysis_time = Instant::now();
|
||||||
|
|
|
@ -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";
|
|
|
@ -139,7 +139,8 @@ pub fn load(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ra_hir::Crate;
|
|
||||||
|
use hir::Crate;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_loading_rust_analyzer() {
|
fn test_loading_rust_analyzer() {
|
|
@ -1,8 +1,8 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
|
mod load_cargo;
|
||||||
mod analysis_stats;
|
mod analysis_stats;
|
||||||
mod analysis_bench;
|
mod analysis_bench;
|
||||||
mod help;
|
|
||||||
mod progress_report;
|
mod progress_report;
|
||||||
|
|
||||||
use std::{error::Error, fmt::Write, io::Read};
|
use std::{error::Error, fmt::Write, io::Read};
|
||||||
|
@ -40,21 +40,26 @@ impl Verbosity {
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
env_logger::try_init()?;
|
env_logger::try_init()?;
|
||||||
|
|
||||||
let subcommand = match std::env::args_os().nth(1) {
|
let mut matches = Arguments::from_env();
|
||||||
None => {
|
let subcommand = matches.subcommand()?.unwrap_or_default();
|
||||||
eprintln!("{}", help::GLOBAL_HELP);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
Some(s) => s,
|
|
||||||
};
|
|
||||||
let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect());
|
|
||||||
|
|
||||||
match &*subcommand.to_string_lossy() {
|
match subcommand.as_str() {
|
||||||
"parse" => {
|
"parse" => {
|
||||||
if matches.contains(["-h", "--help"]) {
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let no_dump = matches.contains("--no-dump");
|
let no_dump = matches.contains("--no-dump");
|
||||||
matches.finish().or_else(handle_extra_flags)?;
|
matches.finish().or_else(handle_extra_flags)?;
|
||||||
|
|
||||||
|
@ -67,10 +72,21 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
"symbols" => {
|
"symbols" => {
|
||||||
if matches.contains(["-h", "--help"]) {
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.finish().or_else(handle_extra_flags)?;
|
matches.finish().or_else(handle_extra_flags)?;
|
||||||
|
|
||||||
let file = file()?;
|
let file = file()?;
|
||||||
for s in file_structure(&file) {
|
for s in file_structure(&file) {
|
||||||
println!("{:?}", s);
|
println!("{:?}", s);
|
||||||
|
@ -78,20 +94,51 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
"highlight" => {
|
"highlight" => {
|
||||||
if matches.contains(["-h", "--help"]) {
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let rainbow_opt = matches.contains(["-r", "--rainbow"]);
|
let rainbow_opt = matches.contains(["-r", "--rainbow"]);
|
||||||
matches.finish().or_else(handle_extra_flags)?;
|
matches.finish().or_else(handle_extra_flags)?;
|
||||||
|
|
||||||
let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
|
let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
|
||||||
let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap();
|
let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap();
|
||||||
println!("{}", html);
|
println!("{}", html);
|
||||||
}
|
}
|
||||||
"analysis-stats" => {
|
"analysis-stats" => {
|
||||||
if matches.contains(["-h", "--help"]) {
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let verbosity = match (
|
let verbosity = match (
|
||||||
matches.contains(["-vv", "--spammy"]),
|
matches.contains(["-vv", "--spammy"]),
|
||||||
matches.contains(["-v", "--verbose"]),
|
matches.contains(["-v", "--verbose"]),
|
||||||
|
@ -111,11 +158,11 @@ fn main() -> Result<()> {
|
||||||
let path = {
|
let path = {
|
||||||
let mut trailing = matches.free()?;
|
let mut trailing = matches.free()?;
|
||||||
if trailing.len() != 1 {
|
if trailing.len() != 1 {
|
||||||
eprintln!("{}", help::ANALYSIS_STATS_HELP);
|
|
||||||
Err("Invalid flags")?;
|
Err("Invalid flags")?;
|
||||||
}
|
}
|
||||||
trailing.pop().unwrap()
|
trailing.pop().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
analysis_stats::run(
|
analysis_stats::run(
|
||||||
verbosity,
|
verbosity,
|
||||||
memory_usage,
|
memory_usage,
|
||||||
|
@ -127,9 +174,27 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
"analysis-bench" => {
|
"analysis-bench" => {
|
||||||
if matches.contains(["-h", "--help"]) {
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let verbose = matches.contains(["-v", "--verbose"]);
|
let verbose = matches.contains(["-v", "--verbose"]);
|
||||||
let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default();
|
let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default();
|
||||||
let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?;
|
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)?;
|
matches.finish().or_else(handle_extra_flags)?;
|
||||||
|
|
||||||
analysis_bench::run(verbose, path.as_ref(), op)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,6 @@ fn no_docs_comments() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let whitelist = [
|
let whitelist = [
|
||||||
"ra_batch",
|
|
||||||
"ra_cli",
|
"ra_cli",
|
||||||
"ra_db",
|
"ra_db",
|
||||||
"ra_hir",
|
"ra_hir",
|
||||||
|
|
Loading…
Reference in a new issue