aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-19 13:42:06 +0100
committerGitHub <[email protected]>2019-08-19 13:42:06 +0100
commitc7d37e424f1e04f87982233f97e1e9385191b7f1 (patch)
tree90a43945782c23458a56a5c01f4adf4586b0ca85
parent3ba9bc493fad9270dac74250d0b557495fe7d109 (diff)
parent7cd9b1dd7a91fb3b1e400fd4b47333c9699381f7 (diff)
Merge #1703
1703: don't load sysroot in most heavy tests r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_lsp_server/src/config.rs5
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs2
-rw-r--r--crates/ra_lsp_server/src/project_model.rs6
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs13
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs19
-rw-r--r--crates/ra_project_model/src/lib.rs12
-rw-r--r--crates/ra_project_model/src/sysroot.rs2
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 {
21 pub exclude_globs: Vec<String>, 21 pub exclude_globs: Vec<String>,
22 22
23 pub lru_capacity: Option<usize>, 23 pub lru_capacity: Option<usize>,
24
25 /// For internal usage to make integrated tests faster.
26 #[serde(deserialize_with = "nullable_bool_true")]
27 pub with_sysroot: bool,
24} 28}
25 29
26impl Default for ServerConfig { 30impl Default for ServerConfig {
@@ -30,6 +34,7 @@ impl Default for ServerConfig {
30 show_workspace_loaded: true, 34 show_workspace_loaded: true,
31 exclude_globs: Vec::new(), 35 exclude_globs: Vec::new(),
32 lru_capacity: None, 36 lru_capacity: None,
37 with_sysroot: true,
33 } 38 }
34 } 39 }
35} 40}
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(
59 log::debug!("server_config: {:?}", config); 59 log::debug!("server_config: {:?}", config);
60 // FIXME: support dynamic workspace loading. 60 // FIXME: support dynamic workspace loading.
61 let workspaces = { 61 let workspaces = {
62 let ws_worker = workspace_loader(); 62 let ws_worker = workspace_loader(config.with_sysroot);
63 let mut loaded_workspaces = Vec::new(); 63 let mut loaded_workspaces = Vec::new();
64 for ws_root in &ws_roots { 64 for ws_root in &ws_roots {
65 ws_worker.sender().send(ws_root.clone()).unwrap(); 65 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::{
8 CargoWorkspace, Package, ProjectWorkspace, Sysroot, Target, TargetKind, 8 CargoWorkspace, Package, ProjectWorkspace, Sysroot, Target, TargetKind,
9}; 9};
10 10
11pub fn workspace_loader() -> Worker<PathBuf, Result<ProjectWorkspace>> { 11pub fn workspace_loader(with_sysroot: bool) -> Worker<PathBuf, Result<ProjectWorkspace>> {
12 Worker::<PathBuf, Result<ProjectWorkspace>>::spawn( 12 Worker::<PathBuf, Result<ProjectWorkspace>>::spawn(
13 "workspace loader", 13 "workspace loader",
14 1, 14 1,
15 |input_receiver, output_sender| { 15 move |input_receiver, output_sender| {
16 input_receiver 16 input_receiver
17 .into_iter() 17 .into_iter()
18 .map(|path| ProjectWorkspace::discover(path.as_path())) 18 .map(|path| ProjectWorkspace::discover_with_sysroot(path.as_path(), with_sysroot))
19 .try_for_each(|it| output_sender.send(it)) 19 .try_for_each(|it| output_sender.send(it))
20 .unwrap() 20 .unwrap()
21 }, 21 },
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 = "";
22#[test] 22#[test]
23fn completes_items_from_standard_library() { 23fn completes_items_from_standard_library() {
24 let project_start = Instant::now(); 24 let project_start = Instant::now();
25 let server = project( 25 let server = Project::with_fixture(
26 r#" 26 r#"
27//- Cargo.toml 27//- Cargo.toml
28[package] 28[package]
@@ -32,7 +32,9 @@ version = "0.0.0"
32//- src/lib.rs 32//- src/lib.rs
33use std::collections::Spam; 33use std::collections::Spam;
34"#, 34"#,
35 ); 35 )
36 .with_sysroot(true)
37 .server();
36 server.wait_until_workspace_is_loaded(); 38 server.wait_until_workspace_is_loaded();
37 eprintln!("loading took {:?}", project_start.elapsed()); 39 eprintln!("loading took {:?}", project_start.elapsed());
38 let completion_start = Instant::now(); 40 let completion_start = Instant::now();
@@ -349,7 +351,7 @@ fn main() {{}}
349fn diagnostics_dont_block_typing() { 351fn diagnostics_dont_block_typing() {
350 let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect(); 352 let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect();
351 let libs: String = (0..10).map(|i| format!("//- src/m{}.rs\nfn foo() {{}}\n\n", i)).collect(); 353 let libs: String = (0..10).map(|i| format!("//- src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
352 let server = project(&format!( 354 let server = Project::with_fixture(&format!(
353 r#" 355 r#"
354//- Cargo.toml 356//- Cargo.toml
355[package] 357[package]
@@ -364,7 +366,10 @@ version = "0.0.0"
364fn main() {{}} 366fn main() {{}}
365"#, 367"#,
366 librs, libs 368 librs, libs
367 )); 369 ))
370 .with_sysroot(true)
371 .server();
372
368 server.wait_until_workspace_is_loaded(); 373 server.wait_until_workspace_is_loaded();
369 for i in 0..10 { 374 for i in 0..10 {
370 server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams { 375 server.notification::<DidOpenTextDocument>(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};
26 26
27pub struct Project<'a> { 27pub struct Project<'a> {
28 fixture: &'a str, 28 fixture: &'a str,
29 with_sysroot: bool,
29 tmp_dir: Option<TempDir>, 30 tmp_dir: Option<TempDir>,
30 roots: Vec<PathBuf>, 31 roots: Vec<PathBuf>,
31} 32}
32 33
33impl<'a> Project<'a> { 34impl<'a> Project<'a> {
34 pub fn with_fixture(fixture: &str) -> Project { 35 pub fn with_fixture(fixture: &str) -> Project {
35 Project { fixture, tmp_dir: None, roots: vec![] } 36 Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false }
36 } 37 }
37 38
38 pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> { 39 pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> {
@@ -45,6 +46,11 @@ impl<'a> Project<'a> {
45 self 46 self
46 } 47 }
47 48
49 pub fn with_sysroot(mut self, sysroot: bool) -> Project<'a> {
50 self.with_sysroot = sysroot;
51 self
52 }
53
48 pub fn server(self) -> Server { 54 pub fn server(self) -> Server {
49 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); 55 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap());
50 static INIT: Once = Once::new(); 56 static INIT: Once = Once::new();
@@ -68,7 +74,7 @@ impl<'a> Project<'a> {
68 74
69 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); 75 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
70 76
71 Server::new(tmp_dir, roots, paths) 77 Server::new(tmp_dir, self.with_sysroot, roots, paths)
72 } 78 }
73} 79}
74 80
@@ -84,7 +90,12 @@ pub struct Server {
84} 90}
85 91
86impl Server { 92impl Server {
87 fn new(dir: TempDir, roots: Vec<PathBuf>, files: Vec<(PathBuf, String)>) -> Server { 93 fn new(
94 dir: TempDir,
95 with_sysroot: bool,
96 roots: Vec<PathBuf>,
97 files: Vec<(PathBuf, String)>,
98 ) -> Server {
88 let path = dir.path().to_path_buf(); 99 let path = dir.path().to_path_buf();
89 100
90 let roots = if roots.is_empty() { vec![path] } else { roots }; 101 let roots = if roots.is_empty() { vec![path] } else { roots };
@@ -107,7 +118,7 @@ impl Server {
107 window: None, 118 window: None,
108 experimental: None, 119 experimental: None,
109 }, 120 },
110 ServerConfig::default(), 121 ServerConfig { with_sysroot, ..ServerConfig::default() },
111 &msg_receiver, 122 &msg_receiver,
112 &msg_sender, 123 &msg_sender,
113 ) 124 )
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 {
57 57
58impl ProjectWorkspace { 58impl ProjectWorkspace {
59 pub fn discover(path: &Path) -> Result<ProjectWorkspace> { 59 pub fn discover(path: &Path) -> Result<ProjectWorkspace> {
60 ProjectWorkspace::discover_with_sysroot(path, true)
61 }
62
63 pub fn discover_with_sysroot(path: &Path, with_sysroot: bool) -> Result<ProjectWorkspace> {
60 match find_rust_project_json(path) { 64 match find_rust_project_json(path) {
61 Some(json_path) => { 65 Some(json_path) => {
62 let file = File::open(json_path)?; 66 let file = File::open(json_path)?;
@@ -65,10 +69,10 @@ impl ProjectWorkspace {
65 } 69 }
66 None => { 70 None => {
67 let cargo_toml = find_cargo_toml(path)?; 71 let cargo_toml = find_cargo_toml(path)?;
68 Ok(ProjectWorkspace::Cargo { 72 let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml)?;
69 cargo: CargoWorkspace::from_cargo_metadata(&cargo_toml)?, 73 let sysroot =
70 sysroot: Sysroot::discover(&cargo_toml)?, 74 if with_sysroot { Sysroot::discover(&cargo_toml)? } else { Sysroot::default() };
71 }) 75 Ok(ProjectWorkspace::Cargo { cargo, sysroot })
72 } 76 }
73 } 77 }
74 } 78 }
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};
7 7
8use crate::Result; 8use crate::Result;
9 9
10#[derive(Debug, Clone)] 10#[derive(Default, Debug, Clone)]
11pub struct Sysroot { 11pub struct Sysroot {
12 crates: Arena<SysrootCrate, SysrootCrateData>, 12 crates: Arena<SysrootCrate, SysrootCrateData>,
13} 13}