diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index a8ee4032fa3..a2dc842e75b 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -20,16 +20,16 @@ use itertools::Itertools; use oorandom::Rand32; use profile::{Bytes, StopWatch}; -use project_model::CargoConfig; +use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace}; use rayon::prelude::*; use rustc_hash::FxHashSet; use stdx::format_to; use syntax::{AstNode, SyntaxNode}; -use vfs::{Vfs, VfsPath}; +use vfs::{AbsPathBuf, Vfs, VfsPath}; use crate::cli::{ flags, - load_cargo::{load_workspace_at, LoadCargoConfig}, + load_cargo::{load_workspace, LoadCargoConfig}, print_memory_usage, progress_report::ProgressReport, report_metric, Result, Verbosity, @@ -50,7 +50,6 @@ pub fn run(self, verbosity: Verbosity) -> Result<()> { Rand32::new(seed) }; - let mut db_load_sw = self.stop_watch(); let mut cargo_config = CargoConfig::default(); cargo_config.no_sysroot = self.no_sysroot; let load_cargo_config = LoadCargoConfig { @@ -58,10 +57,33 @@ pub fn run(self, verbosity: Verbosity) -> Result<()> { with_proc_macro: !self.disable_proc_macros, prefill_caches: false, }; - let (host, vfs, _proc_macro) = - load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?; + let no_progress = &|_| (); + + let mut db_load_sw = self.stop_watch(); + + let path = AbsPathBuf::assert(env::current_dir()?.join(&self.path)); + let manifest = ProjectManifest::discover_single(&path)?; + + let mut workspace = ProjectWorkspace::load(manifest, &cargo_config, no_progress)?; + let metadata_time = db_load_sw.elapsed(); + + let build_scripts_time = if self.disable_build_scripts { + None + } else { + let mut build_scripts_sw = self.stop_watch(); + let bs = workspace.run_build_scripts(&cargo_config, no_progress)?; + workspace.set_build_scripts(bs); + Some(build_scripts_sw.elapsed()) + }; + + let (host, vfs, _proc_macro) = load_workspace(workspace, &load_cargo_config)?; let db = host.raw_database(); - eprintln!("{:<20} {}", "Database loaded:", db_load_sw.elapsed()); + eprint!("{:<20} {}", "Database loaded:", db_load_sw.elapsed()); + eprint!(" (metadata {}", metadata_time); + if let Some(build_scripts_time) = build_scripts_time { + eprint!("; build {}", build_scripts_time); + } + eprintln!(")"); let mut analysis_sw = self.stop_watch(); let mut num_crates = 0; diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 7b6404eb2a7..9559d352a7a 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs @@ -8,7 +8,7 @@ use ide::{AnalysisHost, Change}; use ide_db::base_db::CrateGraph; use proc_macro_api::ProcMacroClient; -use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, WorkspaceBuildScripts}; +use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace}; use vfs::{loader::Handle, AbsPath, AbsPathBuf}; use crate::reload::{load_proc_macro, ProjectFolders, SourceRootConfig}; @@ -31,9 +31,14 @@ pub fn load_workspace_at( ) -> 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)?; + let mut workspace = ProjectWorkspace::load(root, cargo_config, progress)?; - load_workspace(workspace, cargo_config, load_config, progress) + if load_config.load_out_dirs_from_check { + let build_scripts = workspace.run_build_scripts(cargo_config, progress)?; + workspace.set_build_scripts(build_scripts) + } + + load_workspace(workspace, load_config) } // Note: Since this function is used by external tools that use rust-analyzer as a library @@ -42,10 +47,8 @@ pub fn load_workspace_at( // The reason both, `load_workspace_at` and `load_workspace` are `pub` is that some of // these tools need access to `ProjectWorkspace`, too, which `load_workspace_at` hides. pub fn load_workspace( - mut ws: ProjectWorkspace, - cargo_config: &CargoConfig, + ws: ProjectWorkspace, load_config: &LoadCargoConfig, - progress: &dyn Fn(String), ) -> Result<(AnalysisHost, vfs::Vfs, Option)> { let (sender, receiver) = unbounded(); let mut vfs = vfs::Vfs::default(); @@ -62,12 +65,6 @@ pub fn load_workspace( None }; - ws.set_build_scripts(if load_config.load_out_dirs_from_check { - ws.run_build_scripts(cargo_config, progress)? - } else { - WorkspaceBuildScripts::default() - }); - let crate_graph = ws.to_crate_graph( &mut |path: &AbsPath| load_proc_macro(proc_macro_client.as_ref(), path), &mut |path: &AbsPath| {