don't load sysroot in most heavy tests

This commit is contained in:
Aleksey Kladov 2019-08-19 15:41:18 +03:00
parent cef90ce45e
commit 7cd9b1dd7a
7 changed files with 42 additions and 17 deletions

View File

@ -21,6 +21,10 @@ pub struct ServerConfig {
pub exclude_globs: Vec<String>,
pub lru_capacity: Option<usize>,
/// 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,
}
}
}

View File

@ -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();

View File

@ -8,14 +8,14 @@ pub use ra_project_model::{
CargoWorkspace, Package, ProjectWorkspace, Sysroot, Target, TargetKind,
};
pub fn workspace_loader() -> Worker<PathBuf, Result<ProjectWorkspace>> {
pub fn workspace_loader(with_sysroot: bool) -> Worker<PathBuf, Result<ProjectWorkspace>> {
Worker::<PathBuf, Result<ProjectWorkspace>>::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()
},

View File

@ -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::<DidOpenTextDocument>(DidOpenTextDocumentParams {

View File

@ -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<TempDir>,
roots: Vec<PathBuf>,
}
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<PathBuf>, files: Vec<(PathBuf, String)>) -> Server {
fn new(
dir: TempDir,
with_sysroot: bool,
roots: Vec<PathBuf>,
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,
)

View File

@ -57,6 +57,10 @@ impl PackageRoot {
impl ProjectWorkspace {
pub fn discover(path: &Path) -> Result<ProjectWorkspace> {
ProjectWorkspace::discover_with_sysroot(path, true)
}
pub fn discover_with_sysroot(path: &Path, with_sysroot: bool) -> Result<ProjectWorkspace> {
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 })
}
}
}

View File

@ -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<SysrootCrate, SysrootCrateData>,
}