diff --git a/Cargo.lock b/Cargo.lock index 92a729c41c9..d1892b76899 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,6 @@ dependencies = [ "span", "stdx", "syntax", - "test-utils", "triomphe", "vfs", ] @@ -519,6 +518,7 @@ dependencies = [ "span", "stdx", "syntax", + "test-fixture", "test-utils", "tracing", "triomphe", @@ -546,7 +546,6 @@ dependencies = [ "span", "stdx", "syntax", - "test-utils", "tracing", "triomphe", "tt", @@ -584,6 +583,7 @@ dependencies = [ "smallvec", "stdx", "syntax", + "test-fixture", "test-utils", "tracing", "tracing-subscriber", @@ -627,6 +627,7 @@ dependencies = [ "smallvec", "stdx", "syntax", + "test-fixture", "test-utils", "text-edit", "toolchain", @@ -650,6 +651,7 @@ dependencies = [ "sourcegen", "stdx", "syntax", + "test-fixture", "test-utils", "text-edit", ] @@ -669,6 +671,7 @@ dependencies = [ "smallvec", "stdx", "syntax", + "test-fixture", "test-utils", "text-edit", ] @@ -700,6 +703,7 @@ dependencies = [ "span", "stdx", "syntax", + "test-fixture", "test-utils", "text-edit", "tracing", @@ -724,6 +728,7 @@ dependencies = [ "sourcegen", "stdx", "syntax", + "test-fixture", "test-utils", "text-edit", ] @@ -741,6 +746,7 @@ dependencies = [ "parser", "stdx", "syntax", + "test-fixture", "test-utils", "text-edit", "triomphe", @@ -1543,6 +1549,7 @@ dependencies = [ "sourcegen", "stdx", "syntax", + "test-fixture", "test-utils", "tikv-jemallocator", "toolchain", @@ -1815,6 +1822,20 @@ dependencies = [ "ungrammar", ] +[[package]] +name = "test-fixture" +version = "0.0.0" +dependencies = [ + "base-db", + "cfg", + "hir-expand", + "rustc-hash", + "span", + "stdx", + "test-utils", + "tt", +] + [[package]] name = "test-utils" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index f1f61d8ec7c..fdca4f6d160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,11 +70,9 @@ proc-macro-srv = { path = "./crates/proc-macro-srv", version = "0.0.0" } proc-macro-srv-cli = { path = "./crates/proc-macro-srv-cli", version = "0.0.0" } profile = { path = "./crates/profile", version = "0.0.0" } project-model = { path = "./crates/project-model", version = "0.0.0" } -sourcegen = { path = "./crates/sourcegen", version = "0.0.0" } span = { path = "./crates/span", version = "0.0.0" } stdx = { path = "./crates/stdx", version = "0.0.0" } syntax = { path = "./crates/syntax", version = "0.0.0" } -test-utils = { path = "./crates/test-utils", version = "0.0.0" } text-edit = { path = "./crates/text-edit", version = "0.0.0" } toolchain = { path = "./crates/toolchain", version = "0.0.0" } tt = { path = "./crates/tt", version = "0.0.0" } @@ -84,6 +82,9 @@ rustc-dependencies = { path = "./crates/rustc-dependencies", version = "0.0.0" } # local crates that aren't published to crates.io. These should not have versions. proc-macro-test = { path = "./crates/proc-macro-test" } +sourcegen = { path = "./crates/sourcegen" } +test-fixture = { path = "./crates/test-fixture" } +test-utils = { path = "./crates/test-utils" } # In-tree crates that are published separately and follow semver. See lib/README.md line-index = { version = "0.1.1" } @@ -94,8 +95,11 @@ lsp-server = { version = "0.7.4" } anyhow = "1.0.75" bitflags = "2.4.1" cargo_metadata = "0.18.1" +command-group = "2.0.1" +crossbeam-channel = "0.5.8" dissimilar = "1.0.7" either = "1.9.0" +expect-test = "1.4.0" hashbrown = { version = "0.14", features = [ "inline-more", ], default-features = false } @@ -125,5 +129,6 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features = triomphe = { version = "0.1.10", default-features = false, features = ["std"] } xshell = "0.2.5" + # We need to freeze the version of the crate, as the raw-api feature is considered unstable dashmap = { version = "=5.5.3", features = ["raw-api"] } diff --git a/crates/base-db/Cargo.toml b/crates/base-db/Cargo.toml index a8ff97bdedd..371d6ee74b9 100644 --- a/crates/base-db/Cargo.toml +++ b/crates/base-db/Cargo.toml @@ -22,6 +22,5 @@ cfg.workspace = true profile.workspace = true stdx.workspace = true syntax.workspace = true -test-utils.workspace = true vfs.workspace = true span.workspace = true diff --git a/crates/cfg/Cargo.toml b/crates/cfg/Cargo.toml index 4324584df39..a90dec6b7d9 100644 --- a/crates/cfg/Cargo.toml +++ b/crates/cfg/Cargo.toml @@ -12,7 +12,7 @@ rust-version.workspace = true doctest = false [dependencies] -rustc-hash = "1.1.0" +rustc-hash.workspace = true # locals deps tt.workspace = true diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml index 4322d2d966a..6f91ea31bb2 100644 --- a/crates/flycheck/Cargo.toml +++ b/crates/flycheck/Cargo.toml @@ -13,12 +13,12 @@ doctest = false [dependencies] cargo_metadata.workspace = true -crossbeam-channel = "0.5.8" +crossbeam-channel.workspace = true tracing.workspace = true -rustc-hash = "1.1.0" +rustc-hash.workspace = true serde_json.workspace = true serde.workspace = true -command-group = "2.0.1" +command-group.workspace = true # local deps paths.workspace = true diff --git a/crates/hir-def/Cargo.toml b/crates/hir-def/Cargo.toml index 7ebaffcc13d..8348003cdc6 100644 --- a/crates/hir-def/Cargo.toml +++ b/crates/hir-def/Cargo.toml @@ -23,7 +23,7 @@ indexmap.workspace = true itertools.workspace = true la-arena.workspace = true once_cell = "1.17.0" -rustc-hash = "1.1.0" +rustc-hash.workspace = true tracing.workspace = true smallvec.workspace = true hashbrown.workspace = true @@ -46,10 +46,11 @@ span.workspace = true [dev-dependencies] -expect-test = "1.4.0" +expect-test.workspace = true # local deps test-utils.workspace = true +test-fixture.workspace = true [features] in-rust-tree = ["rustc-dependencies/in-rust-tree"] diff --git a/crates/hir-def/src/body/scope.rs b/crates/hir-def/src/body/scope.rs index 9e1f21c5480..ab623250d40 100644 --- a/crates/hir-def/src/body/scope.rs +++ b/crates/hir-def/src/body/scope.rs @@ -268,8 +268,9 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope #[cfg(test)] mod tests { use base_db::{FileId, SourceDatabase}; - use hir_expand::{fixture::WithFixture, name::AsName, InFile}; + use hir_expand::{name::AsName, InFile}; use syntax::{algo::find_node_at_offset, ast, AstNode}; + use test_fixture::WithFixture; use test_utils::{assert_eq_text, extract_offset}; use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId}; diff --git a/crates/hir-def/src/body/tests.rs b/crates/hir-def/src/body/tests.rs index 5e78685b10e..a76ddffb411 100644 --- a/crates/hir-def/src/body/tests.rs +++ b/crates/hir-def/src/body/tests.rs @@ -2,7 +2,7 @@ mod block; use base_db::SourceDatabase; use expect_test::{expect, Expect}; -use hir_expand::fixture::WithFixture; +use test_fixture::WithFixture; use crate::{test_db::TestDB, ModuleDefId}; diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs index 95339201776..4737b48703d 100644 --- a/crates/hir-def/src/find_path.rs +++ b/crates/hir-def/src/find_path.rs @@ -585,8 +585,9 @@ fn find_local_import_locations( #[cfg(test)] mod tests { - use hir_expand::{db::ExpandDatabase, fixture::WithFixture}; + use hir_expand::db::ExpandDatabase; use syntax::ast::AstNode; + use test_fixture::WithFixture; use crate::test_db::TestDB; diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs index 911511a3ba6..0d3014bce27 100644 --- a/crates/hir-def/src/import_map.rs +++ b/crates/hir-def/src/import_map.rs @@ -475,7 +475,7 @@ pub fn search_dependencies( mod tests { use base_db::{SourceDatabase, Upcast}; use expect_test::{expect, Expect}; - use hir_expand::fixture::WithFixture; + use test_fixture::WithFixture; use crate::{db::DefDatabase, test_db::TestDB, ItemContainerId, Lookup}; diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs index bec8e78ac94..f97ae0d8e43 100644 --- a/crates/hir-def/src/item_tree/tests.rs +++ b/crates/hir-def/src/item_tree/tests.rs @@ -1,5 +1,5 @@ use expect_test::{expect, Expect}; -use hir_expand::fixture::WithFixture; +use test_fixture::WithFixture; use crate::{db::DefDatabase, test_db::TestDB}; diff --git a/crates/hir-def/src/macro_expansion_tests/mod.rs b/crates/hir-def/src/macro_expansion_tests/mod.rs index 1d690d2575e..a25f2d29220 100644 --- a/crates/hir-def/src/macro_expansion_tests/mod.rs +++ b/crates/hir-def/src/macro_expansion_tests/mod.rs @@ -20,7 +20,6 @@ use base_db::SourceDatabase; use expect_test::Expect; use hir_expand::{ db::ExpandDatabase, - fixture::WithFixture, proc_macro::{ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind}, span_map::SpanMapRef, InFile, MacroFileId, MacroFileIdExt, @@ -33,6 +32,7 @@ use syntax::{ SyntaxKind::{COMMENT, EOF, IDENT, LIFETIME_IDENT}, SyntaxNode, T, }; +use test_fixture::WithFixture; use crate::{ db::DefDatabase, diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 0f3dbdfd416..71071b45128 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -2370,7 +2370,7 @@ impl ModCollector<'_, '_> { #[cfg(test)] mod tests { use base_db::SourceDatabase; - use hir_expand::fixture::WithFixture; + use test_fixture::WithFixture; use crate::{db::DefDatabase, test_db::TestDB}; diff --git a/crates/hir-def/src/nameres/tests.rs b/crates/hir-def/src/nameres/tests.rs index b950234212f..17e82dc16c4 100644 --- a/crates/hir-def/src/nameres/tests.rs +++ b/crates/hir-def/src/nameres/tests.rs @@ -6,7 +6,7 @@ mod primitives; use base_db::SourceDatabase; use expect_test::{expect, Expect}; -use hir_expand::fixture::WithFixture; +use test_fixture::WithFixture; use triomphe::Arc; use crate::{db::DefDatabase, nameres::DefMap, test_db::TestDB}; diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs index 78cb78e833e..6efced02718 100644 --- a/crates/hir-def/src/nameres/tests/incremental.rs +++ b/crates/hir-def/src/nameres/tests/incremental.rs @@ -1,11 +1,8 @@ use base_db::{SourceDatabase, SourceDatabaseExt}; +use test_fixture::WithFixture; use triomphe::Arc; -use crate::{ - db::DefDatabase, - nameres::tests::{TestDB, WithFixture}, - AdtId, ModuleDefId, -}; +use crate::{db::DefDatabase, nameres::tests::TestDB, AdtId, ModuleDefId}; fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) { let (mut db, pos) = TestDB::with_position(ra_fixture_initial); diff --git a/crates/hir-def/src/nameres/tests/macros.rs b/crates/hir-def/src/nameres/tests/macros.rs index e64fa0b46f1..48fe43450a7 100644 --- a/crates/hir-def/src/nameres/tests/macros.rs +++ b/crates/hir-def/src/nameres/tests/macros.rs @@ -1,6 +1,12 @@ -use super::*; +use expect_test::expect; +use test_fixture::WithFixture; + use itertools::Itertools; +use crate::nameres::tests::check; + +use super::*; + #[test] fn macro_rules_are_globally_visible() { check( diff --git a/crates/hir-expand/Cargo.toml b/crates/hir-expand/Cargo.toml index b39f0907364..e8a8f3ee073 100644 --- a/crates/hir-expand/Cargo.toml +++ b/crates/hir-expand/Cargo.toml @@ -15,7 +15,7 @@ doctest = false cov-mark = "2.0.0-pre.1" tracing.workspace = true either.workspace = true -rustc-hash = "1.1.0" +rustc-hash.workspace = true la-arena.workspace = true itertools.workspace = true hashbrown.workspace = true @@ -33,7 +33,6 @@ tt.workspace = true mbe.workspace = true limit.workspace = true span.workspace = true -test-utils.workspace = true [dev-dependencies] expect-test = "1.4.0" diff --git a/crates/hir-expand/src/change.rs b/crates/hir-expand/src/change.rs new file mode 100644 index 00000000000..67b7df198e9 --- /dev/null +++ b/crates/hir-expand/src/change.rs @@ -0,0 +1,42 @@ +//! Defines a unit of change that can applied to the database to get the next +//! state. Changes are transactional. +use base_db::{salsa::Durability, CrateGraph, FileChange, SourceDatabaseExt, SourceRoot}; +use span::FileId; +use triomphe::Arc; + +use crate::{db::ExpandDatabase, proc_macro::ProcMacros}; + +#[derive(Debug, Default)] +pub struct Change { + pub source_change: FileChange, + pub proc_macros: Option, +} + +impl Change { + pub fn new() -> Self { + Self::default() + } + + pub fn apply(self, db: &mut (impl ExpandDatabase + SourceDatabaseExt)) { + self.source_change.apply(db); + if let Some(proc_macros) = self.proc_macros { + db.set_proc_macros_with_durability(Arc::new(proc_macros), Durability::HIGH); + } + } + + pub fn change_file(&mut self, file_id: FileId, new_text: Option>) { + self.source_change.change_file(file_id, new_text) + } + + pub fn set_crate_graph(&mut self, graph: CrateGraph) { + self.source_change.set_crate_graph(graph) + } + + pub fn set_proc_macros(&mut self, proc_macros: ProcMacros) { + self.proc_macros = Some(proc_macros); + } + + pub fn set_roots(&mut self, roots: Vec) { + self.source_change.set_roots(roots) + } +} diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index 5496f2d661b..1f91e0e6692 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -14,7 +14,7 @@ pub mod builtin_fn_macro; pub mod db; pub mod eager; pub mod files; -pub mod fixture; +pub mod change; pub mod hygiene; pub mod mod_path; pub mod name; diff --git a/crates/hir-ty/Cargo.toml b/crates/hir-ty/Cargo.toml index bbcb76a43ff..c498d50af50 100644 --- a/crates/hir-ty/Cargo.toml +++ b/crates/hir-ty/Cargo.toml @@ -21,7 +21,7 @@ ena = "0.14.0" either.workspace = true oorandom = "11.1.3" tracing.workspace = true -rustc-hash = "1.1.0" +rustc-hash.workspace = true scoped-tls = "1.0.0" chalk-solve = { version = "0.95.0", default-features = false } chalk-ir = "0.95.0" @@ -54,6 +54,7 @@ project-model = { path = "../project-model" } # local deps test-utils.workspace = true +test-fixture.workspace = true [features] in-rust-tree = ["rustc-dependencies/in-rust-tree"] diff --git a/crates/hir-ty/src/consteval/tests.rs b/crates/hir-ty/src/consteval/tests.rs index 518e34b4d77..ac82208708a 100644 --- a/crates/hir-ty/src/consteval/tests.rs +++ b/crates/hir-ty/src/consteval/tests.rs @@ -1,7 +1,7 @@ use base_db::FileId; use chalk_ir::Substitution; use hir_def::db::DefDatabase; -use hir_expand::fixture::WithFixture; +use test_fixture::WithFixture; use test_utils::skip_slow_tests; use crate::{ diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs index f8b55ae4d06..9937113685c 100644 --- a/crates/hir-ty/src/layout/tests.rs +++ b/crates/hir-ty/src/layout/tests.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use chalk_ir::{AdtId, TyKind}; use either::Either; use hir_def::db::DefDatabase; -use hir_expand::fixture::WithFixture; +use test_fixture::WithFixture; use triomphe::Arc; use crate::{ diff --git a/crates/hir-ty/src/mir/eval/tests.rs b/crates/hir-ty/src/mir/eval/tests.rs index b902af7c87c..b0f929279a5 100644 --- a/crates/hir-ty/src/mir/eval/tests.rs +++ b/crates/hir-ty/src/mir/eval/tests.rs @@ -1,7 +1,7 @@ use base_db::FileId; use hir_def::db::DefDatabase; -use hir_expand::fixture::WithFixture; use syntax::{TextRange, TextSize}; +use test_fixture::WithFixture; use crate::{db::HirDatabase, test_db::TestDB, Interner, Substitution}; diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs index 0ac8f796fd5..c8cc61cc21b 100644 --- a/crates/hir-ty/src/tests.rs +++ b/crates/hir-ty/src/tests.rs @@ -23,13 +23,14 @@ use hir_def::{ src::HasSource, AssocItemId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleDefId, }; -use hir_expand::{db::ExpandDatabase, fixture::WithFixture, InFile}; +use hir_expand::{db::ExpandDatabase, InFile}; use once_cell::race::OnceBool; use stdx::format_to; use syntax::{ ast::{self, AstNode, HasName}, SyntaxNode, }; +use test_fixture::WithFixture; use tracing_subscriber::{layer::SubscriberExt, Registry}; use tracing_tree::HierarchicalLayer; use triomphe::Arc; diff --git a/crates/hir-ty/src/tests/incremental.rs b/crates/hir-ty/src/tests/incremental.rs index e21d74bf5ba..82d934009f3 100644 --- a/crates/hir-ty/src/tests/incremental.rs +++ b/crates/hir-ty/src/tests/incremental.rs @@ -1,5 +1,5 @@ use base_db::SourceDatabaseExt; -use hir_expand::fixture::WithFixture; +use test_fixture::WithFixture; use triomphe::Arc; use crate::{db::HirDatabase, test_db::TestDB}; diff --git a/crates/hir/Cargo.toml b/crates/hir/Cargo.toml index 4c1dfbc294e..a234b2d1f64 100644 --- a/crates/hir/Cargo.toml +++ b/crates/hir/Cargo.toml @@ -12,7 +12,7 @@ rust-version.workspace = true doctest = false [dependencies] -rustc-hash = "1.1.0" +rustc-hash.workspace = true either.workspace = true arrayvec = "0.7.2" itertools.workspace = true diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 5096cf2e9c8..ec15aad1c49 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -125,7 +125,7 @@ pub use { }, hir_expand::{ attrs::{Attr, AttrId}, - fixture::{Change, ChangeFixture, WithFixture}, + change::Change, hygiene::{marks_rev, SyntaxContextExt}, name::{known, Name}, proc_macro::ProcMacros, diff --git a/crates/ide-assists/Cargo.toml b/crates/ide-assists/Cargo.toml index a622ec1a953..69d98fd78fd 100644 --- a/crates/ide-assists/Cargo.toml +++ b/crates/ide-assists/Cargo.toml @@ -31,6 +31,7 @@ expect-test = "1.4.0" # local deps test-utils.workspace = true +test-fixture.workspace = true sourcegen.workspace = true [features] diff --git a/crates/ide-assists/src/handlers/auto_import.rs b/crates/ide-assists/src/handlers/auto_import.rs index 5348667981e..1f785b5d0a8 100644 --- a/crates/ide-assists/src/handlers/auto_import.rs +++ b/crates/ide-assists/src/handlers/auto_import.rs @@ -280,8 +280,9 @@ fn module_distance_heuristic(db: &dyn HirDatabase, current: &Module, item: &Modu mod tests { use super::*; - use hir::{Semantics, WithFixture}; + use hir::Semantics; use ide_db::{assists::AssistResolveStrategy, base_db::FileRange, RootDatabase}; + use test_fixture::WithFixture; use crate::tests::{ check_assist, check_assist_by_label, check_assist_not_applicable, check_assist_target, diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 87332d896a3..977c8380ac4 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -3,7 +3,7 @@ mod generated; mod sourcegen; use expect_test::expect; -use hir::{Semantics, WithFixture}; +use hir::Semantics; use ide_db::{ base_db::{FileId, FileRange, SourceDatabaseExt}, imports::insert_use::{ImportGranularity, InsertUseConfig}, @@ -12,6 +12,7 @@ use ide_db::{ }; use stdx::{format_to, trim_indent}; use syntax::TextRange; +use test_fixture::WithFixture; use test_utils::{assert_eq_text, extract_offset}; use crate::{ diff --git a/crates/ide-assists/src/utils/suggest_name.rs b/crates/ide-assists/src/utils/suggest_name.rs index 4dca23abe99..2f1b47b4b4b 100644 --- a/crates/ide-assists/src/utils/suggest_name.rs +++ b/crates/ide-assists/src/utils/suggest_name.rs @@ -275,8 +275,8 @@ fn from_field_name(expr: &ast::Expr) -> Option { #[cfg(test)] mod tests { - use hir::WithFixture; use ide_db::base_db::FileRange; + use test_fixture::WithFixture; use super::*; diff --git a/crates/ide-completion/Cargo.toml b/crates/ide-completion/Cargo.toml index 60f90a41b96..f7fec3cf773 100644 --- a/crates/ide-completion/Cargo.toml +++ b/crates/ide-completion/Cargo.toml @@ -35,3 +35,4 @@ expect-test = "1.4.0" # local deps test-utils.workspace = true +test-fixture.workspace = true diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs index dfaa2588cf4..f13754e2ded 100644 --- a/crates/ide-completion/src/tests.rs +++ b/crates/ide-completion/src/tests.rs @@ -24,7 +24,7 @@ mod use_tree; mod visibility; use expect_test::Expect; -use hir::{ChangeFixture, PrefixKind}; +use hir::PrefixKind; use ide_db::{ base_db::{FileLoader, FilePosition}, imports::insert_use::{ImportGranularity, InsertUseConfig}, @@ -32,6 +32,7 @@ use ide_db::{ }; use itertools::Itertools; use stdx::{format_to, trim_indent}; +use test_fixture::ChangeFixture; use test_utils::assert_eq_text; use crate::{ diff --git a/crates/ide-db/Cargo.toml b/crates/ide-db/Cargo.toml index e14117034f5..07309d37da8 100644 --- a/crates/ide-db/Cargo.toml +++ b/crates/ide-db/Cargo.toml @@ -16,7 +16,7 @@ cov-mark = "2.0.0-pre.1" tracing.workspace = true rayon.workspace = true fst = { version = "0.4.7", default-features = false } -rustc-hash = "1.1.0" +rustc-hash.workspace = true once_cell = "1.17.0" either.workspace = true itertools.workspace = true @@ -48,4 +48,5 @@ xshell.workspace = true # local deps test-utils.workspace = true +test-fixture.workspace = true sourcegen.workspace = true diff --git a/crates/ide-db/src/apply_change.rs b/crates/ide-db/src/apply_change.rs index 0b22143126e..db6cd128e83 100644 --- a/crates/ide-db/src/apply_change.rs +++ b/crates/ide-db/src/apply_change.rs @@ -11,7 +11,7 @@ use profile::{memory_usage, Bytes}; use rustc_hash::FxHashSet; use triomphe::Arc; -use crate::{fixture::Change, symbol_index::SymbolsDatabase, RootDatabase}; +use crate::{symbol_index::SymbolsDatabase, Change, RootDatabase}; impl RootDatabase { pub fn request_cancellation(&mut self) { diff --git a/crates/ide-db/src/imports/insert_use/tests.rs b/crates/ide-db/src/imports/insert_use/tests.rs index 942d262ddf6..a3abce89642 100644 --- a/crates/ide-db/src/imports/insert_use/tests.rs +++ b/crates/ide-db/src/imports/insert_use/tests.rs @@ -1,5 +1,6 @@ -use hir::{PrefixKind, WithFixture}; +use hir::PrefixKind; use stdx::trim_indent; +use test_fixture::WithFixture; use test_utils::{assert_eq_text, CURSOR_MARKER}; use super::*; diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index 63020758d58..128971994f6 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -43,10 +43,7 @@ pub mod syntax_helpers { pub use parser::LexedStr; } -pub mod fixture { - pub use hir::{Change, ChangeFixture, WithFixture}; - pub const WORKSPACE: base_db::SourceRootId = base_db::SourceRootId(0); -} +pub use hir::Change; use std::{fmt, mem::ManuallyDrop}; diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs index 6493e1535a9..24d08500f13 100644 --- a/crates/ide-db/src/symbol_index.rs +++ b/crates/ide-db/src/symbol_index.rs @@ -379,7 +379,8 @@ impl Query { mod tests { use expect_test::expect_file; - use hir::{symbols::SymbolCollector, WithFixture}; + use hir::symbols::SymbolCollector; + use test_fixture::WithFixture; use super::*; diff --git a/crates/ide-db/src/traits.rs b/crates/ide-db/src/traits.rs index 4c9ecfcc844..bbdfd81d653 100644 --- a/crates/ide-db/src/traits.rs +++ b/crates/ide-db/src/traits.rs @@ -115,8 +115,9 @@ fn assoc_item_of_trait( mod tests { use base_db::FilePosition; use expect_test::{expect, Expect}; - use hir::{ChangeFixture, Semantics}; + use hir::Semantics; use syntax::ast::{self, AstNode}; + use test_fixture::ChangeFixture; use crate::RootDatabase; diff --git a/crates/ide-diagnostics/Cargo.toml b/crates/ide-diagnostics/Cargo.toml index f4055024cc3..fd77badbd65 100644 --- a/crates/ide-diagnostics/Cargo.toml +++ b/crates/ide-diagnostics/Cargo.toml @@ -32,6 +32,7 @@ expect-test = "1.4.0" # local deps test-utils.workspace = true +test-fixture.workspace = true sourcegen.workspace = true [features] diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs index e5b1cf2bc04..67912a3a03e 100644 --- a/crates/ide-diagnostics/src/tests.rs +++ b/crates/ide-diagnostics/src/tests.rs @@ -2,12 +2,12 @@ mod sourcegen; use expect_test::Expect; -use hir::WithFixture; use ide_db::{ assists::AssistResolveStrategy, base_db::SourceDatabaseExt, LineIndexDatabase, RootDatabase, }; use itertools::Itertools; use stdx::trim_indent; +use test_fixture::WithFixture; use test_utils::{assert_eq_text, extract_annotations, MiniCore}; use crate::{DiagnosticsConfig, ExprFillDefaultMode, Severity}; diff --git a/crates/ide-ssr/Cargo.toml b/crates/ide-ssr/Cargo.toml index 56b29f92b82..9ea7beaf985 100644 --- a/crates/ide-ssr/Cargo.toml +++ b/crates/ide-ssr/Cargo.toml @@ -31,3 +31,4 @@ expect-test = "1.4.0" # local deps test-utils.workspace = true +test-fixture.workspace = true diff --git a/crates/ide-ssr/src/tests.rs b/crates/ide-ssr/src/tests.rs index 0083e8faff8..7c7d146cb4a 100644 --- a/crates/ide-ssr/src/tests.rs +++ b/crates/ide-ssr/src/tests.rs @@ -65,8 +65,8 @@ fn parser_undefined_placeholder_in_replacement() { /// `code` may optionally contain a cursor marker `$0`. If it doesn't, then the position will be /// the start of the file. If there's a second cursor marker, then we'll return a single range. pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Vec) { - use hir::WithFixture; use ide_db::symbol_index::SymbolsDatabase; + use test_fixture::{WithFixture, WORKSPACE}; let (mut db, file_id, range_or_offset) = if code.contains(test_utils::CURSOR_MARKER) { ide_db::RootDatabase::with_range_or_offset(code) } else { @@ -86,7 +86,7 @@ pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Ve } } let mut local_roots = FxHashSet::default(); - local_roots.insert(ide_db::fixture::WORKSPACE); + local_roots.insert(WORKSPACE); db.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); (db, position, selections) } diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml index 0943574ec1b..22850bae888 100644 --- a/crates/ide/Cargo.toml +++ b/crates/ide/Cargo.toml @@ -50,6 +50,7 @@ expect-test = "1.4.0" # local deps test-utils.workspace = true +test-fixture.workspace = true [features] in-rust-tree = ["ide-assists/in-rust-tree", "ide-diagnostics/in-rust-tree"] diff --git a/crates/ide/src/fixture.rs b/crates/ide/src/fixture.rs index 2fc64ae4571..3b19b85c4bc 100644 --- a/crates/ide/src/fixture.rs +++ b/crates/ide/src/fixture.rs @@ -1,5 +1,5 @@ //! Utilities for creating `Analysis` instances for tests. -use ide_db::fixture::ChangeFixture; +use test_fixture::ChangeFixture; use test_utils::{extract_annotations, RangeOrOffset}; use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs index 479a5e151ad..483fb76d91c 100644 --- a/crates/ide/src/signature_help.rs +++ b/crates/ide/src/signature_help.rs @@ -646,8 +646,9 @@ mod tests { use std::iter; use expect_test::{expect, Expect}; - use ide_db::{base_db::FilePosition, fixture::ChangeFixture}; + use ide_db::base_db::FilePosition; use stdx::format_to; + use test_fixture::ChangeFixture; use crate::RootDatabase; diff --git a/crates/ide/src/ssr.rs b/crates/ide/src/ssr.rs index 312481c9bbc..f0d18fdefa7 100644 --- a/crates/ide/src/ssr.rs +++ b/crates/ide/src/ssr.rs @@ -60,10 +60,10 @@ mod tests { use ide_assists::{Assist, AssistResolveStrategy}; use ide_db::{ base_db::{salsa::Durability, FileRange}, - fixture::WithFixture, symbol_index::SymbolsDatabase, FxHashSet, RootDatabase, }; + use test_fixture::WithFixture; use triomphe::Arc; use super::ssr_assists; @@ -71,7 +71,7 @@ mod tests { fn get_assists(ra_fixture: &str, resolve: AssistResolveStrategy) -> Vec { let (mut db, file_id, range_or_offset) = RootDatabase::with_range_or_offset(ra_fixture); let mut local_roots = FxHashSet::default(); - local_roots.insert(ide_db::fixture::WORKSPACE); + local_roots.insert(test_fixture::WORKSPACE); db.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); ssr_assists(&db, &resolve, FileRange { file_id, range: range_or_offset.into() }) } diff --git a/crates/intern/Cargo.toml b/crates/intern/Cargo.toml index d9184b0fb6f..3b0c2559482 100644 --- a/crates/intern/Cargo.toml +++ b/crates/intern/Cargo.toml @@ -16,5 +16,5 @@ doctest = false # We need to freeze the version of the crate, as the raw-api feature is considered unstable dashmap.workspace = true hashbrown.workspace = true -rustc-hash = "1.1.0" +rustc-hash.workspace = true triomphe.workspace = true diff --git a/crates/load-cargo/Cargo.toml b/crates/load-cargo/Cargo.toml index 346c234f097..ae7c7e2ac75 100644 --- a/crates/load-cargo/Cargo.toml +++ b/crates/load-cargo/Cargo.toml @@ -12,7 +12,7 @@ authors.workspace = true [dependencies] anyhow.workspace = true -crossbeam-channel = "0.5.5" +crossbeam-channel.workspace = true itertools.workspace = true tracing.workspace = true diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index ee42640cebc..556ed73a04c 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -12,8 +12,7 @@ use hir_expand::proc_macro::{ use ide::{AnalysisHost, SourceRoot}; use ide_db::{ base_db::{CrateGraph, Env}, - fixture::Change, - FxHashMap, + Change, FxHashMap, }; use itertools::Itertools; use proc_macro_api::{MacroDylib, ProcMacroServer}; diff --git a/crates/mbe/Cargo.toml b/crates/mbe/Cargo.toml index cc0a47291e3..77f48a57f90 100644 --- a/crates/mbe/Cargo.toml +++ b/crates/mbe/Cargo.toml @@ -13,7 +13,7 @@ doctest = false [dependencies] cov-mark = "2.0.0-pre.1" -rustc-hash = "1.1.0" +rustc-hash.workspace = true smallvec.workspace = true tracing.workspace = true diff --git a/crates/project-model/Cargo.toml b/crates/project-model/Cargo.toml index 3e48de6456b..c1243b5932a 100644 --- a/crates/project-model/Cargo.toml +++ b/crates/project-model/Cargo.toml @@ -14,7 +14,7 @@ doctest = false [dependencies] anyhow.workspace = true cargo_metadata.workspace = true -rustc-hash = "1.1.0" +rustc-hash.workspace = true semver = "1.0.14" serde_json.workspace = true serde.workspace = true diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 39ac338aa1a..75bd13d3264 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -29,7 +29,7 @@ parking_lot = "0.12.1" xflags = "0.3.0" oorandom = "11.1.3" rayon.workspace = true -rustc-hash = "1.1.0" +rustc-hash.workspace = true serde_json = { workspace = true, features = ["preserve_order"] } serde.workspace = true num_cpus = "1.15.0" @@ -76,6 +76,7 @@ expect-test = "1.4.0" xshell.workspace = true test-utils.workspace = true +test-fixture.workspace = true sourcegen.workspace = true mbe.workspace = true diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs index dfc7cbf510b..95c8798d43c 100644 --- a/crates/rust-analyzer/src/cli/scip.rs +++ b/crates/rust-analyzer/src/cli/scip.rs @@ -278,8 +278,8 @@ fn token_to_symbol(token: &TokenStaticData) -> Option { mod test { use super::*; use ide::{AnalysisHost, FilePosition, StaticIndex, TextSize}; - use ide_db::fixture::ChangeFixture; use scip::symbol::format_symbol; + use test_fixture::ChangeFixture; fn position(ra_fixture: &str) -> (AnalysisHost, FilePosition) { let mut host = AnalysisHost::default(); diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index 7a7c0d267fe..1cb9a4aedc5 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml @@ -17,7 +17,7 @@ cov-mark = "2.0.0-pre.1" either.workspace = true itertools.workspace = true rowan = "0.15.15" -rustc-hash = "1.1.0" +rustc-hash.workspace = true once_cell = "1.17.0" indexmap.workspace = true smol_str.workspace = true diff --git a/crates/test-fixture/Cargo.toml b/crates/test-fixture/Cargo.toml new file mode 100644 index 00000000000..ff921aa83d3 --- /dev/null +++ b/crates/test-fixture/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "test-fixture" +version = "0.0.0" +rust-version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +publish = false + +[dependencies] +hir-expand.workspace = true +test-utils.workspace = true +tt.workspace = true +cfg.workspace = true +base-db.workspace = true +rustc-hash.workspace = true +span.workspace = true +stdx.workspace = true diff --git a/crates/hir-expand/src/fixture.rs b/crates/test-fixture/src/lib.rs similarity index 92% rename from crates/hir-expand/src/fixture.rs rename to crates/test-fixture/src/lib.rs index 0c194a1b1e9..8c5f9309072 100644 --- a/crates/hir-expand/src/fixture.rs +++ b/crates/test-fixture/src/lib.rs @@ -2,24 +2,27 @@ use std::{mem, ops::Not, str::FromStr, sync}; use base_db::{ - salsa::Durability, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, - DependencyKind, Edition, Env, FileChange, FileSet, LangCrateOrigin, ReleaseChannel, - SourceDatabaseExt, SourceRoot, VfsPath, + CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, DependencyKind, + Edition, Env, FileChange, FileSet, LangCrateOrigin, ReleaseChannel, SourceDatabaseExt, + SourceRoot, VfsPath, }; use cfg::CfgOptions; +use hir_expand::{ + change::Change, + db::ExpandDatabase, + proc_macro::{ + ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind, ProcMacros, + }, +}; use rustc_hash::FxHashMap; use span::{FileId, FilePosition, FileRange, Span}; use test_utils::{ extract_range_or_offset, Fixture, FixtureWithProjectMeta, RangeOrOffset, CURSOR_MARKER, ESCAPED_CURSOR_MARKER, }; -use triomphe::Arc; use tt::{Leaf, Subtree, TokenTree}; -use crate::{ - db::ExpandDatabase, - proc_macro::{ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacros}, -}; +pub const WORKSPACE: base_db::SourceRootId = base_db::SourceRootId(0); pub trait WithFixture: Default + ExpandDatabase + SourceDatabaseExt + 'static { #[track_caller] @@ -98,41 +101,6 @@ pub trait WithFixture: Default + ExpandDatabase + SourceDatabaseExt + 'static { impl WithFixture for DB {} -#[derive(Debug, Default)] -pub struct Change { - pub source_change: FileChange, - pub proc_macros: Option, -} - -impl Change { - pub fn new() -> Self { - Self::default() - } - - pub fn apply(self, db: &mut (impl ExpandDatabase + SourceDatabaseExt)) { - self.source_change.apply(db); - if let Some(proc_macros) = self.proc_macros { - db.set_proc_macros_with_durability(Arc::new(proc_macros), Durability::HIGH); - } - } - - pub fn change_file(&mut self, file_id: FileId, new_text: Option>) { - self.source_change.change_file(file_id, new_text) - } - - pub fn set_crate_graph(&mut self, graph: CrateGraph) { - self.source_change.set_crate_graph(graph) - } - - pub fn set_proc_macros(&mut self, proc_macros: ProcMacros) { - self.proc_macros = Some(proc_macros); - } - - pub fn set_roots(&mut self, roots: Vec) { - self.source_change.set_roots(roots) - } -} - pub struct ChangeFixture { pub file_position: Option<(FileId, RangeOrOffset)>, pub files: Vec, @@ -223,7 +191,7 @@ impl ChangeFixture { origin, meta.target_data_layout .as_deref() - .map(Arc::from) + .map(From::from) .ok_or_else(|| "target_data_layout unset".into()), Some(toolchain), ); @@ -242,7 +210,7 @@ impl ChangeFixture { default_target_data_layout = meta.target_data_layout; } - source_change.change_file(file_id, Some(Arc::from(text))); + source_change.change_file(file_id, Some(text.into())); let path = VfsPath::new_virtual_path(meta.path); file_set.insert(file_id, path); files.push(file_id); @@ -297,7 +265,7 @@ impl ChangeFixture { fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_string())); roots.push(SourceRoot::new_library(fs)); - source_change.change_file(core_file, Some(Arc::from(mini_core.source_code()))); + source_change.change_file(core_file, Some(mini_core.source_code().into())); let all_crates = crate_graph.crates_in_topological_order(); @@ -342,7 +310,7 @@ impl ChangeFixture { ); roots.push(SourceRoot::new_library(fs)); - source_change.change_file(proc_lib_file, Some(Arc::from(source))); + source_change.change_file(proc_lib_file, Some(source.into())); let all_crates = crate_graph.crates_in_topological_order(); @@ -406,7 +374,7 @@ pub fn identity(_attr: TokenStream, item: TokenStream) -> TokenStream { .into(), ProcMacro { name: "identity".into(), - kind: crate::ProcMacroKind::Attr, + kind: ProcMacroKind::Attr, expander: sync::Arc::new(IdentityProcMacroExpander), }, ), @@ -420,7 +388,7 @@ pub fn derive_identity(item: TokenStream) -> TokenStream { .into(), ProcMacro { name: "DeriveIdentity".into(), - kind: crate::ProcMacroKind::CustomDerive, + kind: ProcMacroKind::CustomDerive, expander: sync::Arc::new(IdentityProcMacroExpander), }, ), @@ -434,7 +402,7 @@ pub fn input_replace(attr: TokenStream, _item: TokenStream) -> TokenStream { .into(), ProcMacro { name: "input_replace".into(), - kind: crate::ProcMacroKind::Attr, + kind: ProcMacroKind::Attr, expander: sync::Arc::new(AttributeInputReplaceProcMacroExpander), }, ), @@ -448,7 +416,7 @@ pub fn mirror(input: TokenStream) -> TokenStream { .into(), ProcMacro { name: "mirror".into(), - kind: crate::ProcMacroKind::FuncLike, + kind: ProcMacroKind::FuncLike, expander: sync::Arc::new(MirrorProcMacroExpander), }, ), @@ -462,7 +430,7 @@ pub fn shorten(input: TokenStream) -> TokenStream { .into(), ProcMacro { name: "shorten".into(), - kind: crate::ProcMacroKind::FuncLike, + kind: ProcMacroKind::FuncLike, expander: sync::Arc::new(ShortenProcMacroExpander), }, ), diff --git a/crates/test-utils/Cargo.toml b/crates/test-utils/Cargo.toml index 438b599ffaa..8b3924dd86b 100644 --- a/crates/test-utils/Cargo.toml +++ b/crates/test-utils/Cargo.toml @@ -15,7 +15,7 @@ doctest = false # Avoid adding deps here, this crate is widely used in tests it should compile fast! dissimilar = "1.0.7" text-size.workspace = true -rustc-hash = "1.1.0" +rustc-hash.workspace = true stdx.workspace = true profile.workspace = true diff --git a/crates/vfs/Cargo.toml b/crates/vfs/Cargo.toml index 11409f2eb81..af4cc034c3c 100644 --- a/crates/vfs/Cargo.toml +++ b/crates/vfs/Cargo.toml @@ -12,7 +12,7 @@ rust-version.workspace = true doctest = false [dependencies] -rustc-hash = "1.1.0" +rustc-hash.workspace = true fst = "0.4.7" indexmap.workspace = true nohash-hasher.workspace = true