diff --git a/crates/ide-host/src/lib.rs b/crates/ide-host/src/lib.rs index 527f19a1e..633c99b5f 100644 --- a/crates/ide-host/src/lib.rs +++ b/crates/ide-host/src/lib.rs @@ -58,6 +58,27 @@ pub struct HostConfig { pub project_environment: bool, } +#[cfg(test)] +impl HostConfig { + /// A host under `base` for unit tests: `config`, `data` and `data` again for the machine-local + /// directory, built-in languages, no grammars, a sink that drops events, the window as its own + /// owner, the current tokio runtime and no project environment. Override fields with + /// `HostConfig { sink_for: .., ..HostConfig::for_test(base) }`. Call it inside a runtime. + pub(crate) fn for_test(base: &Path) -> Self { + Self { + config_dir: base.join("config"), + data_dir: base.join("data"), + local_data_dir: base.join("data"), + languages: Arc::new(LanguageRegistry::load(None).unwrap()), + syntax: Arc::default(), + sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), + owner: |w| w, + runtime: tokio::runtime::Handle::current(), + project_environment: false, + } + } +} + pub struct Host { pub(crate) mcp_executable: Arc>>, pub mcp: mcp::McpService, @@ -622,17 +643,7 @@ mod tests { let root = base.join("project"); std::fs::create_dir(&root).unwrap(); std::fs::write(root.join("main.rs"), "fn main() {}\n").unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); let project = Arc::downgrade(&host.open_project("main", &root).unwrap()); host.close_project_detached("main"); assert!(host.project("main").is_err()); diff --git a/crates/ide-host/src/mcp/background/tests.rs b/crates/ide-host/src/mcp/background/tests.rs index dc2c43407..18e81f889 100644 --- a/crates/ide-host/src/mcp/background/tests.rs +++ b/crates/ide-host/src/mcp/background/tests.rs @@ -42,15 +42,9 @@ impl Fixture { } let syntax: Arc>> = Arc::default(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), syntax: syntax.clone(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..HostConfig::for_test(&base) })); let fixture = Self { host, base, syntax, _tmp: tmp }; fixture.set("enabled", json!(true)); diff --git a/crates/ide-host/src/ops/build.rs b/crates/ide-host/src/ops/build.rs index a5a317991..65dd96cfe 100644 --- a/crates/ide-host/src/ops/build.rs +++ b/crates/ide-host/src/ops/build.rs @@ -1446,17 +1446,8 @@ mod maven_completion_tests { let path = root.join("pom.xml"); std::fs::write(&path, text).unwrap(); - let host = Host::new(crate::HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = + Host::new(crate::HostConfig { local_data_dir: base.join("local"), ..crate::HostConfig::for_test(&base) }); let project = host.open_project("main", &root).unwrap(); let info = project.documents.open(&path).unwrap(); diff --git a/crates/ide-host/src/ops/db.rs b/crates/ide-host/src/ops/db.rs index 6c07ddebb..e4ac76039 100644 --- a/crates/ide-host/src/ops/db.rs +++ b/crates/ide-host/src/ops/db.rs @@ -646,7 +646,6 @@ mod tests { use super::*; use crate::HostConfig; use ide_db::DbDriver; - use std::sync::Arc; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn a_reporting_error_stops_the_batch_and_releases_the_request() { @@ -654,17 +653,7 @@ mod tests { let base = dunce::canonicalize(temp.path()).unwrap(); let root = base.join("project"); std::fs::create_dir(&root).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); let window = "main"; host.open_project(window, &root).unwrap(); host.set_project_trust(&root, true, false).await.unwrap(); diff --git a/crates/ide-host/src/ops/debug/kotlin_tests.rs b/crates/ide-host/src/ops/debug/kotlin_tests.rs index c4cf23d69..5968508e4 100644 --- a/crates/ide-host/src/ops/debug/kotlin_tests.rs +++ b/crates/ide-host/src/ops/debug/kotlin_tests.rs @@ -31,18 +31,11 @@ impl Fixture { let events = Arc::new(Mutex::new(Vec::new())); let captured = events.clone(); let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |_| { let events = captured.clone(); Arc::new(move |event| events.lock().push(event)) }), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..HostConfig::for_test(&base) }); let missing = base.join("missing").join("kotlin-debug-adapter"); host.global_settings diff --git a/crates/ide-host/src/ops/dependencies.rs b/crates/ide-host/src/ops/dependencies.rs index 3de1d6ec2..17eb32601 100644 --- a/crates/ide-host/src/ops/dependencies.rs +++ b/crates/ide-host/src/ops/dependencies.rs @@ -334,7 +334,6 @@ pub async fn pypi_package( mod tests { use super::*; use crate::HostConfig; - use std::sync::Arc; struct Source; impl DependencyVersionSource for Source { @@ -355,17 +354,7 @@ mod tests { let text = "# 中文 😀\n[dependencies]\ntokio = { version = \"0.2\", features = [\"full\"] }\nserde = \"1.0.100\"\nlocal = { path = \"../x\", version = \"0.2\" }\n"; let path = root.join("Cargo.toml"); std::fs::write(&path, text).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); let project = host.open_project("main", &root).unwrap(); let info = project.documents.open(&path).unwrap(); for package in ["tokio", "serde"] { @@ -411,17 +400,7 @@ mod tests { let text = "# 中文\nopenidea-missing-xyz>=1\n-r other.txt\n"; let path = root.join("requirements.txt"); std::fs::write(&path, text).unwrap(); - let host = Host::new(HostConfig { - config_dir: base_dir.join("config"), - data_dir: base_dir.join("data"), - local_data_dir: base_dir.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base_dir.join("local"), ..HostConfig::for_test(&base_dir) }); let project = host.open_project("main", &root).unwrap(); let info = project.documents.open(&path).unwrap(); // Restricted Mode never runs the interpreter. @@ -461,17 +440,7 @@ mod tests { let text = "{\n \"devDependencies\": { \"@types/node\": \"^20\" }\n}\n"; let path = root.join("package.json"); std::fs::write(&path, text).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); let project = host.open_project("main", &root).unwrap(); let info = project.documents.open(&path).unwrap(); host.dependency_versions.versions(&CachedNpm, "@types/node", &CancellationToken::new()).unwrap(); diff --git a/crates/ide-host/src/ops/doc/tests.rs b/crates/ide-host/src/ops/doc/tests.rs index b4fc834bd..458fd48a3 100644 --- a/crates/ide-host/src/ops/doc/tests.rs +++ b/crates/ide-host/src/ops/doc/tests.rs @@ -28,18 +28,11 @@ impl Fixture { let events = Arc::new(Mutex::new(Vec::new())); let captured = events.clone(); let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |_| { let events = captured.clone(); Arc::new(move |event| events.lock().push(event)) }), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..HostConfig::for_test(&base) }); let project = host.open_project("main", &root).unwrap(); Self { _temp: temp, host, project, events, path, outside } diff --git a/crates/ide-host/src/ops/heap/tests.rs b/crates/ide-host/src/ops/heap/tests.rs index f82d3dccd..5fd2f296d 100644 --- a/crates/ide-host/src/ops/heap/tests.rs +++ b/crates/ide-host/src/ops/heap/tests.rs @@ -26,17 +26,7 @@ impl Fixture { let base = dunce::canonicalize(temp.path()).unwrap(); let root = base.join("project"); std::fs::create_dir_all(&root).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); host.open_project(WINDOW, &root).unwrap(); host.set_project_trust(&root, true, false).await.unwrap(); Self { host, base, root, _temp: temp } diff --git a/crates/ide-host/src/ops/sdk.rs b/crates/ide-host/src/ops/sdk.rs index bd341da42..b8b1f15c6 100644 --- a/crates/ide-host/src/ops/sdk.rs +++ b/crates/ide-host/src/ops/sdk.rs @@ -503,7 +503,6 @@ mod tests { use super::*; use crate::HostConfig; use std::path::Path; - use std::sync::Arc; fn fake_venv(root: &Path, name: &str) -> PathBuf { use std::os::unix::fs::PermissionsExt; @@ -529,17 +528,7 @@ mod tests { let (main_python, own_python) = (fake_venv(&root, ".venv"), fake_venv(&own, ".venv")); ide_workspace::workspace::Workspace::attach(&root, "ws", vec![root.clone(), bare.clone(), own.clone()]) .unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); let project = host.project("main").unwrap(); @@ -593,17 +582,7 @@ mod tests { let base = dunce::canonicalize(temp.path()).unwrap(); let root = base.join("project"); std::fs::create_dir(&root).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); @@ -657,17 +636,7 @@ mod tests { ]); std::fs::write(config.join("recent.json"), serde_json::to_vec(&recent).unwrap()).unwrap(); - let host = Host::new(HostConfig { - config_dir: config, - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..HostConfig::for_test(&base) }); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); diff --git a/crates/ide-host/src/ops/stream_trace/tests.rs b/crates/ide-host/src/ops/stream_trace/tests.rs index 550426094..189159f51 100644 --- a/crates/ide-host/src/ops/stream_trace/tests.rs +++ b/crates/ide-host/src/ops/stream_trace/tests.rs @@ -272,17 +272,8 @@ impl Fixture { std::fs::create_dir_all(root.join("src")).unwrap(); let source = root.join("src/Chains.java"); std::fs::write(&source, SOURCE).unwrap(); - let host = Host::new(crate::HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = + Host::new(crate::HostConfig { local_data_dir: base.join("local"), ..crate::HostConfig::for_test(&base) }); host.open_project(WINDOW, &root).unwrap(); host.set_project_trust(&root, true, false).await.unwrap(); Self { host, source, _temp: temp } diff --git a/crates/ide-host/src/ops/term.rs b/crates/ide-host/src/ops/term.rs index db97fa63c..152e2d4ca 100644 --- a/crates/ide-host/src/ops/term.rs +++ b/crates/ide-host/src/ops/term.rs @@ -183,23 +183,12 @@ pub fn term_available_shells() -> Vec { mod tests { use super::*; use crate::HostConfig; - use ide_core::{NullSink, error::ErrorKind}; - use std::sync::Arc; + use ide_core::error::ErrorKind; #[tokio::test] async fn image_size_limit_is_checked_before_storage() { let root = tempfile::tempdir().unwrap(); - let host = Host::new(HostConfig { - config_dir: root.path().join("config"), - data_dir: root.path().join("data"), - local_data_dir: root.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig::for_test(root.path())); let id = TerminalId::next(); let error = term_store_image(&host, id, vec![0; MAX_IMAGE_BYTES + 1].into(), "image/png".into()).await.unwrap_err(); diff --git a/crates/ide-host/src/plugins/files_changed.rs b/crates/ide-host/src/plugins/files_changed.rs index e2c6fd83b..e424127a4 100644 --- a/crates/ide-host/src/plugins/files_changed.rs +++ b/crates/ide-host/src/plugins/files_changed.rs @@ -542,17 +542,7 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); - let backend = crate::Host::new(crate::HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let backend = crate::Host::new(crate::HostConfig::for_test(tmp.path())); backend.open_project("main", &root).unwrap(); let active = backend.project("main").unwrap().files_events_active.clone(); let plugins = diff --git a/crates/ide-host/src/plugins/views.rs b/crates/ide-host/src/plugins/views.rs index d4d5b078f..e4bd3d07f 100644 --- a/crates/ide-host/src/plugins/views.rs +++ b/crates/ide-host/src/plugins/views.rs @@ -130,17 +130,7 @@ mod tests { #[tokio::test] async fn a_tool_window_call_carries_the_active_editor() { let tmp = tempfile::tempdir().unwrap(); - let host = Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig::for_test(tmp.path())); let range = ide_core::Range::new(ide_core::Pos::new(1, 0), ide_core::Pos::new(1, 4)); let active = PluginEditor { path: "/p/a.rs".into(), language: "rust".into(), selections: vec![range] }; let inv = view_invocation(&host, "main", None, Some(active)).unwrap(); diff --git a/crates/ide-host/src/proxy.rs b/crates/ide-host/src/proxy.rs index 6644d250b..5804fcfa7 100644 --- a/crates/ide-host/src/proxy.rs +++ b/crates/ide-host/src/proxy.rs @@ -87,17 +87,7 @@ mod tests { #[tokio::test] async fn without_a_credential_store_the_password_lasts_the_session() { let tmp = tempfile::tempdir().unwrap(); - let mut host = Host::new(crate::HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let mut host = Host::new(crate::HostConfig::for_test(tmp.path())); let path = tmp.path().join("data/proxy-password.json"); std::fs::create_dir_all(path.parent().unwrap()).unwrap(); std::fs::write(&path, r#"{"httpProxy": "old"}"#).unwrap(); diff --git a/crates/ide-host/tests/agent_approvals.rs b/crates/ide-host/tests/agent_approvals.rs index 542c7ef92..7ad2bf329 100644 --- a/crates/ide-host/tests/agent_approvals.rs +++ b/crates/ide-host/tests/agent_approvals.rs @@ -1,6 +1,7 @@ //! The mode new agent tasks start in. -use ide_core::NullSink; +mod common; + use ide_host::{Host, HostConfig}; use serde_json::json; use std::path::Path; @@ -41,17 +42,8 @@ async fn new_tasks_start_asking_for_approval_when_the_user_chose_so() { std::fs::write(config.join("settings.toml"), "[agents]\nnewTaskApprovals = \"ask\"\n").unwrap(); // A project's own settings don't choose this. std::fs::write(root.join(".openidea/settings.toml"), "[agents]\nnewTaskApprovals = \"bypass\"\n").unwrap(); - let host = Arc::new(Host::new(HostConfig { - config_dir: config.clone(), - data_dir: data, - local_data_dir: tmp.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = + Arc::new(Host::new(HostConfig { local_data_dir: tmp.path().join("local"), ..common::host_config(tmp.path()) })); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); assert_eq!(codex_mode(&host).await.as_deref(), Some("ask")); diff --git a/crates/ide-host/tests/agent_env_secrets.rs b/crates/ide-host/tests/agent_env_secrets.rs index 3c6de3c8e..09f499db5 100644 --- a/crates/ide-host/tests/agent_env_secrets.rs +++ b/crates/ide-host/tests/agent_env_secrets.rs @@ -1,7 +1,8 @@ //! Values of agents' environment variables live in the credential store; agent files keep only their names. -use ide_core::NullSink; -use ide_host::{Host, HostConfig}; +mod common; + +use ide_host::Host; use ide_ssh::secrets::testing::{files_containing, use_memory_store}; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; @@ -10,17 +11,7 @@ use std::sync::Arc; const VALUE: &str = "agent-env-value-5b2d81"; fn host(dir: &Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: dir.join("config"), - data_dir: dir.join("data"), - local_data_dir: dir.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(dir))) } fn open(host: &Host, tmp: &tempfile::TempDir) { diff --git a/crates/ide-host/tests/agent_mcp.rs b/crates/ide-host/tests/agent_mcp.rs index 2e327b9b3..cbe01e571 100644 --- a/crates/ide-host/tests/agent_mcp.rs +++ b/crates/ide-host/tests/agent_mcp.rs @@ -1,30 +1,21 @@ //! External MCP servers in Settings › Agents, as the host stores and lists them. +mod common; + use ide_agent::{McpScope, McpServer, McpServerInput}; -use ide_core::NullSink; use ide_core::settings::McpTransport; +use ide_host::Host; use ide_host::ops::agent::{ agent_mcp_import as mcp_import, agent_mcp_list as mcp_list, agent_mcp_save as mcp_save, agent_mcp_set_enabled as mcp_set_enabled, }; -use ide_host::{Host, HostConfig}; use std::path::{Path, PathBuf}; use std::sync::Arc; fn open(base: &Path) -> (Arc, PathBuf) { let root = dunce::canonicalize(base).unwrap().join("project"); std::fs::create_dir_all(root.join(".openidea")).unwrap(); - let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(base))); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); (host, root) diff --git a/crates/ide-host/tests/agent_model_refresh.rs b/crates/ide-host/tests/agent_model_refresh.rs index c91c339ce..0113db065 100644 --- a/crates/ide-host/tests/agent_model_refresh.rs +++ b/crates/ide-host/tests/agent_model_refresh.rs @@ -1,8 +1,9 @@ //! Separate project windows share discovery and its backend-enforced cooldown. #![cfg(unix)] +mod common; + use ide_agent::AgentEvent; -use ide_core::NullSink; use ide_host::{Host, HostConfig, ops}; use std::sync::Arc; use std::time::Duration; @@ -43,17 +44,7 @@ done ), ) .unwrap(); - let host = Host::new(HostConfig { - config_dir: config, - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: tmp.path().join("local"), ..common::host_config(tmp.path()) }); host.trust.decide(&root, true, false).unwrap(); host.open_project("first", &root).unwrap(); host.open_project("second", &root).unwrap(); diff --git a/crates/ide-host/tests/attached_excludes.rs b/crates/ide-host/tests/attached_excludes.rs index 71d81bb03..2368405b9 100644 --- a/crates/ide-host/tests/attached_excludes.rs +++ b/crates/ide-host/tests/attached_excludes.rs @@ -1,5 +1,7 @@ //! Each project of a workspace keeps its own excluded folders: they apply below that project only. -use ide_core::{NullSink, RequestId}; +mod common; + +use ide_core::RequestId; use ide_host::{Host, HostConfig, ops}; use ide_workspace::settings::SettingsScope; use std::path::{Path, PathBuf}; @@ -7,17 +9,7 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; fn host(base: &Path) -> Host { - Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }) + Host::new(HostConfig { local_data_dir: base.join("local"), ..common::host_config(base) }) } /// Files containing `needle` that Find in Files reports, by path. diff --git a/crates/ide-host/tests/binary_args.rs b/crates/ide-host/tests/binary_args.rs index 9b9a510c9..79b344394 100644 --- a/crates/ide-host/tests/binary_args.rs +++ b/crates/ide-host/tests/binary_args.rs @@ -1,8 +1,10 @@ //! Binary command arguments over the remote protocol: base64 strings, not arrays of numbers. -use ide_core::{IpcBytes, NullSink}; +mod common; + +use ide_core::IpcBytes; +use ide_host::Host; use ide_host::rpc::{self, Dispatcher, Invoke}; -use ide_host::{Host, HostConfig}; use ide_jsonrpc::{Handler, Peer}; use serde_json::{Value, json}; use std::sync::{Arc, OnceLock}; @@ -17,17 +19,7 @@ impl Handler for Client { } async fn connect(base: &std::path::Path) -> Peer { - let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(base))); let (client_io, server_io) = tokio::io::duplex(1 << 20); let (sr, sw) = tokio::io::split(server_io); tokio::spawn(rpc::serve(host, Dispatcher::standard(), Arc::new(OnceLock::new()), sr, sw)); diff --git a/crates/ide-host/tests/close_project.rs b/crates/ide-host/tests/close_project.rs index de0d01064..06c935395 100644 --- a/crates/ide-host/tests/close_project.rs +++ b/crates/ide-host/tests/close_project.rs @@ -2,8 +2,9 @@ //! and leaves the other windows' processes alone. #![cfg(unix)] -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_host::{Host, ops}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -27,17 +28,7 @@ fn closing_a_project_closes_its_terminals_and_keeps_other_windows() { std::fs::create_dir_all(&root).unwrap(); let runtime = tokio::runtime::Builder::new_multi_thread().worker_threads(2).enable_all().build().unwrap(); runtime.block_on(async { - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(tmp.path()))); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); let project_shell = ops::term::term_spawn(&host, "main", options(&root), ops::Channel::new(|_| {})) @@ -67,17 +58,7 @@ fn detached_close_returns_while_runtime_workers_wait_for_the_closing_thread() { std::fs::create_dir_all(&root).unwrap(); let runtime = tokio::runtime::Builder::new_multi_thread().worker_threads(1).enable_all().build().unwrap(); let _guard = runtime.enter(); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: runtime.handle().clone(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(tmp.path()))); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); diff --git a/crates/ide-host/tests/common/mod.rs b/crates/ide-host/tests/common/mod.rs new file mode 100644 index 000000000..fdb76ca68 --- /dev/null +++ b/crates/ide-host/tests/common/mod.rs @@ -0,0 +1,23 @@ +//! Shared by the integration tests (each declares `mod common;`). + +use ide_host::HostConfig; +use std::path::Path; +use std::sync::Arc; + +/// A host under `base`: `config`, `data` and `data` again for the machine-local directory, +/// built-in languages, no grammars, a sink that drops events, the window as its own owner, the +/// current tokio runtime and no project environment. Override fields with +/// `HostConfig { sink_for: .., ..common::host_config(base) }`. Call it inside a runtime. +pub fn host_config(base: &Path) -> HostConfig { + HostConfig { + config_dir: base.join("config"), + data_dir: base.join("data"), + local_data_dir: base.join("data"), + languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), + syntax: Arc::default(), + sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), + owner: |w| w, + runtime: tokio::runtime::Handle::current(), + project_environment: false, + } +} diff --git a/crates/ide-host/tests/container_python_real.rs b/crates/ide-host/tests/container_python_real.rs index 08801aa7c..f78398478 100644 --- a/crates/ide-host/tests/container_python_real.rs +++ b/crates/ide-host/tests/container_python_real.rs @@ -5,6 +5,8 @@ //! this machine's Python must not have Django installed. #![cfg(unix)] +mod common; + use ide_core::IdeEvent; use ide_host::{Host, HostConfig, ops}; use ide_run::{OutputChunk, RunConfig}; @@ -18,11 +20,6 @@ type Events = Arc>>; fn host(base: &Path, events: &Events) -> Arc { Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new({ let events = events.clone(); move |_| { @@ -30,9 +27,7 @@ fn host(base: &Path, events: &Events) -> Arc { Arc::new(move |e: IdeEvent| events.lock().unwrap().push(e)) } }), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(base) })) } diff --git a/crates/ide-host/tests/data_dirs.rs b/crates/ide-host/tests/data_dirs.rs index 113f23554..b2ab82879 100644 --- a/crates/ide-host/tests/data_dirs.rs +++ b/crates/ide-host/tests/data_dirs.rs @@ -1,6 +1,6 @@ -use ide_core::NullSink; +mod common; + use ide_host::{Host, HostConfig, ops}; -use std::sync::Arc; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn split_storage_keeps_user_history_and_uses_local_tools_and_caches() { @@ -11,17 +11,8 @@ async fn split_storage_keeps_user_history_and_uses_local_tools_and_caches() { let root = base.join("project"); std::fs::create_dir(&root).unwrap(); std::fs::write(root.join("notes.txt"), "hello\n").unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: data.clone(), - local_data_dir: local.clone(), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = + Host::new(HostConfig { data_dir: data.clone(), local_data_dir: local.clone(), ..common::host_config(&base) }); assert_eq!(std::path::PathBuf::from(ops::tools::jdk_download_location(&host).unwrap()), local.join("tools/jdks")); let light = host.open_light("main", &root.join("notes.txt")).unwrap(); assert!(light.cache_dir.starts_with(&local)); diff --git a/crates/ide-host/tests/db_consoles.rs b/crates/ide-host/tests/db_consoles.rs index e326f0008..11a58d470 100644 --- a/crates/ide-host/tests/db_consoles.rs +++ b/crates/ide-host/tests/db_consoles.rs @@ -1,23 +1,14 @@ -use ide_core::NullSink; +mod common; + +use ide_host::Host; use ide_host::ops::db; -use ide_host::{Host, HostConfig}; use std::sync::Arc; #[tokio::test] async fn new_query_consoles_are_numbered_after_the_default_one() { let tmp = tempfile::tempdir().unwrap(); let base = tmp.path(); - let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(base))); let names = |paths: Vec| -> Vec { paths.iter().map(|p| p.0.file_name().unwrap().to_string_lossy().into_owned()).collect() }; diff --git a/crates/ide-host/tests/debug_jvm_memory_ipc.rs b/crates/ide-host/tests/debug_jvm_memory_ipc.rs index 43aac0211..e803f02c2 100644 --- a/crates/ide-host/tests/debug_jvm_memory_ipc.rs +++ b/crates/ide-host/tests/debug_jvm_memory_ipc.rs @@ -2,9 +2,11 @@ //! that sends no real window (the desktop shell once passed `""`) never reaches the debugger, //! and a project in Restricted Mode never reads the debuggee's memory. -use ide_core::{IdeError, NullSink}; +mod common; + +use ide_core::IdeError; +use ide_host::Host; use ide_host::rpc::{self, Dispatcher, Invoke}; -use ide_host::{Host, HostConfig}; use ide_jsonrpc::{Handler, Peer}; use serde_json::{Value, json}; use std::sync::{Arc, OnceLock}; @@ -39,17 +41,7 @@ fn host(trusted: bool) -> (Arc, tempfile::TempDir) { let tmp = tempfile::tempdir().unwrap(); let root = tmp.path().join("project"); std::fs::create_dir(&root).unwrap(); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(tmp.path()))); host.trust.decide(&root, trusted, false).unwrap(); host.open_project("main", &root).unwrap(); (host, tmp) diff --git a/crates/ide-host/tests/directory_sync.rs b/crates/ide-host/tests/directory_sync.rs index 0cb73c0cd..32478757a 100644 --- a/crates/ide-host/tests/directory_sync.rs +++ b/crates/ide-host/tests/directory_sync.rs @@ -1,6 +1,8 @@ -use ide_core::{NullSink, RequestId}; +mod common; + +use ide_core::RequestId; use ide_host::{ - Host, HostConfig, + Host, ops::{Channel, fs::fs_synchronize_directories}, }; use ide_vfs::{DirectorySyncAction as Action, DirectorySyncOperation, DirectorySyncProgress}; @@ -18,17 +20,7 @@ fn op(path: &str, action: Action, overwrite: bool) -> DirectorySyncOperation { } fn host(base: &Path) -> Host { - Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }) + Host::new(common::host_config(base)) } #[tokio::test(flavor = "multi_thread")] diff --git a/crates/ide-host/tests/docker_run_targets.rs b/crates/ide-host/tests/docker_run_targets.rs index a236354bf..b518dd3f5 100644 --- a/crates/ide-host/tests/docker_run_targets.rs +++ b/crates/ide-host/tests/docker_run_targets.rs @@ -2,8 +2,9 @@ //! (`OPENIDEA_DOCKER`) that prints what it was given. #![cfg(unix)] -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_host::{Host, ops}; use ide_run::{OutputChunk, RunConfig}; use parking_lot::Mutex; use std::collections::BTreeMap; @@ -13,17 +14,7 @@ use std::sync::Arc; use std::time::Duration; fn host(base: &Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(base))) } fn config(target: &str, root: &Path) -> RunConfig { diff --git a/crates/ide-host/tests/docker_run_targets_real.rs b/crates/ide-host/tests/docker_run_targets_real.rs index 24b6304bf..753303a87 100644 --- a/crates/ide-host/tests/docker_run_targets_real.rs +++ b/crates/ide-host/tests/docker_run_targets_real.rs @@ -4,8 +4,9 @@ //! `docker` with the Compose plugin must be on `PATH`. #![cfg(unix)] -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_host::{Host, ops}; use ide_run::{OutputChunk, RunConfig}; use parking_lot::Mutex; use std::collections::BTreeMap; @@ -15,17 +16,7 @@ use std::sync::Arc; use std::time::Duration; fn host(base: &Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(base))) } fn config(id: &str, target: &str, root: &Path, args: &[&str]) -> RunConfig { diff --git a/crates/ide-host/tests/external_log.rs b/crates/ide-host/tests/external_log.rs index 023d96d61..946c07e52 100644 --- a/crates/ide-host/tests/external_log.rs +++ b/crates/ide-host/tests/external_log.rs @@ -1,7 +1,8 @@ //! Explicit external logs allow history reads without adding a writable project root. -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops::vcs}; -use std::{path::Path, process::Command, sync::Arc}; +mod common; + +use ide_host::{Host, ops::vcs}; +use std::{path::Path, process::Command}; fn git(root: &Path, args: &[&str]) -> String { let output = Command::new("git") @@ -31,17 +32,7 @@ async fn external_history_is_readable_and_never_becomes_a_write_target() { git(&external, &["rm", "deleted.txt"]); git(&external, &["commit", "-m", "delete"]); let head = git(&external, &["rev-parse", "HEAD"]); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); // A standalone editor needs no project, indexer, or writable VCS root. vcs::vcs_open_external_log(&host, "standalone", external.clone()).await.unwrap(); let standalone = vcs::vcs_log(&host, "standalone", Some(external.clone()), Default::default()).await.unwrap(); diff --git a/crates/ide-host/tests/gradle_linkage.rs b/crates/ide-host/tests/gradle_linkage.rs index d53c41f4a..d547ed7d6 100644 --- a/crates/ide-host/tests/gradle_linkage.rs +++ b/crates/ide-host/tests/gradle_linkage.rs @@ -1,6 +1,6 @@ -use ide_core::NullSink; +mod common; + use ide_host::{Host, HostConfig, ops}; -use std::sync::Arc; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn links_are_validated_persisted_and_unlinked_without_removing_files() { @@ -12,17 +12,7 @@ async fn links_are_validated_persisted_and_unlinked_without_removing_files() { std::fs::write(dir.join("settings.gradle"), "rootProject.name = 'same-name'").unwrap(); } let config = base.join("config"); - let host = Host::new(HostConfig { - config_dir: config.clone(), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..common::host_config(&base) }); host.open_project("main", &root).unwrap(); assert!(ops::build::gradle_link_projects(&host, "main", vec!["b".into()]).await.is_err()); host.set_project_trust(&root, true, false).await.unwrap(); diff --git a/crates/ide-host/tests/language_smoke.rs b/crates/ide-host/tests/language_smoke.rs index 207d4cefc..f4afc3aa8 100644 --- a/crates/ide-host/tests/language_smoke.rs +++ b/crates/ide-host/tests/language_smoke.rs @@ -8,6 +8,8 @@ //! pinned versions and runs one language per job: //! `cargo test -p ide-host --test language_smoke -- --ignored --exact `. +mod common; + use ide_core::{ChangeSet, DocId, IdeEvent, Pos, Range, RequestId, TextChange}; use ide_host::{Host, HostConfig, ops}; use ide_lsp::types::{FormatOptions, GotoKind}; @@ -182,11 +184,6 @@ impl Smoke { let events: Events = Arc::default(); let app = tmp.path().join("app"); let host = Arc::new(Host::new(HostConfig { - config_dir: app.join("config"), - data_dir: app.join("data"), - local_data_dir: app.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new({ let events = events.clone(); move |_| { @@ -194,9 +191,7 @@ impl Smoke { Arc::new(move |e: IdeEvent| events.lock().unwrap().push(e)) } }), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(&app) })); host.trust.decide(&root, true, false).unwrap(); host.open_project(WINDOW, &root).unwrap(); diff --git a/crates/ide-host/tests/light_edit.rs b/crates/ide-host/tests/light_edit.rs index e65cbfd09..e27df9dc0 100644 --- a/crates/ide-host/tests/light_edit.rs +++ b/crates/ide-host/tests/light_edit.rs @@ -1,22 +1,14 @@ //! LightEdit: a window editing loose files without a project. -use ide_core::{ChangeSet, NullSink, TextChange}; -use ide_host::{Host, HostConfig, catalogue::TrustClass, ops}; +mod common; + +use ide_core::{ChangeSet, TextChange}; +use ide_host::{Host, catalogue::TrustClass, ops}; use std::sync::Arc; use std::time::Duration; fn host(base: &std::path::Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(base))) } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] diff --git a/crates/ide-host/tests/maven_external.rs b/crates/ide-host/tests/maven_external.rs index 04889c2a8..c53321a62 100644 --- a/crates/ide-host/tests/maven_external.rs +++ b/crates/ide-host/tests/maven_external.rs @@ -1,7 +1,7 @@ -use ide_core::NullSink; +mod common; + use ide_host::{Host, HostConfig, ops}; use ide_workspace::settings::SettingsScope; -use std::sync::Arc; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn external_maven_link_persists_reloads_and_unlink_keeps_files() { @@ -17,17 +17,7 @@ async fn external_maven_link_persists_reloads_and_unlink_keeps_files() { std::fs::write(root.join("core/pom.xml"), "core").unwrap(); std::fs::write(sibling.join("pom.xml"), b_pom).unwrap(); let config = base.join("config"); - let host = Host::new(HostConfig { - config_dir: config.clone(), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..common::host_config(&base) }); host.open_project("main", &root).unwrap(); host.set_project_trust(&root, true, false).await.unwrap(); @@ -100,17 +90,7 @@ async fn reactor_module_beside_a_trusted_project_is_a_content_root_until_removed std::fs::write(root.join("pom.xml"), reactor("core../service-a")).unwrap(); std::fs::write(root.join("core/pom.xml"), "core").unwrap(); std::fs::write(service.join("pom.xml"), "service-a").unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(HostConfig { local_data_dir: base.join("local"), ..common::host_config(&base) }); host.open_project("main", &root).unwrap(); let project = || host.project("main").unwrap(); assert!(project().content_roots().is_empty(), "Restricted Mode does not widen the index"); diff --git a/crates/ide-host/tests/mcp.rs b/crates/ide-host/tests/mcp.rs index 287484527..f6a0094ac 100644 --- a/crates/ide-host/tests/mcp.rs +++ b/crates/ide-host/tests/mcp.rs @@ -1,3 +1,5 @@ +mod common; + use ide_core::{CancellationToken, ChangeSet, Diagnostic, IdeEvent, Pos, Range, Severity, TextChange}; use ide_host::mcp::{BackgroundProjects, FileProblems, FocusedEditor, Registry}; use ide_host::{Host, HostConfig}; @@ -25,18 +27,12 @@ impl Harness { let events = Arc::new(std::sync::Mutex::new(Vec::new())); let sink = events.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |_| { let events = sink.clone(); Arc::new(move |e| events.lock().unwrap().push(e)) }), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + local_data_dir: tmp.path().join("local"), + ..common::host_config(tmp.path()) })); host.open_project("main", &root).unwrap(); Self { host, root, tmp, events } diff --git a/crates/ide-host/tests/mcp_secrets.rs b/crates/ide-host/tests/mcp_secrets.rs index 04d153081..58cf64e6e 100644 --- a/crates/ide-host/tests/mcp_secrets.rs +++ b/crates/ide-host/tests/mcp_secrets.rs @@ -2,10 +2,11 @@ //! credential store; `settings.toml` keeps only their names. A project's own servers keep //! their values in the project's file, where the project shares them. +mod common; + use ide_agent::{McpKeyValue, McpScope, McpServer, McpServerInput}; -use ide_core::NullSink; use ide_core::settings::McpTransport; -use ide_host::{Host, HostConfig}; +use ide_host::Host; use ide_ssh::secrets::testing::{files_containing, use_memory_store}; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -13,17 +14,7 @@ use std::sync::Arc; const VALUE: &str = "mcp-value-0f3c9a"; fn host(dir: &Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: dir.join("config"), - data_dir: dir.join("data"), - local_data_dir: dir.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(dir))) } fn project(tmp: &tempfile::TempDir) -> PathBuf { diff --git a/crates/ide-host/tests/nav_inheritance.rs b/crates/ide-host/tests/nav_inheritance.rs index 4503fefb4..e9caa10f9 100644 --- a/crates/ide-host/tests/nav_inheritance.rs +++ b/crates/ide-host/tests/nav_inheritance.rs @@ -3,7 +3,9 @@ //! written in its source, so the UI can compute inheritance gutter markers without a //! language server's type-hierarchy provider. -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_host::{Host, ops}; use std::path::PathBuf; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -57,17 +59,7 @@ async fn open() -> Opened { std::fs::write(dep.join("dep.py"), "class DepBase:\n pass\n").unwrap(); let app = tmp.path().join("app"); - let host = Arc::new(Host::new(HostConfig { - config_dir: app.join("config"), - data_dir: app.join("data"), - local_data_dir: app.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(&app))); host.trust.decide(&root, true, false).unwrap(); ops::project::open(&host, WINDOW, &root).await.unwrap(); diff --git a/crates/ide-host/tests/open_project.rs b/crates/ide-host/tests/open_project.rs index 37ec7c417..d0ae18ec6 100644 --- a/crates/ide-host/tests/open_project.rs +++ b/crates/ide-host/tests/open_project.rs @@ -1,8 +1,9 @@ //! Opening the project a window is already opening reuses it: racing opens (a double //! click, a launch path and a restore) must not start a second index and language servers. -use ide_core::NullSink; -use ide_host::{Host, HostConfig}; +mod common; + +use ide_host::Host; use std::sync::{Arc, Barrier}; #[test] @@ -13,17 +14,7 @@ fn racing_opens_of_one_window_share_one_project() { std::fs::write(root.join("src/Main.java"), "class Main {}\n").unwrap(); let runtime = tokio::runtime::Builder::new_multi_thread().worker_threads(2).enable_all().build().unwrap(); let _guard = runtime.enter(); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: runtime.handle().clone(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(tmp.path()))); host.trust.decide(&root, true, false).unwrap(); let start = Arc::new(Barrier::new(4)); diff --git a/crates/ide-host/tests/plugin_data_tools.rs b/crates/ide-host/tests/plugin_data_tools.rs index bedf5da5a..145b51e76 100644 --- a/crates/ide-host/tests/plugin_data_tools.rs +++ b/crates/ide-host/tests/plugin_data_tools.rs @@ -1,4 +1,6 @@ //! Database and MCP calls through a real sandboxed API 1.4 component. +mod common; + use ide_core::{CancellationToken, IdeEvent, event::McpUiRequest}; use ide_host::{ Host, HostConfig, @@ -37,18 +39,12 @@ impl Harness { let events = Arc::new(Mutex::new(vec![])); let out = events.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| { let (w, out) = (w.to_owned(), out.clone()); Arc::new(move |e| out.lock().unwrap().push((w.clone(), e))) }), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + local_data_dir: tmp.path().join("local"), + ..common::host_config(tmp.path()) })); std::fs::write(root.join("db.sqlite"), "").unwrap(); host.open_project("main", &root).unwrap(); diff --git a/crates/ide-host/tests/plugin_diagnostics.rs b/crates/ide-host/tests/plugin_diagnostics.rs index dcf819ac5..fb71e57aa 100644 --- a/crates/ide-host/tests/plugin_diagnostics.rs +++ b/crates/ide-host/tests/plugin_diagnostics.rs @@ -1,4 +1,6 @@ //! Real Wasm provider dispatch and the document-edit path used locally and over RPC. +mod common; + use ide_core::{CancellationToken, ChangeSet, Diagnostic, IdeEvent, Pos, Range, TextChange}; use ide_host::plugins::{Consent, HostWorkspace, PluginEvent, PluginHost, set_editor_providers}; use ide_host::{Host, HostConfig, ops}; @@ -239,18 +241,11 @@ type Events = Arc>>; fn runtime_host(base: &Path, events: Events) -> Arc { Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |window| { let (events, window) = (events.clone(), window.to_owned()); Arc::new(move |event: IdeEvent| events.lock().push((window.clone(), event))) }), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(base) })) } @@ -434,17 +429,7 @@ async fn typing_is_debounced_versioned_and_scoped_to_document_project_and_window /// A host with a project open: `problems` and `decorations` need a workspace. fn harness(root: &Path) -> Arc { - let host = Arc::new(Host::new(HostConfig { - config_dir: root.join("config"), - data_dir: root.join("data"), - local_data_dir: root.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(HostConfig { local_data_dir: root.join("local"), ..common::host_config(root) })); host.open_project("main", root).unwrap(); host } diff --git a/crates/ide-host/tests/plugin_language_features.rs b/crates/ide-host/tests/plugin_language_features.rs index ccb6346ef..ffeb3d1dc 100644 --- a/crates/ide-host/tests/plugin_language_features.rs +++ b/crates/ide-host/tests/plugin_language_features.rs @@ -1,4 +1,6 @@ //! The API 1.4 fixture exercises every kind through the real component runtime and editor ops. +mod common; + use ide_core::{CancellationToken, Pos, Range, RequestId}; use ide_host::plugins::{Consent, HostWorkspace, PluginHost, set_editor_providers}; use ide_host::{Host, HostConfig, ops}; @@ -78,17 +80,8 @@ async fn editor_ops_merge_the_fixture_format_selection_and_execute_owned_command let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = + Arc::new(Host::new(HostConfig { local_data_dir: tmp.path().join("local"), ..common::host_config(tmp.path()) })); host.open_project("main", &root).unwrap(); let p = plugins(tmp.path()); p.set_workspace(Some(Arc::new(HostWorkspace(Arc::downgrade(&host))))); diff --git a/crates/ide-host/tests/plugin_refactoring.rs b/crates/ide-host/tests/plugin_refactoring.rs index 038d6e281..3dc2e7dd0 100644 --- a/crates/ide-host/tests/plugin_refactoring.rs +++ b/crates/ide-host/tests/plugin_refactoring.rs @@ -1,4 +1,6 @@ //! Indexed names use the same preview/apply/undo commands as language-server refactorings. +mod common; + use ide_core::{IdeEvent, Pos, RequestId, error::ErrorKind}; use ide_host::{ Host, HostConfig, ops, @@ -21,18 +23,12 @@ async fn indexed_usages_rename_preview_staleness_and_grouped_undo() { let events = Arc::new(Mutex::new(vec![])); let captured = events.clone(); let host = Host::new(HostConfig { - config_dir: root.join("config"), - data_dir: root.join("data"), - local_data_dir: root.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |_| { let events = captured.clone(); Arc::new(move |e| events.lock().push(e)) }), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + local_data_dir: root.join("local"), + ..common::host_config(&root) }); let project = host.open_light("main", &first).unwrap(); let doc = project.documents.open(&first).unwrap(); diff --git a/crates/ide-host/tests/plugin_server_commands.rs b/crates/ide-host/tests/plugin_server_commands.rs index 6b544688b..35c754a3a 100644 --- a/crates/ide-host/tests/plugin_server_commands.rs +++ b/crates/ide-host/tests/plugin_server_commands.rs @@ -1,6 +1,8 @@ //! `[[contributes.serverCommands]]` (plugin API 1.9): a command a language server hands to the //! client runs the plugin command that claims it. The fixture's command sends its argument //! back to the server (`mock/ran`), through the real component runtime and `language-servers`. +mod common; + use ide_host::plugins::{Consent, HostWorkspace, PluginHost, set_editor_providers}; use ide_host::{Host, HostConfig, ops}; use ide_jsonrpc::{Handler, Peer}; @@ -88,17 +90,8 @@ async fn a_command_the_server_leaves_to_the_client_runs_the_plugin_that_claims_i let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = + Arc::new(Host::new(HostConfig { local_data_dir: tmp.path().join("local"), ..common::host_config(tmp.path()) })); // Language servers start only in a trusted project. host.set_project_trust(&root, true, false).await.unwrap(); host.open_project("main", &root).unwrap(); diff --git a/crates/ide-host/tests/plugin_workbench.rs b/crates/ide-host/tests/plugin_workbench.rs index 2e01ecd05..ce0da0c49 100644 --- a/crates/ide-host/tests/plugin_workbench.rs +++ b/crates/ide-host/tests/plugin_workbench.rs @@ -1,3 +1,5 @@ +mod common; + use ide_core::{CancellationToken, Diagnostic, Pos, Range, Severity}; use ide_host::plugins::{HostWorkspace, PluginWorkspace}; use ide_host::{Host, HostConfig}; @@ -16,15 +18,8 @@ impl Harness { let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir_all(&root).unwrap(); let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), local_data_dir: tmp.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(tmp.path()) })); host.open_project("main", &root).unwrap(); host.open_project("second", &root).unwrap(); diff --git a/crates/ide-host/tests/plugins.rs b/crates/ide-host/tests/plugins.rs index a8a4523c4..4c289246e 100644 --- a/crates/ide-host/tests/plugins.rs +++ b/crates/ide-host/tests/plugins.rs @@ -5,6 +5,8 @@ //! `misbehave`) so tests need no wasm toolchain. Rebuild them with //! `plugins/build.sh ` after changing their source or `wit/`. +mod common; + use ide_core::error::ErrorKind; use ide_core::ipc_path::to_ipc; use ide_host::plugins::*; @@ -5703,15 +5705,8 @@ async fn web_ptys_are_capped_across_windows_and_end_with_the_plugin() { f.install(&sample("web-pty")); let root = tempfile::tempdir().unwrap(); let host = Arc::new(Host::new(HostConfig { - config_dir: root.path().join("config"), - data_dir: root.path().join("data"), local_data_dir: root.path().join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(root.path()) })); let spawn = |window: &str| { f.host.spawn_web_pty( diff --git a/crates/ide-host/tests/project_smoke.rs b/crates/ide-host/tests/project_smoke.rs index e0093964b..c743a69e8 100644 --- a/crates/ide-host/tests/project_smoke.rs +++ b/crates/ide-host/tests/project_smoke.rs @@ -7,7 +7,9 @@ //! java, kotlin and python jobs): //! `cargo test -p ide-host --test project_smoke -- --ignored`. -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_host::{Host, ops}; use ide_index::SymbolFilter; use ide_workspace::roots::RootKind; use std::path::{Path, PathBuf}; @@ -53,17 +55,7 @@ async fn open(fixture: &str) -> Opened { let root = dunce::canonicalize(tmp.path()).unwrap().join(fixture); copy_dir(&Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures").join(fixture), &root); let app = tmp.path().join("app"); - let host = Arc::new(Host::new(HostConfig { - config_dir: app.join("config"), - data_dir: app.join("data"), - local_data_dir: app.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(&app))); host.trust.decide(&root, true, false).unwrap(); ops::project::open(&host, WINDOW, &root).await.unwrap(); Opened { host, root, _tmp: tmp } diff --git a/crates/ide-host/tests/properties.rs b/crates/ide-host/tests/properties.rs index 4f9c6da28..07e804712 100644 --- a/crates/ide-host/tests/properties.rs +++ b/crates/ide-host/tests/properties.rs @@ -1,6 +1,8 @@ -use ide_core::{ChangeSet, NullSink, RequestId, TextChange}; +mod common; + +use ide_core::{ChangeSet, RequestId, TextChange}; use ide_host::{ - Host, HostConfig, + Host, ops::{doc, search, vcs}, }; use ide_search::{SearchQuery, SearchScope}; @@ -17,17 +19,7 @@ fn git(root: &Path, args: &[&str]) { } fn host(base: &Path) -> Host { - Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }) + Host::new(common::host_config(base)) } async fn find(host: &Host, paths: Vec, pattern: &str) -> Vec { diff --git a/crates/ide-host/tests/proxy.rs b/crates/ide-host/tests/proxy.rs index 423fb4994..71c980636 100644 --- a/crates/ide-host/tests/proxy.rs +++ b/crates/ide-host/tests/proxy.rs @@ -1,23 +1,14 @@ //! System Settings › HTTP Proxy: applied on write, the password kept out of settings.toml. -use ide_core::NullSink; +mod common; + use ide_core::proxy_settings::{ProxyMode, ProxyRoute, proxy}; -use ide_host::{Host, HostConfig, ops}; +use ide_host::{Host, ops}; use ide_workspace::SettingsScope; use std::sync::Arc; fn host(base: &std::path::Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(base))) } fn set(host: &Host, key: &str, value: &str) -> ide_core::settings::Settings { diff --git a/crates/ide-host/tests/remote_plugins.rs b/crates/ide-host/tests/remote_plugins.rs index c822c425e..83c7bfdcf 100644 --- a/crates/ide-host/tests/remote_plugins.rs +++ b/crates/ide-host/tests/remote_plugins.rs @@ -5,6 +5,8 @@ #![cfg(unix)] +mod common; + use ide_core::IdeEvent; use ide_host::plugins::remote_host::{ EVENT_NOTIFICATION, PackageSyncReport, PluginEventMessage, RemotePlugins, SECRET_REQUEST, SYNC_PACKAGES, @@ -139,15 +141,8 @@ async fn remote_projects_run_the_desktops_code_plugins_on_the_server() { let peer_slot = Arc::new(OnceLock::new()); let sink_peer = peer_slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink_peer.clone(), Some(w.to_owned()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(&base) })); let plugins = RemotePlugins::start(&base.join("data"), &host, peer_slot.clone()).unwrap(); plugins.host().set_program_path(path_var); @@ -260,15 +255,8 @@ async fn remote_projects_get_plugin_views_and_custom_editors() { let peer_slot = Arc::new(OnceLock::new()); let sink_peer = peer_slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink_peer.clone(), Some(w.to_owned()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(&base) })); let plugins = RemotePlugins::start(&base.join("data"), &host, peer_slot.clone()).unwrap(); plugins.host().set_program_path(path_var); @@ -382,15 +370,8 @@ async fn api14_remote_calls_keep_browser_listeners_and_secrets_on_the_desktop() let peer_slot = Arc::new(OnceLock::new()); let sink_peer = peer_slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink_peer.clone(), Some(w.into()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(&base) })); let plugins = RemotePlugins::start(&base.join("data"), &host, peer_slot.clone()).unwrap(); let mut dispatcher = Dispatcher::standard(); @@ -600,15 +581,8 @@ async fn api14_stage3_remote_terminal_pins_and_exit_events_stay_on_the_execution let peer_slot = Arc::new(OnceLock::new()); let sink_peer = peer_slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink_peer.clone(), Some(w.into()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(&base) })); let plugins = RemotePlugins::start(&base.join("data"), &host, peer_slot.clone()).unwrap(); plugins.host().set_program_path(path_var); @@ -850,15 +824,9 @@ async fn api14_database_sources_credentials_and_disable_lifetime_run_on_the_serv let slot = Arc::new(OnceLock::new()); let sink = slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("local"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink.clone(), Some(w.into()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + local_data_dir: base.join("local"), + ..common::host_config(&base) })); let plugins = RemotePlugins::start(&base.join("data"), &host, slot.clone()).unwrap(); let mut dispatcher = Dispatcher::standard(); @@ -947,17 +915,7 @@ async fn api14_database_sources_credentials_and_disable_lifetime_run_on_the_serv async fn command_rpc_fixture() -> (tempfile::TempDir, Arc, Peer, Arc) { let tmp = tempfile::tempdir().unwrap(); let peer_slot = Arc::new(OnceLock::new()); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_: IdeEvent| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(tmp.path()))); let plugins = RemotePlugins::start(&tmp.path().join("data"), &host, peer_slot.clone()).unwrap(); plugins.host().install_from_dir(&fixture("misbehave"), &Consent::all()).unwrap(); plugins.host().install_from_dir(&fixture("jobs"), &Consent::all()).unwrap(); diff --git a/crates/ide-host/tests/replace_all.rs b/crates/ide-host/tests/replace_all.rs index 8aaae9312..e1e9fe62d 100644 --- a/crates/ide-host/tests/replace_all.rs +++ b/crates/ide-host/tests/replace_all.rs @@ -1,8 +1,10 @@ //! Replace All when the search hit its match limit (#4083): every match in the //! scope is replaced, not just the listed ones. -use ide_core::{NullSink, Pos, RequestId}; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_core::{Pos, RequestId}; +use ide_host::{Host, ops}; use ide_search::{ReplaceEvent, ReplaceSummary, ReplaceTarget, SearchQuery}; use std::sync::{Arc, Mutex}; @@ -95,17 +97,7 @@ async fn replace_all_covers_matches_past_the_limit() { std::fs::create_dir_all(path.parent().unwrap()).unwrap(); std::fs::write(path, text).unwrap(); } - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); let targets = case @@ -158,17 +150,7 @@ async fn replace_all_saves_open_buffers_without_unsaved_changes() { for name in ["previewed.txt", "edited.txt", "closed.txt"] { std::fs::write(root.join(name), "TOKEN\n").unwrap(); } - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); let project = host.project("main").unwrap(); @@ -218,17 +200,7 @@ async fn replace_all_past_the_limit_keeps_to_the_search_context() { let root = base.join("project"); std::fs::create_dir_all(&root).unwrap(); std::fs::write(root.join("lib.rs"), &original).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); ops::search::replace_in_files( diff --git a/crates/ide-host/tests/rpc.rs b/crates/ide-host/tests/rpc.rs index 2a2028865..581ff6834 100644 --- a/crates/ide-host/tests/rpc.rs +++ b/crates/ide-host/tests/rpc.rs @@ -1,6 +1,8 @@ //! The remote protocol end to end: a server on one side of an in-memory pipe, //! a JSON-RPC client on the other. +mod common; + use ide_host::rpc::{self, ChannelMessage, Dispatcher, EventMessage, Invoke, ServerInfo}; use ide_host::{Host, HostConfig}; use ide_jsonrpc::{Handler, Peer}; @@ -54,15 +56,8 @@ async fn serves_projects_files_documents_search_and_runs() { let peer_slot = Arc::new(OnceLock::new()); let sink_peer = peer_slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink_peer.clone(), Some(w.to_owned()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(&base) })); let (client_io, server_io) = tokio::io::duplex(1 << 20); let (sr, sw) = tokio::io::split(server_io); @@ -355,15 +350,8 @@ async fn local_deployment_runs_on_the_project_host() { let slot = Arc::new(OnceLock::new()); let sink_slot = slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink_slot.clone(), Some(w.to_owned()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(tmp.path()) })); let dispatcher = Dispatcher::standard(); for cmd in [ @@ -465,17 +453,7 @@ async fn properties_conversion_through_remote_dispatch_without_a_remote_host() { let path = root.join("messages.properties"); std::fs::write(&path, r"value=\u4F60\u597D\uD83D\uDE00!").unwrap(); let peer_slot = Arc::new(OnceLock::new()); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(tmp.path()))); let (client_io, server_io) = tokio::io::duplex(1 << 20); let (sr, sw) = tokio::io::split(server_io); tokio::spawn(rpc::serve(host, Dispatcher::standard(), peer_slot, sr, sw)); @@ -533,17 +511,7 @@ async fn renames_a_branch_with_the_clients_argument_names() { git(&["-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "-m", "init"]); git(&["branch", "feature"]); let peer_slot = Arc::new(OnceLock::new()); - let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(tmp.path()))); let (client_io, server_io) = tokio::io::duplex(1 << 20); let (sr, sw) = tokio::io::split(server_io); tokio::spawn(rpc::serve(host, Dispatcher::standard(), peer_slot, sr, sw)); @@ -580,15 +548,8 @@ async fn serves_builtin_mcp_over_remote_dispatch_and_routes_ui_requests() { let peer_slot = Arc::new(OnceLock::new()); let sink_peer = peer_slot.clone(); let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: data_dir.clone(), - local_data_dir: data_dir.clone(), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |w| rpc::event_sink(sink_peer.clone(), Some(w.to_owned()))), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(&base) })); let server_exe = base.join("bin/openidea-server"); host.mcp.set_stdio_link(server_exe.clone()); diff --git a/crates/ide-host/tests/run_configs.rs b/crates/ide-host/tests/run_configs.rs index 7e3a04bc5..4281e2b47 100644 --- a/crates/ide-host/tests/run_configs.rs +++ b/crates/ide-host/tests/run_configs.rs @@ -1,19 +1,10 @@ -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_host::{Host, ops}; use std::sync::Arc; fn host(base: &std::path::Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(base))) } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] diff --git a/crates/ide-host/tests/search_encoding.rs b/crates/ide-host/tests/search_encoding.rs index 343daa5a3..14810d2f5 100644 --- a/crates/ide-host/tests/search_encoding.rs +++ b/crates/ide-host/tests/search_encoding.rs @@ -1,5 +1,7 @@ -use ide_core::{NullSink, RequestId}; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_core::RequestId; +use ide_host::{Host, ops}; use std::sync::{Arc, Mutex}; async fn find(host: &Host, pattern: &str) -> Vec { @@ -30,17 +32,7 @@ async fn find_in_files_decodes_closed_files_with_the_project_encoding() { std::fs::create_dir(&root).unwrap(); let text = "class CreditQuerySendUtils {\n //中文搜索验证 Chinese Chinese Chinese\n}\n"; std::fs::write(root.join("CreditQuerySendUtils.java"), ide_vfs::encode(text, "gbk", false).unwrap()).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); let project = host.open_project("main", &root).unwrap(); let mut defaults = project.documents.file_defaults(); diff --git a/crates/ide-host/tests/ssh_terminal.rs b/crates/ide-host/tests/ssh_terminal.rs index da891e588..89bc851b0 100644 --- a/crates/ide-host/tests/ssh_terminal.rs +++ b/crates/ide-host/tests/ssh_terminal.rs @@ -1,3 +1,5 @@ +mod common; + use ide_core::remote_settings::{SshAuth, SshConfiguration}; use ide_core::{IdeEvent, SharedSink}; use ide_docker::DockerEndpoint; @@ -46,17 +48,8 @@ async fn host_with_ssh_box(tmp: &Path, exec: ide_ssh::testing::ExecFn) -> (Arc Arc { - Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: environment, - })) + Arc::new(Host::new(HostConfig { project_environment: environment, ..common::host_config(base) })) } /// Each class against each window state: a trusted project, a Restricted one, and no project. diff --git a/crates/ide-host/tests/trust_git_binary.rs b/crates/ide-host/tests/trust_git_binary.rs index 24cbe5cc1..d26f16b42 100644 --- a/crates/ide-host/tests/trust_git_binary.rs +++ b/crates/ide-host/tests/trust_git_binary.rs @@ -1,24 +1,15 @@ //! Which git executable each window's repositories run. Its own test binary: the default //! executable (global settings) is process-wide. #![cfg(unix)] -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_host::{Host, ops}; use std::os::unix::fs::PermissionsExt; use std::path::Path; use std::sync::Arc; fn host(base: &Path) -> Arc { - Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })) + Arc::new(Host::new(common::host_config(base))) } /// A repository with `tools/git`: it appends a line to `marker`, waits while `gate` exists, diff --git a/crates/ide-host/tests/trust_vcs_sweep.rs b/crates/ide-host/tests/trust_vcs_sweep.rs index 36f1bcf34..6ad0c067b 100644 --- a/crates/ide-host/tests/trust_vcs_sweep.rs +++ b/crates/ide-host/tests/trust_vcs_sweep.rs @@ -1,14 +1,15 @@ //! Security audit lead 2: every `vcs_*` command Restricted Mode allows, run against a //! repository whose config names a program for a signed commit, an index read, an external //! diff, a clean filter and a missing object. None may run. -use ide_core::{NullSink, RequestId}; -use ide_host::{Host, HostConfig, catalogue::TrustClass, ops, ops::vcs}; +mod common; + +use ide_core::RequestId; +use ide_host::{Host, catalogue::TrustClass, ops, ops::vcs}; use std::collections::BTreeSet; use std::future::Future; use std::path::{Path, PathBuf}; use std::pin::Pin; use std::process::{Command, Stdio}; -use std::sync::Arc; /// Allowed in Restricted Mode and not swept: none of them starts git for the project. const NOT_THE_PROJECT_REPOSITORY: [&str; 8] = [ @@ -141,17 +142,7 @@ async fn restricted_vcs_commands_run_no_program_of_the_repository() { clear(&markers); let project = arm(&base.join("project"), &markers); let external = arm(&base.join("external"), &markers); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&project.root, false, false).unwrap(); clear(&markers); assert!(!host.open_project("main", &project.root).unwrap().is_trusted()); diff --git a/crates/ide-host/tests/unity.rs b/crates/ide-host/tests/unity.rs index 106674b04..41f90e270 100644 --- a/crates/ide-host/tests/unity.rs +++ b/crates/ide-host/tests/unity.rs @@ -1,5 +1,7 @@ -use ide_core::{NullSink, RequestId}; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_core::RequestId; +use ide_host::{Host, ops}; use std::{sync::Arc, time::Duration}; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -16,17 +18,7 @@ async fn opens_unity_without_generated_solutions_and_excludes_caches_from_the_in std::fs::write(root.join("Library/PackageCache/Cached.cs"), "class Cached {}\n").unwrap(); std::fs::write(root.join("Temp/Temporary.cs"), "class Temporary {}\n").unwrap(); std::fs::write(root.join("Logs/Editor.log"), "log\n").unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); let project = host.open_project("main", &root).unwrap(); let info = ops::project::info(&project); assert_eq!(info.name, "Game"); diff --git a/crates/ide-host/tests/vcs_documents.rs b/crates/ide-host/tests/vcs_documents.rs index 915d5083c..e9c450e93 100644 --- a/crates/ide-host/tests/vcs_documents.rs +++ b/crates/ide-host/tests/vcs_documents.rs @@ -1,5 +1,7 @@ -use ide_core::{ChangeSet, NullSink, TextChange}; -use ide_host::{Host, HostConfig, Project, ops::vcs}; +mod common; + +use ide_core::{ChangeSet, TextChange}; +use ide_host::{Host, Project, ops::vcs}; use std::{path::Path, process::Command, sync::Arc, time::Duration}; const ORIGINAL: &str = "SELECT *\nFROM patients\n\tLIMIT 10 OFFSET 0"; @@ -39,17 +41,7 @@ impl Fixture { std::fs::write(&path, OTHER).unwrap(); git(&root, &["commit", "-am", "other"]); git(&root, &["switch", "main"]); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); let project = host.open_project("main", &root).unwrap(); for _ in 0..500 { diff --git a/crates/ide-host/tests/vcs_encoding.rs b/crates/ide-host/tests/vcs_encoding.rs index 61203a5c4..70af8119b 100644 --- a/crates/ide-host/tests/vcs_encoding.rs +++ b/crates/ide-host/tests/vcs_encoding.rs @@ -1,6 +1,8 @@ -use ide_core::{ChangeSet, NullSink, TextChange}; -use ide_host::{Host, HostConfig, ops::vcs}; -use std::{path::Path, process::Command, sync::Arc, time::Duration}; +mod common; + +use ide_core::{ChangeSet, TextChange}; +use ide_host::{Host, ops::vcs}; +use std::{path::Path, process::Command, time::Duration}; fn git(root: &Path, args: &[&str]) { let out = Command::new("git").current_dir(root).args(args).output().unwrap(); @@ -25,17 +27,7 @@ async fn gbk_document_gutter_diff_stage_and_rollback_share_encoding() { std::fs::write(root.join("Utf8.java"), old).unwrap(); git(&root, &["add", "."]); git(&root, &["commit", "-m", "GBK Java"]); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); let project = host.open_project("main", &root).unwrap(); for _ in 0..500 { @@ -129,17 +121,7 @@ async fn a_directory_symlink_revision_is_its_target() { std::os::unix::fs::symlink("target", root.join("dir-link")).unwrap(); git(&root, &["add", "."]); git(&root, &["commit", "-m", "Add a directory symlink"]); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); let project = host.open_project("main", &root).unwrap(); for _ in 0..500 { diff --git a/crates/ide-host/tests/vcs_flow.rs b/crates/ide-host/tests/vcs_flow.rs index d29c17317..c142b0ae1 100644 --- a/crates/ide-host/tests/vcs_flow.rs +++ b/crates/ide-host/tests/vcs_flow.rs @@ -2,8 +2,10 @@ //! marked in the gutter, Local Changes and its diff, a commit in the log, a branch, a stash, and //! a merge that conflicts, resolved and committed. Open documents follow every step. +mod common; + use ide_core::DocId; -use ide_host::{Host, HostConfig, ops}; +use ide_host::{Host, ops}; use ide_vcs::{ChangeKind, CommitOptions, FileStatus, HunkKind, LogQuery}; use std::path::{Path, PathBuf}; use std::process::Command; @@ -55,17 +57,7 @@ impl Flow { } git(&root, &["add", "-A"]); git(&root, &["commit", "-q", "-m", "Initial commit"]); - let host = Arc::new(Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - })); + let host = Arc::new(Host::new(common::host_config(&base))); host.trust.decide(&root, true, false).unwrap(); let project = ops::project::open(&host, WINDOW, &root).await.unwrap(); for _ in 0..500 { diff --git a/crates/ide-host/tests/vcs_roots.rs b/crates/ide-host/tests/vcs_roots.rs index 65f39952e..c13f85d33 100644 --- a/crates/ide-host/tests/vcs_roots.rs +++ b/crates/ide-host/tests/vcs_roots.rs @@ -1,7 +1,8 @@ //! Repository-scoped patch operations must never fall back to the primary root. -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops::vcs}; -use std::{path::Path, process::Command, sync::Arc, time::Duration}; +mod common; + +use ide_host::{Host, ops::vcs}; +use std::{path::Path, process::Command, time::Duration}; fn git(root: &Path, args: &[&str]) -> String { let output = Command::new("git").current_dir(root).args(args).output().unwrap(); @@ -33,17 +34,7 @@ async fn patches_read_and_write_the_requested_repository() { git(root, &["commit", "-am", "change"]); revisions.push(git(root, &["rev-parse", "HEAD"])); } - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&project_root, true, false).unwrap(); let project = host.open_project("main", &project_root).unwrap(); for _ in 0..500 { @@ -521,17 +512,7 @@ async fn add_to_ignore_accepts_the_repositories_of_attached_projects() { std::fs::write(&own, "x").unwrap(); std::fs::write(&attached, "x").unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&project_root, true, false).unwrap(); host.trust.decide(&attached_root, true, false).unwrap(); let project = host.open_project("main", &project_root).unwrap(); diff --git a/crates/ide-host/tests/vcs_shelf_roots.rs b/crates/ide-host/tests/vcs_shelf_roots.rs index 7b3470815..1ddd12afc 100644 --- a/crates/ide-host/tests/vcs_shelf_roots.rs +++ b/crates/ide-host/tests/vcs_shelf_roots.rs @@ -1,7 +1,8 @@ //! Shelves retain their repository even when the project root is above or below it. -use ide_core::NullSink; -use ide_host::{Host, HostConfig, ops::vcs}; -use std::{path::Path, process::Command, sync::Arc, time::Duration}; +mod common; + +use ide_host::{Host, ops::vcs}; +use std::{path::Path, process::Command, time::Duration}; fn git(root: &Path, args: &[&str]) { let output = Command::new("git").current_dir(root).args(args).output().unwrap(); @@ -9,17 +10,7 @@ fn git(root: &Path, args: &[&str]) { } async fn open_project(base: &Path, root: &Path, repo_count: usize) -> Host { - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(base)); host.trust.decide(root, true, false).unwrap(); let project = host.open_project("main", root).unwrap(); for _ in 0..500 { diff --git a/crates/ide-host/tests/vcs_watcher_moved_repository.rs b/crates/ide-host/tests/vcs_watcher_moved_repository.rs index 656aeab2a..9d651434b 100644 --- a/crates/ide-host/tests/vcs_watcher_moved_repository.rs +++ b/crates/ide-host/tests/vcs_watcher_moved_repository.rs @@ -2,9 +2,10 @@ //! the folder brings no `.git` event of its own, so the watcher's "created path" is what the //! rescan has to answer to (the open scan already ran). -use ide_core::NullSink; -use ide_host::{Host, HostConfig}; -use std::{path::Path, sync::Arc, time::Duration}; +mod common; + +use ide_host::Host; +use std::{path::Path, time::Duration}; fn git_init(dir: &Path) { std::fs::create_dir_all(dir).unwrap(); @@ -30,17 +31,7 @@ async fn moving_a_repository_into_the_project_registers_it() { let prepared = base.join("prepared"); git_init(&prepared); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); let project = host.open_project("main", &root).unwrap(); // The scan on project open runs in the background: wait for it before moving anything in. diff --git a/crates/ide-host/tests/vcs_worktrees.rs b/crates/ide-host/tests/vcs_worktrees.rs index 51d14a1ce..713c724a5 100644 --- a/crates/ide-host/tests/vcs_worktrees.rs +++ b/crates/ide-host/tests/vcs_worktrees.rs @@ -1,5 +1,7 @@ -use ide_core::{NullSink, RequestId}; -use ide_host::{Host, HostConfig, Project, ops::vcs}; +mod common; + +use ide_core::RequestId; +use ide_host::{Host, Project, ops::vcs}; use std::{path::PathBuf, process::Command, sync::Arc, time::Duration}; fn git(root: &std::path::Path, args: &[&str]) { @@ -38,17 +40,7 @@ impl Fixture { std::fs::write(root.join("file.txt"), "original\n").unwrap(); git(&root, &["add", "."]); git(&root, &["commit", "-m", "original"]); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); let project = host.open_project("main", &root).unwrap(); wait_for_repos(&project, 1).await; diff --git a/crates/ide-host/tests/workspace_edits.rs b/crates/ide-host/tests/workspace_edits.rs index ea2886fc8..3030cca2f 100644 --- a/crates/ide-host/tests/workspace_edits.rs +++ b/crates/ide-host/tests/workspace_edits.rs @@ -1,3 +1,5 @@ +mod common; + use ide_core::{IdeEvent, SharedSink, WorkspaceEdit, error::ErrorKind}; use ide_host::{Host, HostConfig, ops}; use parking_lot::Mutex; @@ -18,15 +20,9 @@ async fn preview_apply_and_grouped_undo_use_the_shared_host_commands() { Arc::new(move |event| events.lock().push(event)) }; let host = Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), local_data_dir: tmp.path().join("local-data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), sink_for: Box::new(move |_| sink.clone()), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(tmp.path()) }); host.open_light("main", &first).unwrap(); let info = ops::doc::doc_open(&host, "main", first.clone()).await.unwrap(); @@ -96,15 +92,8 @@ async fn contended_version_reads_do_not_block_the_async_worker() { let file = tmp.path().join("main.txt"); std::fs::write(&file, "old").unwrap(); let host = Arc::new(Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), local_data_dir: tmp.path().join("local-data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(ide_core::NullSink)), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, + ..common::host_config(tmp.path()) })); let project = host.open_light("main", &file).unwrap(); let doc = project.documents.open(&file).unwrap().id; @@ -182,17 +171,8 @@ async fn code_actions_skip_a_command_no_server_provides_after_their_edit() { let tmp = tempfile::tempdir().unwrap(); let file = tmp.path().join("imports.txt"); std::fs::write(&file, "unused\nused\n").unwrap(); - let host = Host::new(HostConfig { - config_dir: tmp.path().join("config"), - data_dir: tmp.path().join("data"), - local_data_dir: tmp.path().join("local-data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(|_| {})), - owner: |window| window, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = + Host::new(HostConfig { local_data_dir: tmp.path().join("local-data"), ..common::host_config(tmp.path()) }); host.open_light("main", &file).unwrap(); let info = ops::doc::doc_open(&host, "main", file.clone()).await.unwrap(); // Optimize Imports as vtsls offers it: the edit, then a command its client runs itself. diff --git a/crates/ide-host/tests/workspaces.rs b/crates/ide-host/tests/workspaces.rs index b0fb69a49..ab1ab71e0 100644 --- a/crates/ide-host/tests/workspaces.rs +++ b/crates/ide-host/tests/workspaces.rs @@ -1,5 +1,7 @@ -use ide_core::{ChangeSet, NullSink, RequestId, TextChange}; -use ide_host::{Host, HostConfig, ops}; +mod common; + +use ide_core::{ChangeSet, RequestId, TextChange}; +use ide_host::{Host, ops}; use ide_workspace::workspace::Workspace; use std::{ sync::{Arc, Mutex}, @@ -72,17 +74,7 @@ done .set(SettingsScope::Global, &format!("languageServers.{server}.enabled"), serde_json::json!(false)) .unwrap(); } - let host = Host::new(HostConfig { - config_dir, - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); for root in roots { host.trust.decide(root, true, false).unwrap(); } @@ -120,17 +112,7 @@ async fn linked_projects_share_navigation_but_keep_files_repositories_and_run_di } let root = base.join("workspace"); Workspace::save(&root, "Full stack", vec![roots[0].clone()], true).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); std::fs::write(root.join("internal-needle.txt"), "needle").unwrap(); host.trust.decide(&root, true, false).unwrap(); for member in &roots { @@ -224,17 +206,7 @@ async fn a_project_attached_inside_the_root_is_searched_and_indexed_once() { std::fs::write(root.join("main.txt"), "needle\n").unwrap(); std::fs::write(ignored.join("feature.txt"), "needle\n").unwrap(); std::fs::write(covered.join("lib.txt"), "needle\n").unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); for dir in [&root, &ignored, &covered] { host.trust.decide(dir, true, false).unwrap(); } @@ -285,17 +257,7 @@ async fn python_effective_interpreter_falls_back_to_the_primary_project() { std::fs::create_dir_all(member.join("src")).unwrap(); // The primary project with an attached folder (the "attach" flow, not a container workspace). Workspace::attach(&primary, "Primary", vec![primary.clone(), member.clone()]).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&primary, true, false).unwrap(); host.trust.decide(&member, true, false).unwrap(); host.open_project("main", &primary).unwrap(); @@ -350,17 +312,7 @@ async fn php_language_level_follows_the_member_of_the_file() { ide_workspace::SettingsStore::load(&config_dir, Some(&legacy)) .set(ide_workspace::SettingsScope::Project, "languages.php.languageLevel", "8.3".into()) .unwrap(); - let host = Host::new(HostConfig { - config_dir, - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&root, true, false).unwrap(); host.open_project("main", &root).unwrap(); let found = |version: &str, source| Some(PhpLanguageLevel { version: version.into(), source }); @@ -393,17 +345,7 @@ async fn build_tool_availability_follows_workspace_members_and_trust() { } let root = base.join("workspace"); Workspace::save(&root, "Build tools", members.clone(), true).unwrap(); - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); for member in &members { host.trust.decide(member, true, false).unwrap(); } @@ -432,17 +374,7 @@ async fn attach_and_detach_preserve_the_primary_project_session() { std::fs::write(root.join("same.txt"), "needle").unwrap(); std::fs::write(root.join("package.json"), r#"{"scripts":{"test":"echo test"}}"#).unwrap(); } - let host = Host::new(HostConfig { - config_dir: base.join("config"), - data_dir: base.join("data"), - local_data_dir: base.join("data"), - languages: Arc::new(ide_language::LanguageRegistry::load(None).unwrap()), - syntax: Arc::default(), - sink_for: Box::new(|_| Arc::new(NullSink)), - owner: |w| w, - runtime: tokio::runtime::Handle::current(), - project_environment: false, - }); + let host = Host::new(common::host_config(&base)); host.trust.decide(&roots[0], true, false).unwrap(); let project = host.open_project("main", &roots[0]).unwrap(); assert!(project.index.wait_idle(Duration::from_secs(10)));