mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
internal: Move out WithFixture
into dev-dep only crate
This commit is contained in:
parent
ec6162308e
commit
f49a2fed3f
59 changed files with 189 additions and 119 deletions
25
Cargo.lock
generated
25
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
|
|
42
crates/hir-expand/src/change.rs
Normal file
42
crates/hir-expand/src/change.rs
Normal file
|
@ -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<ProcMacros>,
|
||||
}
|
||||
|
||||
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<Arc<str>>) {
|
||||
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<SourceRoot>) {
|
||||
self.source_change.set_roots(roots)
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -31,6 +31,7 @@ expect-test = "1.4.0"
|
|||
|
||||
# local deps
|
||||
test-utils.workspace = true
|
||||
test-fixture.workspace = true
|
||||
sourcegen.workspace = true
|
||||
|
||||
[features]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -275,8 +275,8 @@ fn from_field_name(expr: &ast::Expr) -> Option<String> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hir::WithFixture;
|
||||
use ide_db::base_db::FileRange;
|
||||
use test_fixture::WithFixture;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
|
|
@ -35,3 +35,4 @@ expect-test = "1.4.0"
|
|||
|
||||
# local deps
|
||||
test-utils.workspace = true
|
||||
test-fixture.workspace = true
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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::*;
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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::*;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ expect-test = "1.4.0"
|
|||
|
||||
# local deps
|
||||
test-utils.workspace = true
|
||||
test-fixture.workspace = true
|
||||
sourcegen.workspace = true
|
||||
|
||||
[features]
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -31,3 +31,4 @@ expect-test = "1.4.0"
|
|||
|
||||
# local deps
|
||||
test-utils.workspace = true
|
||||
test-fixture.workspace = true
|
||||
|
|
|
@ -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<FileRange>) {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<Assist> {
|
||||
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() })
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -278,8 +278,8 @@ fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
|
|||
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();
|
||||
|
|
|
@ -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
|
||||
|
|
18
crates/test-fixture/Cargo.toml
Normal file
18
crates/test-fixture/Cargo.toml
Normal file
|
@ -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
|
|
@ -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<DB: ExpandDatabase + SourceDatabaseExt + Default + 'static> WithFixture for DB {}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Change {
|
||||
pub source_change: FileChange,
|
||||
pub proc_macros: Option<ProcMacros>,
|
||||
}
|
||||
|
||||
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<Arc<str>>) {
|
||||
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<SourceRoot>) {
|
||||
self.source_change.set_roots(roots)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ChangeFixture {
|
||||
pub file_position: Option<(FileId, RangeOrOffset)>,
|
||||
pub files: Vec<FileId>,
|
||||
|
@ -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),
|
||||
},
|
||||
),
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue