From 7cd9b1dd7a91fb3b1e400fd4b47333c9699381f7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 19 Aug 2019 15:41:18 +0300 Subject: don't load sysroot in most heavy tests --- crates/ra_lsp_server/src/config.rs | 5 +++++ crates/ra_lsp_server/src/main_loop.rs | 2 +- crates/ra_lsp_server/src/project_model.rs | 6 +++--- crates/ra_lsp_server/tests/heavy_tests/main.rs | 13 +++++++++---- crates/ra_lsp_server/tests/heavy_tests/support.rs | 19 +++++++++++++++---- crates/ra_project_model/src/lib.rs | 12 ++++++++---- crates/ra_project_model/src/sysroot.rs | 2 +- 7 files changed, 42 insertions(+), 17 deletions(-) diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs index 6dcdc695a..71838b89c 100644 --- a/crates/ra_lsp_server/src/config.rs +++ b/crates/ra_lsp_server/src/config.rs @@ -21,6 +21,10 @@ pub struct ServerConfig { pub exclude_globs: Vec, pub lru_capacity: Option, + + /// For internal usage to make integrated tests faster. + #[serde(deserialize_with = "nullable_bool_true")] + pub with_sysroot: bool, } impl Default for ServerConfig { @@ -30,6 +34,7 @@ impl Default for ServerConfig { show_workspace_loaded: true, exclude_globs: Vec::new(), lru_capacity: None, + with_sysroot: true, } } } diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index b9c99a223..3ee0ad652 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -59,7 +59,7 @@ pub fn main_loop( log::debug!("server_config: {:?}", config); // FIXME: support dynamic workspace loading. let workspaces = { - let ws_worker = workspace_loader(); + let ws_worker = workspace_loader(config.with_sysroot); let mut loaded_workspaces = Vec::new(); for ws_root in &ws_roots { ws_worker.sender().send(ws_root.clone()).unwrap(); diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index 1130d08de..ad59cde64 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs @@ -8,14 +8,14 @@ pub use ra_project_model::{ CargoWorkspace, Package, ProjectWorkspace, Sysroot, Target, TargetKind, }; -pub fn workspace_loader() -> Worker> { +pub fn workspace_loader(with_sysroot: bool) -> Worker> { Worker::>::spawn( "workspace loader", 1, - |input_receiver, output_sender| { + move |input_receiver, output_sender| { input_receiver .into_iter() - .map(|path| ProjectWorkspace::discover(path.as_path())) + .map(|path| ProjectWorkspace::discover_with_sysroot(path.as_path(), with_sysroot)) .try_for_each(|it| output_sender.send(it)) .unwrap() }, diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 451be32a8..de3bd5bc5 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -22,7 +22,7 @@ const PROFILE: &'static str = ""; #[test] fn completes_items_from_standard_library() { let project_start = Instant::now(); - let server = project( + let server = Project::with_fixture( r#" //- Cargo.toml [package] @@ -32,7 +32,9 @@ version = "0.0.0" //- src/lib.rs use std::collections::Spam; "#, - ); + ) + .with_sysroot(true) + .server(); server.wait_until_workspace_is_loaded(); eprintln!("loading took {:?}", project_start.elapsed()); let completion_start = Instant::now(); @@ -349,7 +351,7 @@ fn main() {{}} fn diagnostics_dont_block_typing() { let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect(); let libs: String = (0..10).map(|i| format!("//- src/m{}.rs\nfn foo() {{}}\n\n", i)).collect(); - let server = project(&format!( + let server = Project::with_fixture(&format!( r#" //- Cargo.toml [package] @@ -364,7 +366,10 @@ version = "0.0.0" fn main() {{}} "#, librs, libs - )); + )) + .with_sysroot(true) + .server(); + server.wait_until_workspace_is_loaded(); for i in 0..10 { server.notification::(DidOpenTextDocumentParams { diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index ba8ee8b06..055c8fff2 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs @@ -26,13 +26,14 @@ use ra_lsp_server::{main_loop, req, ServerConfig}; pub struct Project<'a> { fixture: &'a str, + with_sysroot: bool, tmp_dir: Option, roots: Vec, } impl<'a> Project<'a> { pub fn with_fixture(fixture: &str) -> Project { - Project { fixture, tmp_dir: None, roots: vec![] } + Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false } } pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> { @@ -45,6 +46,11 @@ impl<'a> Project<'a> { self } + pub fn with_sysroot(mut self, sysroot: bool) -> Project<'a> { + self.with_sysroot = sysroot; + self + } + pub fn server(self) -> Server { let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); static INIT: Once = Once::new(); @@ -68,7 +74,7 @@ impl<'a> Project<'a> { let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); - Server::new(tmp_dir, roots, paths) + Server::new(tmp_dir, self.with_sysroot, roots, paths) } } @@ -84,7 +90,12 @@ pub struct Server { } impl Server { - fn new(dir: TempDir, roots: Vec, files: Vec<(PathBuf, String)>) -> Server { + fn new( + dir: TempDir, + with_sysroot: bool, + roots: Vec, + files: Vec<(PathBuf, String)>, + ) -> Server { let path = dir.path().to_path_buf(); let roots = if roots.is_empty() { vec![path] } else { roots }; @@ -107,7 +118,7 @@ impl Server { window: None, experimental: None, }, - ServerConfig::default(), + ServerConfig { with_sysroot, ..ServerConfig::default() }, &msg_receiver, &msg_sender, ) diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 55b94b911..676dc4941 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -57,6 +57,10 @@ impl PackageRoot { impl ProjectWorkspace { pub fn discover(path: &Path) -> Result { + ProjectWorkspace::discover_with_sysroot(path, true) + } + + pub fn discover_with_sysroot(path: &Path, with_sysroot: bool) -> Result { match find_rust_project_json(path) { Some(json_path) => { let file = File::open(json_path)?; @@ -65,10 +69,10 @@ impl ProjectWorkspace { } None => { let cargo_toml = find_cargo_toml(path)?; - Ok(ProjectWorkspace::Cargo { - cargo: CargoWorkspace::from_cargo_metadata(&cargo_toml)?, - sysroot: Sysroot::discover(&cargo_toml)?, - }) + let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml)?; + let sysroot = + if with_sysroot { Sysroot::discover(&cargo_toml)? } else { Sysroot::default() }; + Ok(ProjectWorkspace::Cargo { cargo, sysroot }) } } } diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 3f34d51cc..2a7927f7e 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs @@ -7,7 +7,7 @@ use ra_arena::{impl_arena_id, Arena, RawId}; use crate::Result; -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] pub struct Sysroot { crates: Arena, } -- cgit v1.2.3