mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Add with-proc-macro in bench ,stats and diagnositcs
This commit is contained in:
parent
aa887d7ab4
commit
22e33f308a
6 changed files with 49 additions and 13 deletions
|
@ -29,15 +29,18 @@ pub(crate) enum Command {
|
||||||
with_deps: bool,
|
with_deps: bool,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
load_output_dirs: bool,
|
load_output_dirs: bool,
|
||||||
|
with_proc_macro: bool,
|
||||||
},
|
},
|
||||||
Bench {
|
Bench {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
what: BenchWhat,
|
what: BenchWhat,
|
||||||
load_output_dirs: bool,
|
load_output_dirs: bool,
|
||||||
|
with_proc_macro: bool,
|
||||||
},
|
},
|
||||||
Diagnostics {
|
Diagnostics {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
load_output_dirs: bool,
|
load_output_dirs: bool,
|
||||||
|
with_proc_macro: bool,
|
||||||
/// Include files which are not modules. In rust-analyzer
|
/// Include files which are not modules. In rust-analyzer
|
||||||
/// this would include the parser test files.
|
/// this would include the parser test files.
|
||||||
all: bool,
|
all: bool,
|
||||||
|
@ -148,6 +151,7 @@ FLAGS:
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
--memory-usage
|
--memory-usage
|
||||||
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
|
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
|
||||||
|
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
|
||||||
-v, --verbose
|
-v, --verbose
|
||||||
-q, --quiet
|
-q, --quiet
|
||||||
|
|
||||||
|
@ -165,6 +169,7 @@ ARGS:
|
||||||
let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?;
|
let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?;
|
||||||
let with_deps: bool = matches.contains("--with-deps");
|
let with_deps: bool = matches.contains("--with-deps");
|
||||||
let load_output_dirs = matches.contains("--load-output-dirs");
|
let load_output_dirs = matches.contains("--load-output-dirs");
|
||||||
|
let with_proc_macro = matches.contains("--with-proc-macro");
|
||||||
let path = {
|
let path = {
|
||||||
let mut trailing = matches.free()?;
|
let mut trailing = matches.free()?;
|
||||||
if trailing.len() != 1 {
|
if trailing.len() != 1 {
|
||||||
|
@ -173,7 +178,15 @@ ARGS:
|
||||||
trailing.pop().unwrap().into()
|
trailing.pop().unwrap().into()
|
||||||
};
|
};
|
||||||
|
|
||||||
Command::Stats { randomize, memory_usage, only, with_deps, path, load_output_dirs }
|
Command::Stats {
|
||||||
|
randomize,
|
||||||
|
memory_usage,
|
||||||
|
only,
|
||||||
|
with_deps,
|
||||||
|
path,
|
||||||
|
load_output_dirs,
|
||||||
|
with_proc_macro,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"analysis-bench" => {
|
"analysis-bench" => {
|
||||||
if matches.contains(["-h", "--help"]) {
|
if matches.contains(["-h", "--help"]) {
|
||||||
|
@ -187,6 +200,7 @@ USAGE:
|
||||||
FLAGS:
|
FLAGS:
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
|
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
|
||||||
|
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
|
||||||
-v, --verbose
|
-v, --verbose
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
|
@ -214,7 +228,8 @@ ARGS:
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
let load_output_dirs = matches.contains("--load-output-dirs");
|
let load_output_dirs = matches.contains("--load-output-dirs");
|
||||||
Command::Bench { path, what, load_output_dirs }
|
let with_proc_macro = matches.contains("--with-proc-macro");
|
||||||
|
Command::Bench { path, what, load_output_dirs, with_proc_macro }
|
||||||
}
|
}
|
||||||
"diagnostics" => {
|
"diagnostics" => {
|
||||||
if matches.contains(["-h", "--help"]) {
|
if matches.contains(["-h", "--help"]) {
|
||||||
|
@ -237,6 +252,7 @@ ARGS:
|
||||||
}
|
}
|
||||||
|
|
||||||
let load_output_dirs = matches.contains("--load-output-dirs");
|
let load_output_dirs = matches.contains("--load-output-dirs");
|
||||||
|
let with_proc_macro = matches.contains("--with-proc-macro");
|
||||||
let all = matches.contains("--all");
|
let all = matches.contains("--all");
|
||||||
let path = {
|
let path = {
|
||||||
let mut trailing = matches.free()?;
|
let mut trailing = matches.free()?;
|
||||||
|
@ -246,7 +262,7 @@ ARGS:
|
||||||
trailing.pop().unwrap().into()
|
trailing.pop().unwrap().into()
|
||||||
};
|
};
|
||||||
|
|
||||||
Command::Diagnostics { path, load_output_dirs, all }
|
Command::Diagnostics { path, load_output_dirs, with_proc_macro, all }
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
|
|
@ -25,6 +25,7 @@ fn main() -> Result<()> {
|
||||||
with_deps,
|
with_deps,
|
||||||
path,
|
path,
|
||||||
load_output_dirs,
|
load_output_dirs,
|
||||||
|
with_proc_macro,
|
||||||
} => cli::analysis_stats(
|
} => cli::analysis_stats(
|
||||||
args.verbosity,
|
args.verbosity,
|
||||||
memory_usage,
|
memory_usage,
|
||||||
|
@ -33,14 +34,21 @@ fn main() -> Result<()> {
|
||||||
with_deps,
|
with_deps,
|
||||||
randomize,
|
randomize,
|
||||||
load_output_dirs,
|
load_output_dirs,
|
||||||
|
with_proc_macro,
|
||||||
)?,
|
)?,
|
||||||
|
|
||||||
args::Command::Bench { path, what, load_output_dirs } => {
|
args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => {
|
||||||
cli::analysis_bench(args.verbosity, path.as_ref(), what, load_output_dirs)?
|
cli::analysis_bench(
|
||||||
|
args.verbosity,
|
||||||
|
path.as_ref(),
|
||||||
|
what,
|
||||||
|
load_output_dirs,
|
||||||
|
with_proc_macro,
|
||||||
|
)?
|
||||||
}
|
}
|
||||||
|
|
||||||
args::Command::Diagnostics { path, load_output_dirs, all } => {
|
args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => {
|
||||||
cli::diagnostics(path.as_ref(), load_output_dirs, all)?
|
cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)?
|
||||||
}
|
}
|
||||||
|
|
||||||
args::Command::RunServer => run_server()?,
|
args::Command::RunServer => run_server()?,
|
||||||
|
|
|
@ -47,12 +47,13 @@ pub fn analysis_bench(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
what: BenchWhat,
|
what: BenchWhat,
|
||||||
load_output_dirs: bool,
|
load_output_dirs: bool,
|
||||||
|
with_proc_macro: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
ra_prof::init();
|
ra_prof::init();
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
eprint!("loading: ");
|
eprint!("loading: ");
|
||||||
let (mut host, roots) = load_cargo(path, load_output_dirs)?;
|
let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
|
||||||
let db = host.raw_database();
|
let db = host.raw_database();
|
||||||
eprintln!("{:?}\n", start.elapsed());
|
eprintln!("{:?}\n", start.elapsed());
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,10 @@ pub fn analysis_stats(
|
||||||
with_deps: bool,
|
with_deps: bool,
|
||||||
randomize: bool,
|
randomize: bool,
|
||||||
load_output_dirs: bool,
|
load_output_dirs: bool,
|
||||||
|
with_proc_macro: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let db_load_time = Instant::now();
|
let db_load_time = Instant::now();
|
||||||
let (mut host, roots) = load_cargo(path, load_output_dirs)?;
|
let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
|
||||||
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();
|
||||||
|
|
|
@ -9,8 +9,13 @@ use std::{collections::HashSet, path::Path};
|
||||||
use crate::cli::{load_cargo::load_cargo, Result};
|
use crate::cli::{load_cargo::load_cargo, Result};
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
|
|
||||||
pub fn diagnostics(path: &Path, load_output_dirs: bool, all: bool) -> Result<()> {
|
pub fn diagnostics(
|
||||||
let (host, roots) = load_cargo(path, load_output_dirs)?;
|
path: &Path,
|
||||||
|
load_output_dirs: bool,
|
||||||
|
with_proc_macro: bool,
|
||||||
|
all: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
let (host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
|
||||||
let db = host.raw_database();
|
let db = host.raw_database();
|
||||||
let analysis = host.analysis();
|
let analysis = host.analysis();
|
||||||
let semantics = Semantics::new(db);
|
let semantics = Semantics::new(db);
|
||||||
|
|
|
@ -25,6 +25,7 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
|
||||||
pub(crate) fn load_cargo(
|
pub(crate) fn load_cargo(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
load_out_dirs_from_check: bool,
|
load_out_dirs_from_check: bool,
|
||||||
|
with_proc_macro: bool,
|
||||||
) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> {
|
) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> {
|
||||||
let root = std::env::current_dir()?.join(root);
|
let root = std::env::current_dir()?.join(root);
|
||||||
let ws = ProjectWorkspace::discover(
|
let ws = ProjectWorkspace::discover(
|
||||||
|
@ -69,7 +70,11 @@ pub(crate) fn load_cargo(
|
||||||
})
|
})
|
||||||
.collect::<FxHashMap<_, _>>();
|
.collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
let proc_macro_client = ProcMacroClient::dummy();
|
let proc_macro_client = if with_proc_macro {
|
||||||
|
ProcMacroClient::dummy()
|
||||||
|
} else {
|
||||||
|
ProcMacroClient::extern_process(Path::new("ra_proc_macro_srv")).unwrap()
|
||||||
|
};
|
||||||
let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client);
|
let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client);
|
||||||
Ok((host, source_roots))
|
Ok((host, source_roots))
|
||||||
}
|
}
|
||||||
|
@ -175,7 +180,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_loading_rust_analyzer() {
|
fn test_loading_rust_analyzer() {
|
||||||
let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
|
let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
|
||||||
let (host, _roots) = load_cargo(path, false).unwrap();
|
let (host, _roots) = load_cargo(path, false, false).unwrap();
|
||||||
let n_crates = Crate::all(host.raw_database()).len();
|
let n_crates = Crate::all(host.raw_database()).len();
|
||||||
// RA has quite a few crates, but the exact count doesn't matter
|
// RA has quite a few crates, but the exact count doesn't matter
|
||||||
assert!(n_crates > 20);
|
assert!(n_crates > 20);
|
||||||
|
|
Loading…
Reference in a new issue