aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/tests/heavy_tests/support.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/tests/heavy_tests/support.rs')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs62
1 files changed, 45 insertions, 17 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 9e115fb7f..b07882700 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -26,26 +26,51 @@ use ra_lsp_server::{
26 InitializationOptions, 26 InitializationOptions,
27}; 27};
28 28
29pub fn project(fixture: &str) -> Server { 29pub struct Project<'a> {
30 let tmp_dir = TempDir::new().unwrap(); 30 fixture: &'a str,
31 project_with_tmpdir(tmp_dir, fixture) 31 tmp_dir: Option<TempDir>,
32 roots: Vec<PathBuf>,
32} 33}
33 34
34pub fn project_with_tmpdir(tmp_dir: TempDir, fixture: &str) -> Server { 35impl<'a> Project<'a> {
35 static INIT: Once = Once::new(); 36 pub fn with_fixture(fixture: &str) -> Project {
36 INIT.call_once(|| { 37 Project { fixture, tmp_dir: None, roots: vec![] }
37 let _ = Logger::with_env_or_str(crate::LOG).start().unwrap(); 38 }
38 });
39 39
40 let mut paths = vec![]; 40 pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> {
41 self.tmp_dir = Some(tmp_dir);
42 self
43 }
41 44
42 for entry in parse_fixture(fixture) { 45 pub fn root(mut self, path: &str) -> Project<'a> {
43 let path = tmp_dir.path().join(entry.meta); 46 self.roots.push(path.into());
44 fs::create_dir_all(path.parent().unwrap()).unwrap(); 47 self
45 fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); 48 }
46 paths.push((path, entry.text)); 49
50 pub fn server(self) -> Server {
51 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap());
52 static INIT: Once = Once::new();
53 INIT.call_once(|| {
54 let _ = Logger::with_env_or_str(crate::LOG).start().unwrap();
55 });
56
57 let mut paths = vec![];
58
59 for entry in parse_fixture(self.fixture) {
60 let path = tmp_dir.path().join(entry.meta);
61 fs::create_dir_all(path.parent().unwrap()).unwrap();
62 fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
63 paths.push((path, entry.text));
64 }
65
66 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
67
68 Server::new(tmp_dir, roots, paths)
47 } 69 }
48 Server::new(tmp_dir, paths) 70}
71
72pub fn project(fixture: &str) -> Server {
73 Project::with_fixture(fixture).server()
49} 74}
50 75
51pub struct Server { 76pub struct Server {
@@ -56,14 +81,17 @@ pub struct Server {
56} 81}
57 82
58impl Server { 83impl Server {
59 fn new(dir: TempDir, files: Vec<(PathBuf, String)>) -> Server { 84 fn new(dir: TempDir, roots: Vec<PathBuf>, files: Vec<(PathBuf, String)>) -> Server {
60 let path = dir.path().to_path_buf(); 85 let path = dir.path().to_path_buf();
86
87 let roots = if roots.is_empty() { vec![path] } else { roots };
88
61 let worker = Worker::<RawMessage, RawMessage>::spawn( 89 let worker = Worker::<RawMessage, RawMessage>::spawn(
62 "test server", 90 "test server",
63 128, 91 128,
64 move |mut msg_receiver, mut msg_sender| { 92 move |mut msg_receiver, mut msg_sender| {
65 main_loop( 93 main_loop(
66 vec![path], 94 roots,
67 InitializationOptions::default(), 95 InitializationOptions::default(),
68 &mut msg_receiver, 96 &mut msg_receiver,
69 &mut msg_sender, 97 &mut msg_sender,