Skip to content

Commit 22e33f3

Browse files
committed
Add with-proc-macro in bench ,stats and diagnositcs
1 parent aa887d7 commit 22e33f3

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

crates/rust-analyzer/src/bin/args.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ pub(crate) enum Command {
2929
with_deps: bool,
3030
path: PathBuf,
3131
load_output_dirs: bool,
32+
with_proc_macro: bool,
3233
},
3334
Bench {
3435
path: PathBuf,
3536
what: BenchWhat,
3637
load_output_dirs: bool,
38+
with_proc_macro: bool,
3739
},
3840
Diagnostics {
3941
path: PathBuf,
4042
load_output_dirs: bool,
43+
with_proc_macro: bool,
4144
/// Include files which are not modules. In rust-analyzer
4245
/// this would include the parser test files.
4346
all: bool,
@@ -148,6 +151,7 @@ FLAGS:
148151
-h, --help Prints help information
149152
--memory-usage
150153
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
154+
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
151155
-v, --verbose
152156
-q, --quiet
153157
@@ -165,6 +169,7 @@ ARGS:
165169
let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?;
166170
let with_deps: bool = matches.contains("--with-deps");
167171
let load_output_dirs = matches.contains("--load-output-dirs");
172+
let with_proc_macro = matches.contains("--with-proc-macro");
168173
let path = {
169174
let mut trailing = matches.free()?;
170175
if trailing.len() != 1 {
@@ -173,7 +178,15 @@ ARGS:
173178
trailing.pop().unwrap().into()
174179
};
175180

176-
Command::Stats { randomize, memory_usage, only, with_deps, path, load_output_dirs }
181+
Command::Stats {
182+
randomize,
183+
memory_usage,
184+
only,
185+
with_deps,
186+
path,
187+
load_output_dirs,
188+
with_proc_macro,
189+
}
177190
}
178191
"analysis-bench" => {
179192
if matches.contains(["-h", "--help"]) {
@@ -187,6 +200,7 @@ USAGE:
187200
FLAGS:
188201
-h, --help Prints help information
189202
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
203+
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
190204
-v, --verbose
191205
192206
OPTIONS:
@@ -214,7 +228,8 @@ ARGS:
214228
),
215229
};
216230
let load_output_dirs = matches.contains("--load-output-dirs");
217-
Command::Bench { path, what, load_output_dirs }
231+
let with_proc_macro = matches.contains("--with-proc-macro");
232+
Command::Bench { path, what, load_output_dirs, with_proc_macro }
218233
}
219234
"diagnostics" => {
220235
if matches.contains(["-h", "--help"]) {
@@ -237,6 +252,7 @@ ARGS:
237252
}
238253

239254
let load_output_dirs = matches.contains("--load-output-dirs");
255+
let with_proc_macro = matches.contains("--with-proc-macro");
240256
let all = matches.contains("--all");
241257
let path = {
242258
let mut trailing = matches.free()?;
@@ -246,7 +262,7 @@ ARGS:
246262
trailing.pop().unwrap().into()
247263
};
248264

249-
Command::Diagnostics { path, load_output_dirs, all }
265+
Command::Diagnostics { path, load_output_dirs, with_proc_macro, all }
250266
}
251267
_ => {
252268
eprintln!(

crates/rust-analyzer/src/bin/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn main() -> Result<()> {
2525
with_deps,
2626
path,
2727
load_output_dirs,
28+
with_proc_macro,
2829
} => cli::analysis_stats(
2930
args.verbosity,
3031
memory_usage,
@@ -33,14 +34,21 @@ fn main() -> Result<()> {
3334
with_deps,
3435
randomize,
3536
load_output_dirs,
37+
with_proc_macro,
3638
)?,
3739

38-
args::Command::Bench { path, what, load_output_dirs } => {
39-
cli::analysis_bench(args.verbosity, path.as_ref(), what, load_output_dirs)?
40+
args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => {
41+
cli::analysis_bench(
42+
args.verbosity,
43+
path.as_ref(),
44+
what,
45+
load_output_dirs,
46+
with_proc_macro,
47+
)?
4048
}
4149

42-
args::Command::Diagnostics { path, load_output_dirs, all } => {
43-
cli::diagnostics(path.as_ref(), load_output_dirs, all)?
50+
args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => {
51+
cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)?
4452
}
4553

4654
args::Command::RunServer => run_server()?,

crates/rust-analyzer/src/cli/analysis_bench.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ pub fn analysis_bench(
4747
path: &Path,
4848
what: BenchWhat,
4949
load_output_dirs: bool,
50+
with_proc_macro: bool,
5051
) -> Result<()> {
5152
ra_prof::init();
5253

5354
let start = Instant::now();
5455
eprint!("loading: ");
55-
let (mut host, roots) = load_cargo(path, load_output_dirs)?;
56+
let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
5657
let db = host.raw_database();
5758
eprintln!("{:?}\n", start.elapsed());
5859

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ pub fn analysis_stats(
2525
with_deps: bool,
2626
randomize: bool,
2727
load_output_dirs: bool,
28+
with_proc_macro: bool,
2829
) -> Result<()> {
2930
let db_load_time = Instant::now();
30-
let (mut host, roots) = load_cargo(path, load_output_dirs)?;
31+
let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
3132
let db = host.raw_database();
3233
println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
3334
let analysis_time = Instant::now();

crates/rust-analyzer/src/cli/diagnostics.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ use std::{collections::HashSet, path::Path};
99
use crate::cli::{load_cargo::load_cargo, Result};
1010
use hir::Semantics;
1111

12-
pub fn diagnostics(path: &Path, load_output_dirs: bool, all: bool) -> Result<()> {
13-
let (host, roots) = load_cargo(path, load_output_dirs)?;
12+
pub fn diagnostics(
13+
path: &Path,
14+
load_output_dirs: bool,
15+
with_proc_macro: bool,
16+
all: bool,
17+
) -> Result<()> {
18+
let (host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
1419
let db = host.raw_database();
1520
let analysis = host.analysis();
1621
let semantics = Semantics::new(db);

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
2525
pub(crate) fn load_cargo(
2626
root: &Path,
2727
load_out_dirs_from_check: bool,
28+
with_proc_macro: bool,
2829
) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> {
2930
let root = std::env::current_dir()?.join(root);
3031
let ws = ProjectWorkspace::discover(
@@ -69,7 +70,11 @@ pub(crate) fn load_cargo(
6970
})
7071
.collect::<FxHashMap<_, _>>();
7172

72-
let proc_macro_client = ProcMacroClient::dummy();
73+
let proc_macro_client = if with_proc_macro {
74+
ProcMacroClient::dummy()
75+
} else {
76+
ProcMacroClient::extern_process(Path::new("ra_proc_macro_srv")).unwrap()
77+
};
7378
let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client);
7479
Ok((host, source_roots))
7580
}
@@ -175,7 +180,7 @@ mod tests {
175180
#[test]
176181
fn test_loading_rust_analyzer() {
177182
let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
178-
let (host, _roots) = load_cargo(path, false).unwrap();
183+
let (host, _roots) = load_cargo(path, false, false).unwrap();
179184
let n_crates = Crate::all(host.raw_database()).len();
180185
// RA has quite a few crates, but the exact count doesn't matter
181186
assert!(n_crates > 20);

0 commit comments

Comments
 (0)