From 3507bcb97aaaafba10d55c101bd295f3ab4fed4f Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Thu, 11 Apr 2019 08:08:19 +0200 Subject: Adds support for multiple editor workspaces on initialization This is a quick, partial fix for #1104 --- crates/ra_lsp_server/tests/heavy_tests/support.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/tests') diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index ab9db3dd4..4ea6760a1 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs @@ -63,7 +63,7 @@ impl Server { 128, move |mut msg_receiver, mut msg_sender| { main_loop( - path, + vec![path], InitializationOptions::default(), &mut msg_receiver, &mut msg_sender, -- cgit v1.2.3 From 7c7cfc5f04c51ed1e31b6a3091efc3941b3383c2 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Sat, 13 Apr 2019 19:45:21 +0200 Subject: Sends cwd info for runnables and code lenses --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 6 +++++- crates/ra_lsp_server/tests/heavy_tests/support.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/ra_lsp_server/tests') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 407719080..e9ce002de 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -62,6 +62,7 @@ fn foo() { "args": [ "test", "--", "foo", "--nocapture" ], "bin": "cargo", "env": { "RUST_BACKTRACE": "short" }, + "cwd": null, "label": "test foo", "range": { "end": { "character": 1, "line": 2 }, @@ -75,6 +76,7 @@ fn foo() { ], "bin": "cargo", "env": {}, + "cwd": null, "label": "cargo check --all", "range": { "end": { @@ -123,7 +125,8 @@ fn test_eggs() {} "range": { "end": { "character": 17, "line": 1 }, "start": { "character": 0, "line": 0 } - } + }, + "cwd": server.path() }, { "args": [ @@ -135,6 +138,7 @@ fn test_eggs() {} ], "bin": "cargo", "env": {}, + "cwd": server.path(), "label": "cargo check -p foo", "range": { "end": { diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 4ea6760a1..9e115fb7f 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs @@ -1,7 +1,7 @@ use std::{ cell::{Cell, RefCell}, fs, - path::PathBuf, + path::{Path, PathBuf}, sync::Once, time::Duration, }; @@ -177,6 +177,10 @@ impl Server { fn send_notification(&self, not: RawNotification) { self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap(); } + + pub fn path(&self) -> &Path { + self.dir.path() + } } impl Drop for Server { -- cgit v1.2.3 From c2dfc8a229c0a18dff08d5ce7e6836c91648eee5 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Sat, 13 Apr 2019 20:33:49 +0200 Subject: Modifies runnables test to use multi-workspace root --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 35 ++++++++----- crates/ra_lsp_server/tests/heavy_tests/support.rs | 62 ++++++++++++++++------- 2 files changed, 68 insertions(+), 29 deletions(-) (limited to 'crates/ra_lsp_server/tests') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index e9ce002de..6f37a980d 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -14,7 +14,7 @@ use ra_lsp_server::req::{ use serde_json::json; use tempfile::TempDir; -use crate::support::{project, project_with_tmpdir}; +use crate::support::{project, Project}; const LOG: &'static str = ""; @@ -95,25 +95,34 @@ fn foo() { #[test] fn test_runnables_project() { - let server = project( - r#" -//- Cargo.toml + let code = r#" +//- foo/Cargo.toml [package] name = "foo" version = "0.0.0" -//- src/lib.rs +//- foo/src/lib.rs pub fn foo() {} -//- tests/spam.rs +//- foo/tests/spam.rs #[test] fn test_eggs() {} -"#, - ); + +//- bar/Cargo.toml +[package] +name = "bar" +version = "0.0.0" + +//- bar/src/main.rs +fn main() {} +"#; + + let server = Project::with_fixture(code).root("foo").root("bar").server(); + server.wait_until_workspace_is_loaded(); server.request::( RunnablesParams { - text_document: server.doc_id("tests/spam.rs"), + text_document: server.doc_id("foo/tests/spam.rs"), position: None, }, json!([ @@ -126,7 +135,7 @@ fn test_eggs() {} "end": { "character": 17, "line": 1 }, "start": { "character": 0, "line": 0 } }, - "cwd": server.path() + "cwd": server.path().join("foo") }, { "args": [ @@ -138,7 +147,7 @@ fn test_eggs() {} ], "bin": "cargo", "env": {}, - "cwd": server.path(), + "cwd": server.path().join("foo"), "label": "cargo check -p foo", "range": { "end": { @@ -287,7 +296,9 @@ fn main() {{}} "#, PROJECT = project.to_string(), ); - let server = project_with_tmpdir(tmp_dir, &code); + + let server = Project::with_fixture(&code).tmp_dir(tmp_dir).server(); + server.wait_until_workspace_is_loaded(); let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; server.request::( 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::{ InitializationOptions, }; -pub fn project(fixture: &str) -> Server { - let tmp_dir = TempDir::new().unwrap(); - project_with_tmpdir(tmp_dir, fixture) +pub struct Project<'a> { + fixture: &'a str, + tmp_dir: Option, + roots: Vec, } -pub fn project_with_tmpdir(tmp_dir: TempDir, fixture: &str) -> Server { - static INIT: Once = Once::new(); - INIT.call_once(|| { - let _ = Logger::with_env_or_str(crate::LOG).start().unwrap(); - }); +impl<'a> Project<'a> { + pub fn with_fixture(fixture: &str) -> Project { + Project { fixture, tmp_dir: None, roots: vec![] } + } - let mut paths = vec![]; + pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> { + self.tmp_dir = Some(tmp_dir); + self + } - for entry in parse_fixture(fixture) { - let path = tmp_dir.path().join(entry.meta); - fs::create_dir_all(path.parent().unwrap()).unwrap(); - fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); - paths.push((path, entry.text)); + pub fn root(mut self, path: &str) -> Project<'a> { + self.roots.push(path.into()); + self + } + + pub fn server(self) -> Server { + let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); + static INIT: Once = Once::new(); + INIT.call_once(|| { + let _ = Logger::with_env_or_str(crate::LOG).start().unwrap(); + }); + + let mut paths = vec![]; + + for entry in parse_fixture(self.fixture) { + let path = tmp_dir.path().join(entry.meta); + fs::create_dir_all(path.parent().unwrap()).unwrap(); + fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); + paths.push((path, entry.text)); + } + + let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); + + Server::new(tmp_dir, roots, paths) } - Server::new(tmp_dir, paths) +} + +pub fn project(fixture: &str) -> Server { + Project::with_fixture(fixture).server() } pub struct Server { @@ -56,14 +81,17 @@ pub struct Server { } impl Server { - fn new(dir: TempDir, files: Vec<(PathBuf, String)>) -> Server { + fn new(dir: TempDir, roots: Vec, files: Vec<(PathBuf, String)>) -> Server { let path = dir.path().to_path_buf(); + + let roots = if roots.is_empty() { vec![path] } else { roots }; + let worker = Worker::::spawn( "test server", 128, move |mut msg_receiver, mut msg_sender| { main_loop( - vec![path], + roots, InitializationOptions::default(), &mut msg_receiver, &mut msg_sender, -- cgit v1.2.3