From 877521325f81eb5965848e9d24ccbf6d7db6d8e4 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 2 Mar 2021 13:14:05 +0800 Subject: [PATCH] Fix ProcMacroClient dropped too early in cli --- crates/rust-analyzer/src/cli/analysis_bench.rs | 2 +- crates/rust-analyzer/src/cli/analysis_stats.rs | 2 +- crates/rust-analyzer/src/cli/diagnostics.rs | 3 ++- crates/rust-analyzer/src/cli/load_cargo.rs | 9 +++++---- crates/rust-analyzer/src/cli/ssr.rs | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 8991f3bdb6..ebbbf05963 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs @@ -68,7 +68,7 @@ impl BenchCmd { load_out_dirs_from_check: self.load_output_dirs, with_proc_macro: self.with_proc_macro, }; - let (mut host, vfs) = + let (mut host, vfs, _proc_macro) = load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?; eprintln!("{:?}\n", start.elapsed()); diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 9072d89447..ad0759bdad 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -64,7 +64,7 @@ impl AnalysisStatsCmd { load_out_dirs_from_check: self.load_output_dirs, with_proc_macro: self.with_proc_macro, }; - let (host, vfs) = + let (host, vfs, _proc_macro) = load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?; let db = host.raw_database(); eprintln!("{:<20} {}", "Database loaded:", db_load_sw.elapsed()); diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index 876f6c44f3..8b985716b0 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs @@ -35,7 +35,8 @@ pub fn diagnostics( ) -> Result<()> { let cargo_config = Default::default(); let load_cargo_config = LoadCargoConfig { load_out_dirs_from_check, with_proc_macro }; - let (host, _vfs) = load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; + let (host, _vfs, _proc_macro) = + load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; let db = host.raw_database(); let analysis = host.analysis(); diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 23442afacc..310c36904e 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs @@ -23,7 +23,7 @@ pub fn load_workspace_at( cargo_config: &CargoConfig, load_config: &LoadCargoConfig, progress: &dyn Fn(String), -) -> Result<(AnalysisHost, vfs::Vfs)> { +) -> Result<(AnalysisHost, vfs::Vfs, Option)> { let root = AbsPathBuf::assert(std::env::current_dir()?.join(root)); let root = ProjectManifest::discover_single(&root)?; let workspace = ProjectWorkspace::load(root, cargo_config, progress)?; @@ -35,7 +35,7 @@ pub fn load_workspace( ws: ProjectWorkspace, config: &LoadCargoConfig, progress: &dyn Fn(String), -) -> Result<(AnalysisHost, vfs::Vfs)> { +) -> Result<(AnalysisHost, vfs::Vfs, Option)> { let (sender, receiver) = unbounded(); let mut vfs = vfs::Vfs::default(); let mut loader = { @@ -80,7 +80,7 @@ pub fn load_workspace( log::debug!("crate graph: {:?}", crate_graph); let host = load_crate_graph(crate_graph, project_folders.source_root_config, &mut vfs, &receiver); - Ok((host, vfs)) + Ok((host, vfs, proc_macro_client)) } fn load_crate_graph( @@ -138,7 +138,8 @@ mod tests { let cargo_config = Default::default(); let load_cargo_config = LoadCargoConfig { load_out_dirs_from_check: false, with_proc_macro: false }; - let (host, _vfs) = load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; + let (host, _vfs, _proc_macro) = + load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; let n_crates = Crate::all(host.raw_database()).len(); // RA has quite a few crates, but the exact count doesn't matter diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs index 71a8f8fb9e..79f426fff1 100644 --- a/crates/rust-analyzer/src/cli/ssr.rs +++ b/crates/rust-analyzer/src/cli/ssr.rs @@ -11,7 +11,7 @@ pub fn apply_ssr_rules(rules: Vec) -> Result<()> { let cargo_config = Default::default(); let load_cargo_config = LoadCargoConfig { load_out_dirs_from_check: true, with_proc_macro: true }; - let (host, vfs) = + let (host, vfs, _proc_macro) = load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?; let db = host.raw_database(); let mut match_finder = MatchFinder::at_first_file(db)?; @@ -38,7 +38,7 @@ pub fn search_for_patterns(patterns: Vec, debug_snippet: Option