diff options
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_bench.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 13 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/diagnostics.rs | 18 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 26 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/ssr.rs | 19 |
5 files changed, 70 insertions, 20 deletions
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index a01b49822..6735b6388 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs | |||
@@ -16,7 +16,10 @@ use ide_db::{ | |||
16 | }; | 16 | }; |
17 | use vfs::AbsPathBuf; | 17 | use vfs::AbsPathBuf; |
18 | 18 | ||
19 | use crate::cli::{load_cargo::load_cargo, print_memory_usage, Verbosity}; | 19 | use crate::cli::{ |
20 | load_cargo::{load_cargo, LoadCargoConfig}, | ||
21 | print_memory_usage, Verbosity, | ||
22 | }; | ||
20 | 23 | ||
21 | pub struct BenchCmd { | 24 | pub struct BenchCmd { |
22 | pub path: PathBuf, | 25 | pub path: PathBuf, |
@@ -59,7 +62,14 @@ impl BenchCmd { | |||
59 | 62 | ||
60 | let start = Instant::now(); | 63 | let start = Instant::now(); |
61 | eprint!("loading: "); | 64 | eprint!("loading: "); |
62 | let (mut host, vfs) = load_cargo(&self.path, self.load_output_dirs, self.with_proc_macro)?; | 65 | |
66 | let load_cargo_config = LoadCargoConfig { | ||
67 | cargo_config: Default::default(), | ||
68 | load_out_dirs_from_check: self.load_output_dirs, | ||
69 | with_proc_macro: self.with_proc_macro, | ||
70 | }; | ||
71 | |||
72 | let (mut host, vfs) = load_cargo(&self.path, &load_cargo_config)?; | ||
63 | eprintln!("{:?}\n", start.elapsed()); | 73 | eprintln!("{:?}\n", start.elapsed()); |
64 | 74 | ||
65 | let file_id = { | 75 | let file_id = { |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 66416f709..3417af687 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -25,8 +25,10 @@ use stdx::format_to; | |||
25 | use syntax::AstNode; | 25 | use syntax::AstNode; |
26 | 26 | ||
27 | use crate::cli::{ | 27 | use crate::cli::{ |
28 | load_cargo::load_cargo, print_memory_usage, progress_report::ProgressReport, report_metric, | 28 | load_cargo::{load_cargo, LoadCargoConfig}, |
29 | Result, Verbosity, | 29 | print_memory_usage, |
30 | progress_report::ProgressReport, | ||
31 | report_metric, Result, Verbosity, | ||
30 | }; | 32 | }; |
31 | use profile::StopWatch; | 33 | use profile::StopWatch; |
32 | 34 | ||
@@ -57,7 +59,12 @@ impl AnalysisStatsCmd { | |||
57 | }; | 59 | }; |
58 | 60 | ||
59 | let mut db_load_sw = self.stop_watch(); | 61 | let mut db_load_sw = self.stop_watch(); |
60 | let (host, vfs) = load_cargo(&self.path, self.load_output_dirs, self.with_proc_macro)?; | 62 | let load_cargo_config = LoadCargoConfig { |
63 | cargo_config: Default::default(), | ||
64 | load_out_dirs_from_check: self.load_output_dirs, | ||
65 | with_proc_macro: self.with_proc_macro, | ||
66 | }; | ||
67 | let (host, vfs) = load_cargo(&self.path, &load_cargo_config)?; | ||
61 | let db = host.raw_database(); | 68 | let db = host.raw_database(); |
62 | eprintln!("{:<20} {}", "Database loaded:", db_load_sw.elapsed()); | 69 | eprintln!("{:<20} {}", "Database loaded:", db_load_sw.elapsed()); |
63 | 70 | ||
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index 0090fd2c2..c60374c24 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs | |||
@@ -10,7 +10,10 @@ use hir::{db::HirDatabase, Crate, Module}; | |||
10 | use ide::{DiagnosticsConfig, Severity}; | 10 | use ide::{DiagnosticsConfig, Severity}; |
11 | use ide_db::base_db::SourceDatabaseExt; | 11 | use ide_db::base_db::SourceDatabaseExt; |
12 | 12 | ||
13 | use crate::cli::{load_cargo::load_cargo, Result}; | 13 | use crate::cli::{ |
14 | load_cargo::{load_cargo, LoadCargoConfig}, | ||
15 | Result, | ||
16 | }; | ||
14 | 17 | ||
15 | fn all_modules(db: &dyn HirDatabase) -> Vec<Module> { | 18 | fn all_modules(db: &dyn HirDatabase) -> Vec<Module> { |
16 | let mut worklist: Vec<_> = | 19 | let mut worklist: Vec<_> = |
@@ -25,8 +28,17 @@ fn all_modules(db: &dyn HirDatabase) -> Vec<Module> { | |||
25 | modules | 28 | modules |
26 | } | 29 | } |
27 | 30 | ||
28 | pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> { | 31 | pub fn diagnostics( |
29 | let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; | 32 | path: &Path, |
33 | load_out_dirs_from_check: bool, | ||
34 | with_proc_macro: bool, | ||
35 | ) -> Result<()> { | ||
36 | let load_cargo_config = LoadCargoConfig { | ||
37 | cargo_config: Default::default(), | ||
38 | load_out_dirs_from_check, | ||
39 | with_proc_macro, | ||
40 | }; | ||
41 | let (host, _vfs) = load_cargo(path, &load_cargo_config)?; | ||
30 | let db = host.raw_database(); | 42 | let db = host.raw_database(); |
31 | let analysis = host.analysis(); | 43 | let analysis = host.analysis(); |
32 | 44 | ||
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index e12e87180..cc63c6cc2 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -13,14 +13,16 @@ use vfs::{loader::Handle, AbsPath, AbsPathBuf}; | |||
13 | 13 | ||
14 | use crate::reload::{ProjectFolders, SourceRootConfig}; | 14 | use crate::reload::{ProjectFolders, SourceRootConfig}; |
15 | 15 | ||
16 | pub fn load_cargo( | 16 | pub struct LoadCargoConfig { |
17 | root: &Path, | 17 | pub cargo_config: CargoConfig, |
18 | load_out_dirs_from_check: bool, | 18 | pub load_out_dirs_from_check: bool, |
19 | with_proc_macro: bool, | 19 | pub with_proc_macro: bool, |
20 | ) -> Result<(AnalysisHost, vfs::Vfs)> { | 20 | } |
21 | |||
22 | pub fn load_cargo(root: &Path, config: &LoadCargoConfig) -> Result<(AnalysisHost, vfs::Vfs)> { | ||
21 | let root = AbsPathBuf::assert(std::env::current_dir()?.join(root)); | 23 | let root = AbsPathBuf::assert(std::env::current_dir()?.join(root)); |
22 | let root = ProjectManifest::discover_single(&root)?; | 24 | let root = ProjectManifest::discover_single(&root)?; |
23 | let ws = ProjectWorkspace::load(root, &CargoConfig::default(), &|_| {})?; | 25 | let ws = ProjectWorkspace::load(root, &config.cargo_config, &|_| {})?; |
24 | 26 | ||
25 | let (sender, receiver) = unbounded(); | 27 | let (sender, receiver) = unbounded(); |
26 | let mut vfs = vfs::Vfs::default(); | 28 | let mut vfs = vfs::Vfs::default(); |
@@ -30,14 +32,14 @@ pub fn load_cargo( | |||
30 | Box::new(loader) | 32 | Box::new(loader) |
31 | }; | 33 | }; |
32 | 34 | ||
33 | let proc_macro_client = if with_proc_macro { | 35 | let proc_macro_client = if config.with_proc_macro { |
34 | let path = std::env::current_exe()?; | 36 | let path = std::env::current_exe()?; |
35 | Some(ProcMacroClient::extern_process(path, &["proc-macro"]).unwrap()) | 37 | Some(ProcMacroClient::extern_process(path, &["proc-macro"]).unwrap()) |
36 | } else { | 38 | } else { |
37 | None | 39 | None |
38 | }; | 40 | }; |
39 | 41 | ||
40 | let build_data = if load_out_dirs_from_check { | 42 | let build_data = if config.load_out_dirs_from_check { |
41 | let mut collector = BuildDataCollector::default(); | 43 | let mut collector = BuildDataCollector::default(); |
42 | ws.collect_build_data_configs(&mut collector); | 44 | ws.collect_build_data_configs(&mut collector); |
43 | Some(collector.collect(&|_| {})?) | 45 | Some(collector.collect(&|_| {})?) |
@@ -116,7 +118,13 @@ mod tests { | |||
116 | #[test] | 118 | #[test] |
117 | fn test_loading_rust_analyzer() { | 119 | fn test_loading_rust_analyzer() { |
118 | let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); | 120 | let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); |
119 | let (host, _vfs) = load_cargo(path, false, false).unwrap(); | 121 | let load_cargo_config = LoadCargoConfig { |
122 | cargo_config: Default::default(), | ||
123 | load_out_dirs_from_check: false, | ||
124 | with_proc_macro: false, | ||
125 | }; | ||
126 | |||
127 | let (host, _vfs) = load_cargo(path, &load_cargo_config).unwrap(); | ||
120 | let n_crates = Crate::all(host.raw_database()).len(); | 128 | let n_crates = Crate::all(host.raw_database()).len(); |
121 | // RA has quite a few crates, but the exact count doesn't matter | 129 | // RA has quite a few crates, but the exact count doesn't matter |
122 | assert!(n_crates > 20); | 130 | assert!(n_crates > 20); |
diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs index bbb550ec9..8729ff0d9 100644 --- a/crates/rust-analyzer/src/cli/ssr.rs +++ b/crates/rust-analyzer/src/cli/ssr.rs | |||
@@ -1,11 +1,19 @@ | |||
1 | //! Applies structured search replace rules from the command line. | 1 | //! Applies structured search replace rules from the command line. |
2 | 2 | ||
3 | use crate::cli::{load_cargo::load_cargo, Result}; | 3 | use crate::cli::{ |
4 | load_cargo::{load_cargo, LoadCargoConfig}, | ||
5 | Result, | ||
6 | }; | ||
4 | use ssr::{MatchFinder, SsrPattern, SsrRule}; | 7 | use ssr::{MatchFinder, SsrPattern, SsrRule}; |
5 | 8 | ||
6 | pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { | 9 | pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { |
7 | use ide_db::base_db::SourceDatabaseExt; | 10 | use ide_db::base_db::SourceDatabaseExt; |
8 | let (host, vfs) = load_cargo(&std::env::current_dir()?, true, true)?; | 11 | let load_cargo_config = LoadCargoConfig { |
12 | cargo_config: Default::default(), | ||
13 | load_out_dirs_from_check: true, | ||
14 | with_proc_macro: true, | ||
15 | }; | ||
16 | let (host, vfs) = load_cargo(&std::env::current_dir()?, &load_cargo_config)?; | ||
9 | let db = host.raw_database(); | 17 | let db = host.raw_database(); |
10 | let mut match_finder = MatchFinder::at_first_file(db)?; | 18 | let mut match_finder = MatchFinder::at_first_file(db)?; |
11 | for rule in rules { | 19 | for rule in rules { |
@@ -28,7 +36,12 @@ pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { | |||
28 | pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<String>) -> Result<()> { | 36 | pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<String>) -> Result<()> { |
29 | use ide_db::base_db::SourceDatabaseExt; | 37 | use ide_db::base_db::SourceDatabaseExt; |
30 | use ide_db::symbol_index::SymbolsDatabase; | 38 | use ide_db::symbol_index::SymbolsDatabase; |
31 | let (host, _vfs) = load_cargo(&std::env::current_dir()?, true, true)?; | 39 | let load_cargo_config = LoadCargoConfig { |
40 | cargo_config: Default::default(), | ||
41 | load_out_dirs_from_check: true, | ||
42 | with_proc_macro: true, | ||
43 | }; | ||
44 | let (host, _vfs) = load_cargo(&std::env::current_dir()?, &load_cargo_config)?; | ||
32 | let db = host.raw_database(); | 45 | let db = host.raw_database(); |
33 | let mut match_finder = MatchFinder::at_first_file(db)?; | 46 | let mut match_finder = MatchFinder::at_first_file(db)?; |
34 | for pattern in patterns { | 47 | for pattern in patterns { |