diff --git a/crates/hir-def/src/body/scope.rs b/crates/hir-def/src/body/scope.rs index 63a7a9af20..08af470b96 100644 --- a/crates/hir-def/src/body/scope.rs +++ b/crates/hir-def/src/body/scope.rs @@ -345,7 +345,7 @@ mod tests { } } - fn do_check(ra_fixture: &str, expected: &[&str]) { + fn do_check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: &[&str]) { let (offset, code) = extract_offset(ra_fixture); let code = { let mut buf = String::new(); @@ -509,7 +509,7 @@ fn foo() { ); } - fn do_check_local_name(ra_fixture: &str, expected_offset: u32) { + fn do_check_local_name(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_offset: u32) { let (db, position) = TestDB::with_position(ra_fixture); let file_id = position.file_id; let offset = position.offset; diff --git a/crates/hir-def/src/body/tests.rs b/crates/hir-def/src/body/tests.rs index 7e15a9f2d6..65f44dbc35 100644 --- a/crates/hir-def/src/body/tests.rs +++ b/crates/hir-def/src/body/tests.rs @@ -7,7 +7,7 @@ use crate::{test_db::TestDB, ModuleDefId}; use super::*; -fn lower(ra_fixture: &str) -> (TestDB, Arc, DefWithBodyId) { +fn lower(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (TestDB, Arc, DefWithBodyId) { let db = TestDB::with_files(ra_fixture); let krate = db.fetch_test_crate(); @@ -27,14 +27,14 @@ fn lower(ra_fixture: &str) -> (TestDB, Arc, DefWithBodyId) { (db, body, fn_def) } -fn def_map_at(ra_fixture: &str) -> String { +fn def_map_at(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String { let (db, position) = TestDB::with_position(ra_fixture); let module = db.module_at_position(position); module.def_map(&db).dump(&db) } -fn check_block_scopes_at(ra_fixture: &str, expect: Expect) { +fn check_block_scopes_at(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (db, position) = TestDB::with_position(ra_fixture); let module = db.module_at_position(position); @@ -42,7 +42,7 @@ fn check_block_scopes_at(ra_fixture: &str, expect: Expect) { expect.assert_eq(&actual); } -fn check_at(ra_fixture: &str, expect: Expect) { +fn check_at(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let actual = def_map_at(ra_fixture); expect.assert_eq(&actual); } diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs index a615abd1bb..5d67902c8a 100644 --- a/crates/hir-def/src/find_path.rs +++ b/crates/hir-def/src/find_path.rs @@ -665,7 +665,7 @@ mod tests { /// module the cursor is in. #[track_caller] fn check_found_path_( - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, path: &str, prefer_prelude: bool, prefer_absolute: bool, @@ -727,19 +727,35 @@ mod tests { expect.assert_eq(&res); } - fn check_found_path(ra_fixture: &str, path: &str, expect: Expect) { + fn check_found_path( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + path: &str, + expect: Expect, + ) { check_found_path_(ra_fixture, path, false, false, false, expect); } - fn check_found_path_prelude(ra_fixture: &str, path: &str, expect: Expect) { + fn check_found_path_prelude( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + path: &str, + expect: Expect, + ) { check_found_path_(ra_fixture, path, true, false, false, expect); } - fn check_found_path_absolute(ra_fixture: &str, path: &str, expect: Expect) { + fn check_found_path_absolute( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + path: &str, + expect: Expect, + ) { check_found_path_(ra_fixture, path, false, true, false, expect); } - fn check_found_path_prefer_no_std(ra_fixture: &str, path: &str, expect: Expect) { + fn check_found_path_prefer_no_std( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + path: &str, + expect: Expect, + ) { check_found_path_(ra_fixture, path, false, false, true, expect); } diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs index 9574e5d9cd..ac262950f1 100644 --- a/crates/hir-def/src/import_map.rs +++ b/crates/hir-def/src/import_map.rs @@ -509,7 +509,12 @@ mod tests { } } - fn check_search(ra_fixture: &str, crate_name: &str, query: Query, expect: Expect) { + fn check_search( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + crate_name: &str, + query: Query, + expect: Expect, + ) { let db = TestDB::with_files(ra_fixture); let crate_graph = db.crate_graph(); let krate = crate_graph @@ -587,7 +592,7 @@ mod tests { )) } - fn check(ra_fixture: &str, expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let db = TestDB::with_files(ra_fixture); let crate_graph = db.crate_graph(); diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs index 735586c049..80b699649f 100644 --- a/crates/hir-def/src/item_tree/tests.rs +++ b/crates/hir-def/src/item_tree/tests.rs @@ -4,7 +4,7 @@ use test_fixture::WithFixture; use crate::{db::DefDatabase, test_db::TestDB}; -fn check(ra_fixture: &str, expect: Expect) { +fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (db, file_id) = TestDB::with_single_file(ra_fixture); let item_tree = db.file_item_tree(file_id.into()); let pretty = item_tree.pretty_print(&db, Edition::CURRENT); diff --git a/crates/hir-def/src/macro_expansion_tests/mod.rs b/crates/hir-def/src/macro_expansion_tests/mod.rs index adcf278472..408d03ff71 100644 --- a/crates/hir-def/src/macro_expansion_tests/mod.rs +++ b/crates/hir-def/src/macro_expansion_tests/mod.rs @@ -47,7 +47,7 @@ use crate::{ }; #[track_caller] -fn check_errors(ra_fixture: &str, expect: Expect) { +fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let db = TestDB::with_files(ra_fixture); let krate = db.fetch_test_crate(); let def_map = db.crate_def_map(krate); @@ -77,7 +77,7 @@ fn check_errors(ra_fixture: &str, expect: Expect) { } #[track_caller] -fn check(ra_fixture: &str, mut expect: Expect) { +fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, mut expect: Expect) { let extra_proc_macros = vec![( r#" #[proc_macro_attribute] diff --git a/crates/hir-def/src/nameres/tests.rs b/crates/hir-def/src/nameres/tests.rs index 32c158415b..318aee04f7 100644 --- a/crates/hir-def/src/nameres/tests.rs +++ b/crates/hir-def/src/nameres/tests.rs @@ -11,19 +11,19 @@ use triomphe::Arc; use crate::{db::DefDatabase, nameres::DefMap, test_db::TestDB}; -fn compute_crate_def_map(ra_fixture: &str) -> Arc { +fn compute_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> Arc { let db = TestDB::with_files(ra_fixture); let krate = db.fetch_test_crate(); db.crate_def_map(krate) } -fn render_crate_def_map(ra_fixture: &str) -> String { +fn render_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String { let db = TestDB::with_files(ra_fixture); let krate = db.fetch_test_crate(); db.crate_def_map(krate).dump(&db) } -fn check(ra_fixture: &str, expect: Expect) { +fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let actual = render_crate_def_map(ra_fixture); expect.assert_eq(&actual); } diff --git a/crates/hir-expand/src/fixup.rs b/crates/hir-expand/src/fixup.rs index c4113de7a5..eb43017739 100644 --- a/crates/hir-expand/src/fixup.rs +++ b/crates/hir-expand/src/fixup.rs @@ -532,7 +532,7 @@ mod tests { } #[track_caller] - fn check(ra_fixture: &str, mut expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, mut expect: Expect) { let parsed = syntax::SourceFile::parse(ra_fixture, span::Edition::CURRENT); let span_map = SpanMap::RealSpanMap(Arc::new(RealSpanMap::absolute(EditionedFileId::new( FileId::from_raw(0), diff --git a/crates/hir-ty/src/consteval/tests.rs b/crates/hir-ty/src/consteval/tests.rs index 0a8bfaa70f..2d7d4cacd2 100644 --- a/crates/hir-ty/src/consteval/tests.rs +++ b/crates/hir-ty/src/consteval/tests.rs @@ -31,7 +31,10 @@ fn simplify(e: ConstEvalError) -> ConstEvalError { } #[track_caller] -fn check_fail(ra_fixture: &str, error: impl FnOnce(ConstEvalError) -> bool) { +fn check_fail( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + error: impl FnOnce(ConstEvalError) -> bool, +) { let (db, file_id) = TestDB::with_single_file(ra_fixture); match eval_goal(&db, file_id) { Ok(_) => panic!("Expected fail, but it succeeded"), @@ -42,7 +45,7 @@ fn check_fail(ra_fixture: &str, error: impl FnOnce(ConstEvalError) -> bool) { } #[track_caller] -fn check_number(ra_fixture: &str, answer: i128) { +fn check_number(#[rust_analyzer::rust_fixture] ra_fixture: &str, answer: i128) { check_answer(ra_fixture, |b, _| { assert_eq!( b, @@ -54,7 +57,7 @@ fn check_number(ra_fixture: &str, answer: i128) { } #[track_caller] -fn check_str(ra_fixture: &str, answer: &str) { +fn check_str(#[rust_analyzer::rust_fixture] ra_fixture: &str, answer: &str) { check_answer(ra_fixture, |b, mm| { let addr = usize::from_le_bytes(b[0..b.len() / 2].try_into().unwrap()); let size = usize::from_le_bytes(b[b.len() / 2..].try_into().unwrap()); @@ -71,7 +74,10 @@ fn check_str(ra_fixture: &str, answer: &str) { } #[track_caller] -fn check_answer(ra_fixture: &str, check: impl FnOnce(&[u8], &MemoryMap)) { +fn check_answer( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + check: impl FnOnce(&[u8], &MemoryMap), +) { let (db, file_ids) = TestDB::with_many_files(ra_fixture); let file_id = *file_ids.last().unwrap(); let r = match eval_goal(&db, file_id) { diff --git a/crates/hir-ty/src/dyn_compatibility/tests.rs b/crates/hir-ty/src/dyn_compatibility/tests.rs index 8a56bd28b5..3060b610bb 100644 --- a/crates/hir-ty/src/dyn_compatibility/tests.rs +++ b/crates/hir-ty/src/dyn_compatibility/tests.rs @@ -26,7 +26,7 @@ enum DynCompatibilityViolationKind { } fn check_dyn_compatibility<'a>( - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, expected: impl IntoIterator)>, ) { let mut expected: FxHashMap<_, _> = diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs index 66159ddce2..4d3896660b 100644 --- a/crates/hir-ty/src/layout/tests.rs +++ b/crates/hir-ty/src/layout/tests.rs @@ -25,7 +25,10 @@ fn current_machine_data_layout() -> String { .unwrap() } -fn eval_goal(ra_fixture: &str, minicore: &str) -> Result, LayoutError> { +fn eval_goal( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + minicore: &str, +) -> Result, LayoutError> { let target_data_layout = current_machine_data_layout(); let ra_fixture = format!( "//- target_data_layout: {target_data_layout}\n{minicore}//- /main.rs crate:test\n{ra_fixture}", @@ -81,7 +84,10 @@ fn eval_goal(ra_fixture: &str, minicore: &str) -> Result, LayoutErro } /// A version of `eval_goal` for types that can not be expressed in ADTs, like closures and `impl Trait` -fn eval_expr(ra_fixture: &str, minicore: &str) -> Result, LayoutError> { +fn eval_expr( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + minicore: &str, +) -> Result, LayoutError> { let target_data_layout = current_machine_data_layout(); let ra_fixture = format!( "//- target_data_layout: {target_data_layout}\n{minicore}//- /main.rs crate:test\nfn main(){{let goal = {{{ra_fixture}}};}}", @@ -114,21 +120,31 @@ fn eval_expr(ra_fixture: &str, minicore: &str) -> Result, LayoutErro } #[track_caller] -fn check_size_and_align(ra_fixture: &str, minicore: &str, size: u64, align: u64) { +fn check_size_and_align( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + minicore: &str, + size: u64, + align: u64, +) { let l = eval_goal(ra_fixture, minicore).unwrap(); assert_eq!(l.size.bytes(), size, "size mismatch"); assert_eq!(l.align.abi.bytes(), align, "align mismatch"); } #[track_caller] -fn check_size_and_align_expr(ra_fixture: &str, minicore: &str, size: u64, align: u64) { +fn check_size_and_align_expr( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + minicore: &str, + size: u64, + align: u64, +) { let l = eval_expr(ra_fixture, minicore).unwrap(); assert_eq!(l.size.bytes(), size, "size mismatch"); assert_eq!(l.align.abi.bytes(), align, "align mismatch"); } #[track_caller] -fn check_fail(ra_fixture: &str, e: LayoutError) { +fn check_fail(#[rust_analyzer::rust_fixture] ra_fixture: &str, e: LayoutError) { let r = eval_goal(ra_fixture, ""); assert_eq!(r, Err(e)); } diff --git a/crates/hir-ty/src/mir/eval/tests.rs b/crates/hir-ty/src/mir/eval/tests.rs index ce43e90df7..f1e86daea2 100644 --- a/crates/hir-ty/src/mir/eval/tests.rs +++ b/crates/hir-ty/src/mir/eval/tests.rs @@ -37,11 +37,15 @@ fn eval_main(db: &TestDB, file_id: EditionedFileId) -> Result<(String, String), Ok((output.stdout().into_owned(), output.stderr().into_owned())) } -fn check_pass(ra_fixture: &str) { +fn check_pass(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_pass_and_stdio(ra_fixture, "", ""); } -fn check_pass_and_stdio(ra_fixture: &str, expected_stdout: &str, expected_stderr: &str) { +fn check_pass_and_stdio( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expected_stdout: &str, + expected_stderr: &str, +) { let (db, file_ids) = TestDB::with_many_files(ra_fixture); let file_id = *file_ids.last().unwrap(); let x = eval_main(&db, file_id); @@ -73,7 +77,7 @@ fn check_pass_and_stdio(ra_fixture: &str, expected_stdout: &str, expected_stderr } } -fn check_panic(ra_fixture: &str, expected_panic: &str) { +fn check_panic(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_panic: &str) { let (db, file_ids) = TestDB::with_many_files(ra_fixture); let file_id = *file_ids.last().unwrap(); let e = eval_main(&db, file_id).unwrap_err(); diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs index b7607b5f63..acdcbb4757 100644 --- a/crates/hir-ty/src/tests.rs +++ b/crates/hir-ty/src/tests.rs @@ -69,27 +69,32 @@ fn setup_tracing() -> Option { } #[track_caller] -fn check_types(ra_fixture: &str) { +fn check_types(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_impl(ra_fixture, false, true, false) } #[track_caller] -fn check_types_source_code(ra_fixture: &str) { +fn check_types_source_code(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_impl(ra_fixture, false, true, true) } #[track_caller] -fn check_no_mismatches(ra_fixture: &str) { +fn check_no_mismatches(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_impl(ra_fixture, true, false, false) } #[track_caller] -fn check(ra_fixture: &str) { +fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_impl(ra_fixture, false, false, false) } #[track_caller] -fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_source: bool) { +fn check_impl( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + allow_none: bool, + only_types: bool, + display_source: bool, +) { let _tracing = setup_tracing(); let (db, files) = TestDB::with_many_files(ra_fixture); @@ -282,7 +287,7 @@ fn pat_node( }) } -fn infer(ra_fixture: &str) -> String { +fn infer(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String { infer_with_mismatches(ra_fixture, false) } @@ -520,13 +525,13 @@ fn ellipsize(mut text: String, max_len: usize) -> String { text } -fn check_infer(ra_fixture: &str, expect: Expect) { +fn check_infer(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let mut actual = infer(ra_fixture); actual.push('\n'); expect.assert_eq(&actual); } -fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) { +fn check_infer_with_mismatches(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let mut actual = infer_with_mismatches(ra_fixture, true); actual.push('\n'); expect.assert_eq(&actual); diff --git a/crates/hir-ty/src/tests/closure_captures.rs b/crates/hir-ty/src/tests/closure_captures.rs index 7de92d6b16..34d299edd1 100644 --- a/crates/hir-ty/src/tests/closure_captures.rs +++ b/crates/hir-ty/src/tests/closure_captures.rs @@ -14,7 +14,7 @@ use crate::test_db::TestDB; use super::visit_module; -fn check_closure_captures(ra_fixture: &str, expect: Expect) { +fn check_closure_captures(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (db, file_id) = TestDB::with_single_file(ra_fixture); let module = db.module_for_file(file_id); let def_map = module.def_map(&db); diff --git a/crates/hir-ty/src/variance.rs b/crates/hir-ty/src/variance.rs index 30711b16df..afd163fbd9 100644 --- a/crates/hir-ty/src/variance.rs +++ b/crates/hir-ty/src/variance.rs @@ -968,7 +968,7 @@ struct FixedPoint(&'static FixedPoint<(), T, U>, V); } #[track_caller] - fn check(ra_fixture: &str, expected: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: Expect) { // use tracing_subscriber::{layer::SubscriberExt, Layer}; // let my_layer = tracing_subscriber::fmt::layer(); // let _g = tracing::subscriber::set_default(tracing_subscriber::registry().with( diff --git a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs index c879a4a3d9..ac58af6252 100644 --- a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs +++ b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs @@ -933,7 +933,7 @@ mod tests_setter { use super::*; - fn check_not_applicable(ra_fixture: &str) { + fn check_not_applicable(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_assist_not_applicable(generate_setter, ra_fixture) } diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 0b1ff87c5c..85f1099ea5 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -130,22 +130,36 @@ pub(crate) fn check_assist_by_label( // `extract_ranges` and mark the target as ` ` in the // fixture? #[track_caller] -pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { +pub(crate) fn check_assist_target( + assist: Handler, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + target: &str, +) { check(assist, ra_fixture, ExpectedResult::Target(target), None); } #[track_caller] -pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { +pub(crate) fn check_assist_not_applicable( + assist: Handler, + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) { check(assist, ra_fixture, ExpectedResult::NotApplicable, None); } #[track_caller] -pub(crate) fn check_assist_not_applicable_by_label(assist: Handler, ra_fixture: &str, label: &str) { +pub(crate) fn check_assist_not_applicable_by_label( + assist: Handler, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + label: &str, +) { check(assist, ra_fixture, ExpectedResult::NotApplicable, Some(label)); } #[track_caller] -pub(crate) fn check_assist_not_applicable_for_import_one(assist: Handler, ra_fixture: &str) { +pub(crate) fn check_assist_not_applicable_for_import_one( + assist: Handler, + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) { check_with_config( TEST_CONFIG_IMPORT_ONE, assist, @@ -157,7 +171,10 @@ pub(crate) fn check_assist_not_applicable_for_import_one(assist: Handler, ra_fix /// Check assist in unresolved state. Useful to check assists for lazy computation. #[track_caller] -pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) { +pub(crate) fn check_assist_unresolved( + assist: Handler, + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) { check(assist, ra_fixture, ExpectedResult::Unresolved, None); } diff --git a/crates/ide-completion/src/context/tests.rs b/crates/ide-completion/src/context/tests.rs index 82a1c10c53..fc2bfc01e6 100644 --- a/crates/ide-completion/src/context/tests.rs +++ b/crates/ide-completion/src/context/tests.rs @@ -6,7 +6,7 @@ use crate::{ tests::{position, TEST_CONFIG}, }; -fn check_expected_type_and_name(ra_fixture: &str, expect: Expect) { +fn check_expected_type_and_name(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (db, pos) = position(ra_fixture); let config = TEST_CONFIG; let (completion_context, _analysis) = CompletionContext::new(&db, pos, &config).unwrap(); diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index c239ca512d..eb5d136b8b 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -693,20 +693,28 @@ mod tests { }; #[track_caller] - fn check(ra_fixture: &str, kind: impl Into, expect: Expect) { + fn check( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + kind: impl Into, + expect: Expect, + ) { let actual = do_completion(ra_fixture, kind.into()); expect.assert_debug_eq(&actual); } #[track_caller] - fn check_kinds(ra_fixture: &str, kinds: &[CompletionItemKind], expect: Expect) { + fn check_kinds( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + kinds: &[CompletionItemKind], + expect: Expect, + ) { let actual: Vec<_> = kinds.iter().flat_map(|&kind| do_completion(ra_fixture, kind)).collect(); expect.assert_debug_eq(&actual); } #[track_caller] - fn check_function_relevance(ra_fixture: &str, expect: Expect) { + fn check_function_relevance(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let actual: Vec<_> = do_completion(ra_fixture, CompletionItemKind::SymbolKind(SymbolKind::Method)) .into_iter() @@ -717,7 +725,11 @@ mod tests { } #[track_caller] - fn check_relevance_for_kinds(ra_fixture: &str, kinds: &[CompletionItemKind], expect: Expect) { + fn check_relevance_for_kinds( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + kinds: &[CompletionItemKind], + expect: Expect, + ) { let mut actual = get_all_items(TEST_CONFIG, ra_fixture, None); actual.retain(|it| kinds.contains(&it.kind)); actual.sort_by_key(|it| cmp::Reverse(it.relevance.score())); @@ -725,7 +737,7 @@ mod tests { } #[track_caller] - fn check_relevance(ra_fixture: &str, expect: Expect) { + fn check_relevance(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let mut actual = get_all_items(TEST_CONFIG, ra_fixture, None); actual.retain(|it| it.kind != CompletionItemKind::Snippet); actual.retain(|it| it.kind != CompletionItemKind::Keyword); diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs index 71d143a2b7..a37cf59485 100644 --- a/crates/ide-completion/src/tests.rs +++ b/crates/ide-completion/src/tests.rs @@ -89,22 +89,24 @@ pub(crate) const TEST_CONFIG: CompletionConfig<'_> = CompletionConfig { exclude_traits: &[], }; -pub(crate) fn completion_list(ra_fixture: &str) -> String { +pub(crate) fn completion_list(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String { completion_list_with_config(TEST_CONFIG, ra_fixture, true, None) } -pub(crate) fn completion_list_no_kw(ra_fixture: &str) -> String { +pub(crate) fn completion_list_no_kw(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String { completion_list_with_config(TEST_CONFIG, ra_fixture, false, None) } -pub(crate) fn completion_list_no_kw_with_private_editable(ra_fixture: &str) -> String { +pub(crate) fn completion_list_no_kw_with_private_editable( + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) -> String { let mut config = TEST_CONFIG; config.enable_private_editable = true; completion_list_with_config(config, ra_fixture, false, None) } pub(crate) fn completion_list_with_trigger_character( - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, trigger_character: Option, ) -> String { completion_list_with_config(TEST_CONFIG, ra_fixture, true, trigger_character) @@ -112,7 +114,7 @@ pub(crate) fn completion_list_with_trigger_character( fn completion_list_with_config_raw( config: CompletionConfig<'_>, - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, include_keywords: bool, trigger_character: Option, ) -> Vec { @@ -135,7 +137,7 @@ fn completion_list_with_config_raw( fn completion_list_with_config( config: CompletionConfig<'_>, - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, include_keywords: bool, trigger_character: Option, ) -> String { @@ -148,7 +150,9 @@ fn completion_list_with_config( } /// Creates analysis from a multi-file fixture, returns positions marked with $0. -pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { +pub(crate) fn position( + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) -> (RootDatabase, FilePosition) { let change_fixture = ChangeFixture::parse(ra_fixture); let mut database = RootDatabase::default(); database.enable_proc_attr_macros(); @@ -253,27 +257,33 @@ pub(crate) fn check_edit_with_config( assert_eq_text!(&ra_fixture_after, &actual) } -pub(crate) fn check(ra_fixture: &str, expect: Expect) { +pub(crate) fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let actual = completion_list(ra_fixture); expect.assert_eq(&actual); } -pub(crate) fn check_with_base_items(ra_fixture: &str, expect: Expect) { +pub(crate) fn check_with_base_items( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, +) { check(&format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"), expect) } -pub(crate) fn check_no_kw(ra_fixture: &str, expect: Expect) { +pub(crate) fn check_no_kw(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let actual = completion_list_no_kw(ra_fixture); expect.assert_eq(&actual) } -pub(crate) fn check_with_private_editable(ra_fixture: &str, expect: Expect) { +pub(crate) fn check_with_private_editable( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, +) { let actual = completion_list_no_kw_with_private_editable(ra_fixture); expect.assert_eq(&actual); } pub(crate) fn check_with_trigger_character( - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, trigger_character: Option, expect: Expect, ) { diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index 3cc7fc9d92..d0dc6206f4 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -10,7 +10,11 @@ use crate::{ CompletionConfig, }; -fn check_with_config(config: CompletionConfig<'_>, ra_fixture: &str, expect: Expect) { +fn check_with_config( + config: CompletionConfig<'_>, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, +) { let actual = completion_list_with_config( config, &format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"), diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs index d413977f7c..0adf1b825f 100644 --- a/crates/ide-completion/src/tests/flyimport.rs +++ b/crates/ide-completion/src/tests/flyimport.rs @@ -6,11 +6,15 @@ use crate::{ CompletionConfig, }; -fn check(ra_fixture: &str, expect: Expect) { +fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { check_with_config(TEST_CONFIG, ra_fixture, expect); } -fn check_with_config(config: CompletionConfig<'_>, ra_fixture: &str, expect: Expect) { +fn check_with_config( + config: CompletionConfig<'_>, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, +) { let (db, position) = crate::tests::position(ra_fixture); let (ctx, analysis) = crate::context::CompletionContext::new(&db, position, &config).unwrap(); diff --git a/crates/ide-completion/src/tests/raw_identifiers.rs b/crates/ide-completion/src/tests/raw_identifiers.rs index d81b3d697a..9ab66243b5 100644 --- a/crates/ide-completion/src/tests/raw_identifiers.rs +++ b/crates/ide-completion/src/tests/raw_identifiers.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use crate::tests::{completion_list_with_config_raw, position, TEST_CONFIG}; -fn check(ra_fixture: &str, expect: Expect) { +fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let completions = completion_list_with_config_raw(TEST_CONFIG, ra_fixture, true, None); let (db, position) = position(ra_fixture); let mut actual = db.file_text(position.file_id).to_string(); diff --git a/crates/ide-db/src/active_parameter.rs b/crates/ide-db/src/active_parameter.rs index 7482491fc6..11808fed3b 100644 --- a/crates/ide-db/src/active_parameter.rs +++ b/crates/ide-db/src/active_parameter.rs @@ -4,7 +4,7 @@ use either::Either; use hir::{InFile, Semantics, Type}; use parser::T; use syntax::{ - ast::{self, HasArgList, HasName}, + ast::{self, AstChildren, HasArgList, HasAttrs, HasName}, match_ast, AstNode, NodeOrToken, SyntaxToken, }; @@ -37,6 +37,10 @@ impl ActiveParameter { _ => None, }) } + + pub fn attrs(&self) -> Option> { + self.src.as_ref().and_then(|param| Some(param.value.as_ref().right()?.attrs())) + } } /// Returns a [`hir::Callable`] this token is a part of and its argument index of said callable. diff --git a/crates/ide-db/src/imports/insert_use/tests.rs b/crates/ide-db/src/imports/insert_use/tests.rs index 81604b5527..3e3aa266f7 100644 --- a/crates/ide-db/src/imports/insert_use/tests.rs +++ b/crates/ide-db/src/imports/insert_use/tests.rs @@ -1330,7 +1330,7 @@ fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehavior assert_eq!(result.map(|u| u.to_string()), None); } -fn check_guess(ra_fixture: &str, expected: ImportGranularityGuess) { +fn check_guess(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: ImportGranularityGuess) { let syntax = ast::SourceFile::parse(ra_fixture, span::Edition::CURRENT).tree().syntax().clone(); let file = ImportScope::from(syntax).unwrap(); assert_eq!(super::guess_granularity_from_scope(&file), expected); diff --git a/crates/ide-db/src/syntax_helpers/suggest_name.rs b/crates/ide-db/src/syntax_helpers/suggest_name.rs index 365d726d2a..557c95f704 100644 --- a/crates/ide-db/src/syntax_helpers/suggest_name.rs +++ b/crates/ide-db/src/syntax_helpers/suggest_name.rs @@ -421,7 +421,7 @@ mod tests { use super::*; #[track_caller] - fn check(ra_fixture: &str, expected: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: &str) { let (db, file_id, range_or_offset) = RootDatabase::with_range_or_offset(ra_fixture); let frange = FileRange { file_id, range: range_or_offset.into() }; diff --git a/crates/ide-db/src/traits.rs b/crates/ide-db/src/traits.rs index 82aca50d03..0f67496d09 100644 --- a/crates/ide-db/src/traits.rs +++ b/crates/ide-db/src/traits.rs @@ -123,7 +123,9 @@ mod tests { use crate::RootDatabase; /// Creates analysis from a multi-file fixture, returns positions marked with $0. - pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { + pub(crate) fn position( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + ) -> (RootDatabase, FilePosition) { let change_fixture = ChangeFixture::parse(ra_fixture); let mut database = RootDatabase::default(); database.apply_change(change_fixture.change); @@ -133,7 +135,7 @@ mod tests { (database, FilePosition { file_id, offset }) } - fn check_trait(ra_fixture: &str, expect: Expect) { + fn check_trait(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (db, position) = position(ra_fixture); let sema = Semantics::new(&db); let file = sema.parse(position.file_id); @@ -147,7 +149,7 @@ mod tests { expect.assert_eq(&actual); } - fn check_missing_assoc(ra_fixture: &str, expect: Expect) { + fn check_missing_assoc(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (db, position) = position(ra_fixture); let sema = Semantics::new(&db); let file = sema.parse(position.file_id); diff --git a/crates/ide-diagnostics/src/handlers/inactive_code.rs b/crates/ide-diagnostics/src/handlers/inactive_code.rs index 4c0c685e55..96a368eb0e 100644 --- a/crates/ide-diagnostics/src/handlers/inactive_code.rs +++ b/crates/ide-diagnostics/src/handlers/inactive_code.rs @@ -41,7 +41,7 @@ pub(crate) fn inactive_code( mod tests { use crate::{tests::check_diagnostics_with_config, DiagnosticsConfig}; - pub(crate) fn check(ra_fixture: &str) { + pub(crate) fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let config = DiagnosticsConfig { disabled: std::iter::once("unlinked-file".to_owned()).collect(), ..DiagnosticsConfig::test_sample() diff --git a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs index 08e6e7dced..0bf600e5df 100644 --- a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs +++ b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs @@ -26,7 +26,7 @@ mod tests { use test_utils::skip_slow_tests; #[track_caller] - fn check_diagnostics_no_bails(ra_fixture: &str) { + fn check_diagnostics_no_bails(#[rust_analyzer::rust_fixture] ra_fixture: &str) { cov_mark::check_count!(validate_match_bailed_out, 0); crate::tests::check_diagnostics(ra_fixture) } diff --git a/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs b/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs index f481365f2a..4aff446de6 100644 --- a/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs +++ b/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs @@ -61,7 +61,7 @@ mod tests { }; #[track_caller] - pub(crate) fn check_diagnostics(ra_fixture: &str) { + pub(crate) fn check_diagnostics(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let mut config = DiagnosticsConfig::test_sample(); config.disabled.insert("inactive-code".to_owned()); config.disabled.insert("E0599".to_owned()); diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs index 7cf51f3d14..605a6f69fc 100644 --- a/crates/ide-diagnostics/src/tests.rs +++ b/crates/ide-diagnostics/src/tests.rs @@ -191,7 +191,7 @@ pub(crate) fn check_has_single_fix(ra_fixture_before: &str, ra_fixture_after: &s } /// Checks that there's a diagnostic *without* fix at `$0`. -pub(crate) fn check_no_fix(ra_fixture: &str) { +pub(crate) fn check_no_fix(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (db, file_position) = RootDatabase::with_position(ra_fixture); let diagnostic = super::full_diagnostics( &db, @@ -205,21 +205,27 @@ pub(crate) fn check_no_fix(ra_fixture: &str) { } #[track_caller] -pub(crate) fn check_diagnostics(ra_fixture: &str) { +pub(crate) fn check_diagnostics(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let mut config = DiagnosticsConfig::test_sample(); config.disabled.insert("inactive-code".to_owned()); check_diagnostics_with_config(config, ra_fixture) } #[track_caller] -pub(crate) fn check_diagnostics_with_disabled(ra_fixture: &str, disabled: &[&str]) { +pub(crate) fn check_diagnostics_with_disabled( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + disabled: &[&str], +) { let mut config = DiagnosticsConfig::test_sample(); config.disabled.extend(disabled.iter().map(|&s| s.to_owned())); check_diagnostics_with_config(config, ra_fixture) } #[track_caller] -pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixture: &str) { +pub(crate) fn check_diagnostics_with_config( + config: DiagnosticsConfig, + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) { let (db, files) = RootDatabase::with_many_files(ra_fixture); let mut annotations = files .iter() diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 6a4e5ba290..18f866eb9f 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -220,7 +220,11 @@ mod tests { location: AnnotationLocation::AboveName, }; - fn check_with_config(ra_fixture: &str, expect: Expect, config: &AnnotationConfig) { + fn check_with_config( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, + config: &AnnotationConfig, + ) { let (analysis, file_id) = fixture::file(ra_fixture); let annotations: Vec = analysis @@ -233,7 +237,7 @@ mod tests { expect.assert_debug_eq(&annotations); } - fn check(ra_fixture: &str, expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { check_with_config(ra_fixture, expect, &DEFAULT_CONFIG); } diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 8066894cd8..afd6f740c4 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -173,7 +173,7 @@ mod tests { fn check_hierarchy( exclude_tests: bool, - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, expected_nav: Expect, expected_incoming: Expect, expected_outgoing: Expect, diff --git a/crates/ide/src/doc_links/tests.rs b/crates/ide/src/doc_links/tests.rs index fe91c81a61..d7291c4b9f 100644 --- a/crates/ide/src/doc_links/tests.rs +++ b/crates/ide/src/doc_links/tests.rs @@ -16,7 +16,7 @@ use crate::{ }; fn check_external_docs( - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, target_dir: Option<&str>, expect_web_url: Option, expect_local_url: Option, @@ -41,7 +41,7 @@ fn check_external_docs( } } -fn check_rewrite(ra_fixture: &str, expect: Expect) { +fn check_rewrite(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let sema = &Semantics::new(&*analysis.db); let (cursor_def, docs) = def_under_cursor(sema, &position); @@ -49,7 +49,7 @@ fn check_rewrite(ra_fixture: &str, expect: Expect) { expect.assert_eq(&res) } -fn check_doc_links(ra_fixture: &str) { +fn check_doc_links(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let key_fn = |&(FileRange { file_id, range }, _): &_| (file_id, range.start()); let (analysis, position, mut expected) = fixture::annotations(ra_fixture); diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index e028c5ff0c..0ad894427b 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -296,7 +296,7 @@ mod tests { use crate::fixture; #[track_caller] - fn check(ra_fixture: &str, expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, pos) = fixture::position(ra_fixture); let expansion = analysis.expand_macro(pos).unwrap().unwrap(); let actual = format!("{}\n{}", expansion.name, expansion.expansion); diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index 5ef65c209c..50977ee840 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs @@ -257,7 +257,7 @@ mod tests { use super::*; - fn check(ra_fixture: &str, expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let file = SourceFile::parse(ra_fixture, span::Edition::CURRENT).ok().unwrap(); let structure = file_structure(&file); expect.assert_debug_eq(&structure) diff --git a/crates/ide/src/fixture.rs b/crates/ide/src/fixture.rs index b16511072b..a0612f48d3 100644 --- a/crates/ide/src/fixture.rs +++ b/crates/ide/src/fixture.rs @@ -5,7 +5,7 @@ use test_utils::{extract_annotations, RangeOrOffset}; use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; /// Creates analysis for a single file. -pub(crate) fn file(ra_fixture: &str) -> (Analysis, FileId) { +pub(crate) fn file(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (Analysis, FileId) { let mut host = AnalysisHost::default(); let change_fixture = ChangeFixture::parse(ra_fixture); host.db.enable_proc_attr_macros(); @@ -14,7 +14,9 @@ pub(crate) fn file(ra_fixture: &str) -> (Analysis, FileId) { } /// Creates analysis from a multi-file fixture, returns positions marked with $0. -pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) { +pub(crate) fn position( + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) -> (Analysis, FilePosition) { let mut host = AnalysisHost::default(); let change_fixture = ChangeFixture::parse(ra_fixture); host.db.enable_proc_attr_macros(); @@ -25,7 +27,7 @@ pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) { } /// Creates analysis for a single file, returns range marked with a pair of $0. -pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) { +pub(crate) fn range(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (Analysis, FileRange) { let mut host = AnalysisHost::default(); let change_fixture = ChangeFixture::parse(ra_fixture); host.db.enable_proc_attr_macros(); @@ -36,7 +38,9 @@ pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) { } /// Creates analysis for a single file, returns range marked with a pair of $0 or a position marked with $0. -pub(crate) fn range_or_position(ra_fixture: &str) -> (Analysis, FileId, RangeOrOffset) { +pub(crate) fn range_or_position( + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) -> (Analysis, FileId, RangeOrOffset) { let mut host = AnalysisHost::default(); let change_fixture = ChangeFixture::parse(ra_fixture); host.db.enable_proc_attr_macros(); @@ -46,7 +50,9 @@ pub(crate) fn range_or_position(ra_fixture: &str) -> (Analysis, FileId, RangeOrO } /// Creates analysis from a multi-file fixture, returns positions marked with $0. -pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(FileRange, String)>) { +pub(crate) fn annotations( + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) -> (Analysis, FilePosition, Vec<(FileRange, String)>) { let mut host = AnalysisHost::default(); let change_fixture = ChangeFixture::parse(ra_fixture); host.db.enable_proc_attr_macros(); @@ -69,7 +75,9 @@ pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(Fil } /// Creates analysis from a multi-file fixture with annotations without $0 -pub(crate) fn annotations_without_marker(ra_fixture: &str) -> (Analysis, Vec<(FileRange, String)>) { +pub(crate) fn annotations_without_marker( + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) -> (Analysis, Vec<(FileRange, String)>) { let mut host = AnalysisHost::default(); let change_fixture = ChangeFixture::parse(ra_fixture); host.db.enable_proc_attr_macros(); diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index c1b7693a65..e5a94ff9fe 100755 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -286,7 +286,7 @@ mod tests { use super::*; - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (ranges, text) = extract_tags(ra_fixture, "fold"); let parse = SourceFile::parse(&text, span::Edition::CURRENT); diff --git a/crates/ide/src/goto_declaration.rs b/crates/ide/src/goto_declaration.rs index 7b6a5ef13e..3742edc8db 100644 --- a/crates/ide/src/goto_declaration.rs +++ b/crates/ide/src/goto_declaration.rs @@ -83,7 +83,7 @@ mod tests { use crate::fixture; - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position, expected) = fixture::annotations(ra_fixture); let navs = analysis .goto_declaration(position) diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 6c66907ec3..6c739de82d 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -424,7 +424,7 @@ mod tests { use syntax::SmolStr; #[track_caller] - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position, expected) = fixture::annotations(ra_fixture); let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info; @@ -443,14 +443,14 @@ mod tests { assert_eq!(expected, navs); } - fn check_unresolved(ra_fixture: &str) { + fn check_unresolved(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position) = fixture::position(ra_fixture); let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info; assert!(navs.is_empty(), "didn't expect this to resolve anywhere: {navs:?}") } - fn check_name(expected_name: &str, ra_fixture: &str) { + fn check_name(expected_name: &str, #[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position, _) = fixture::annotations(ra_fixture); let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info; assert!(navs.len() < 2, "expected single navigation target but encountered {}", navs.len()); diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index 04da1f67e9..e926378367 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs @@ -129,7 +129,7 @@ mod tests { use crate::fixture; - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position, expected) = fixture::annotations(ra_fixture); let navs = analysis.goto_implementation(position).unwrap().unwrap().info; diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs index c7ebd9a353..3d827f64f7 100644 --- a/crates/ide/src/goto_type_definition.rs +++ b/crates/ide/src/goto_type_definition.rs @@ -118,7 +118,7 @@ mod tests { use crate::fixture; - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position, expected) = fixture::annotations(ra_fixture); let navs = analysis.goto_type_definition(position).unwrap().unwrap().info; assert!(!navs.is_empty(), "navigation is empty"); diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index 4002cbebad..612bc36f62 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -684,12 +684,15 @@ mod tests { }; #[track_caller] - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config(ra_fixture, ENABLED_CONFIG); } #[track_caller] - fn check_with_config(ra_fixture: &str, config: HighlightRelatedConfig) { + fn check_with_config( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + config: HighlightRelatedConfig, + ) { let (analysis, pos, annotations) = fixture::annotations(ra_fixture); let hls = analysis.highlight_related(config, pos).unwrap().unwrap_or_default(); diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 501dd642a8..4edfa6d5c3 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -23,7 +23,7 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig { max_subst_ty_len: super::SubstTyLen::Unlimited, }; -fn check_hover_no_result(ra_fixture: &str) { +fn check_hover_no_result(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position) = fixture::position(ra_fixture); let hover = analysis .hover( @@ -35,7 +35,7 @@ fn check_hover_no_result(ra_fixture: &str) { } #[track_caller] -fn check(ra_fixture: &str, expect: Expect) { +fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let hover = analysis .hover( @@ -55,7 +55,7 @@ fn check(ra_fixture: &str, expect: Expect) { #[track_caller] fn check_hover_fields_limit( fields_count: impl Into>, - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect, ) { let (analysis, position) = fixture::position(ra_fixture); @@ -81,7 +81,7 @@ fn check_hover_fields_limit( #[track_caller] fn check_hover_enum_variants_limit( variants_count: impl Into>, - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect, ) { let (analysis, position) = fixture::position(ra_fixture); @@ -105,7 +105,11 @@ fn check_hover_enum_variants_limit( } #[track_caller] -fn check_assoc_count(count: usize, ra_fixture: &str, expect: Expect) { +fn check_assoc_count( + count: usize, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, +) { let (analysis, position) = fixture::position(ra_fixture); let hover = analysis .hover( @@ -126,7 +130,7 @@ fn check_assoc_count(count: usize, ra_fixture: &str, expect: Expect) { expect.assert_eq(&actual) } -fn check_hover_no_links(ra_fixture: &str, expect: Expect) { +fn check_hover_no_links(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let hover = analysis .hover( @@ -143,7 +147,7 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) { expect.assert_eq(&actual) } -fn check_hover_no_memory_layout(ra_fixture: &str, expect: Expect) { +fn check_hover_no_memory_layout(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let hover = analysis .hover( @@ -160,7 +164,7 @@ fn check_hover_no_memory_layout(ra_fixture: &str, expect: Expect) { expect.assert_eq(&actual) } -fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) { +fn check_hover_no_markdown(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let hover = analysis .hover( @@ -181,7 +185,7 @@ fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) { expect.assert_eq(&actual) } -fn check_actions(ra_fixture: &str, expect: Expect) { +fn check_actions(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, file_id, position) = fixture::range_or_position(ra_fixture); let mut hover = analysis .hover( @@ -206,13 +210,13 @@ fn check_actions(ra_fixture: &str, expect: Expect) { expect.assert_debug_eq(&hover.info.actions) } -fn check_hover_range(ra_fixture: &str, expect: Expect) { +fn check_hover_range(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, range) = fixture::range(ra_fixture); let hover = analysis.hover(&HOVER_BASE_CONFIG, range).unwrap().unwrap(); expect.assert_eq(hover.info.markup.as_str()) } -fn check_hover_range_actions(ra_fixture: &str, expect: Expect) { +fn check_hover_range_actions(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, range) = fixture::range(ra_fixture); let mut hover = analysis .hover(&HoverConfig { links_in_hover: true, ..HOVER_BASE_CONFIG }, range) @@ -234,7 +238,7 @@ fn check_hover_range_actions(ra_fixture: &str, expect: Expect) { expect.assert_debug_eq(&hover.info.actions); } -fn check_hover_range_no_results(ra_fixture: &str) { +fn check_hover_range_no_results(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, range) = fixture::range(ra_fixture); let hover = analysis.hover(&HOVER_BASE_CONFIG, range).unwrap(); assert!(hover.is_none()); diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 1c08e0b560..040f1f72a6 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -798,12 +798,15 @@ mod tests { }; #[track_caller] - pub(super) fn check(ra_fixture: &str) { + pub(super) fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config(TEST_CONFIG, ra_fixture); } #[track_caller] - pub(super) fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { + pub(super) fn check_with_config( + config: InlayHintsConfig, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + ) { let (analysis, file_id) = fixture::file(ra_fixture); let mut expected = extract_annotations(&analysis.file_text(file_id).unwrap()); let inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap(); @@ -819,7 +822,11 @@ mod tests { } #[track_caller] - pub(super) fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) { + pub(super) fn check_expect( + config: InlayHintsConfig, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, + ) { let (analysis, file_id) = fixture::file(ra_fixture); let inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap(); let filtered = @@ -830,7 +837,11 @@ mod tests { /// Computes inlay hints for the fixture, applies all the provided text edits and then runs /// expect test. #[track_caller] - pub(super) fn check_edit(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) { + pub(super) fn check_edit( + config: InlayHintsConfig, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, + ) { let (analysis, file_id) = fixture::file(ra_fixture); let inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap(); @@ -849,7 +860,10 @@ mod tests { } #[track_caller] - pub(super) fn check_no_edit(config: InlayHintsConfig, ra_fixture: &str) { + pub(super) fn check_no_edit( + config: InlayHintsConfig, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + ) { let (analysis, file_id) = fixture::file(ra_fixture); let inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap(); diff --git a/crates/ide/src/inlay_hints/bind_pat.rs b/crates/ide/src/inlay_hints/bind_pat.rs index 7a808fb4a9..1c2289158b 100644 --- a/crates/ide/src/inlay_hints/bind_pat.rs +++ b/crates/ide/src/inlay_hints/bind_pat.rs @@ -185,7 +185,7 @@ mod tests { }; #[track_caller] - fn check_types(ra_fixture: &str) { + fn check_types(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config(InlayHintsConfig { type_hints: true, ..DISABLED_CONFIG }, ra_fixture); } diff --git a/crates/ide/src/inlay_hints/bounds.rs b/crates/ide/src/inlay_hints/bounds.rs index 334f3ca631..429ddd31cb 100644 --- a/crates/ide/src/inlay_hints/bounds.rs +++ b/crates/ide/src/inlay_hints/bounds.rs @@ -83,7 +83,7 @@ mod tests { use crate::inlay_hints::tests::{check_expect, check_with_config, DISABLED_CONFIG}; #[track_caller] - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config(InlayHintsConfig { sized_bound: true, ..DISABLED_CONFIG }, ra_fixture); } diff --git a/crates/ide/src/inlay_hints/chaining.rs b/crates/ide/src/inlay_hints/chaining.rs index 8eeacb6e8d..7fa7ab1a94 100644 --- a/crates/ide/src/inlay_hints/chaining.rs +++ b/crates/ide/src/inlay_hints/chaining.rs @@ -86,14 +86,14 @@ mod tests { }; #[track_caller] - fn check_chains(ra_fixture: &str) { + fn check_chains(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config(InlayHintsConfig { chaining_hints: true, ..DISABLED_CONFIG }, ra_fixture); } #[track_caller] pub(super) fn check_expect_clear_loc( config: InlayHintsConfig, - ra_fixture: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect, ) { let (analysis, file_id) = fixture::file(ra_fixture); diff --git a/crates/ide/src/inlay_hints/discriminant.rs b/crates/ide/src/inlay_hints/discriminant.rs index 8f2949cb38..9aef859333 100644 --- a/crates/ide/src/inlay_hints/discriminant.rs +++ b/crates/ide/src/inlay_hints/discriminant.rs @@ -105,7 +105,7 @@ mod tests { }; #[track_caller] - fn check_discriminants(ra_fixture: &str) { + fn check_discriminants(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config( InlayHintsConfig { discriminant_hints: DiscriminantHints::Always, ..DISABLED_CONFIG }, ra_fixture, @@ -113,7 +113,7 @@ mod tests { } #[track_caller] - fn check_discriminants_fieldless(ra_fixture: &str) { + fn check_discriminants_fieldless(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config( InlayHintsConfig { discriminant_hints: DiscriminantHints::Fieldless, diff --git a/crates/ide/src/inlay_hints/generic_param.rs b/crates/ide/src/inlay_hints/generic_param.rs index ed7ebc3b1e..037b328d97 100644 --- a/crates/ide/src/inlay_hints/generic_param.rs +++ b/crates/ide/src/inlay_hints/generic_param.rs @@ -142,7 +142,7 @@ mod tests { }; #[track_caller] - fn generic_param_name_hints_always(ra_fixture: &str) { + fn generic_param_name_hints_always(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config( InlayHintsConfig { generic_parameter_hints: GenericParameterHints { @@ -157,7 +157,7 @@ mod tests { } #[track_caller] - fn generic_param_name_hints_const_only(ra_fixture: &str) { + fn generic_param_name_hints_const_only(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config( InlayHintsConfig { generic_parameter_hints: GenericParameterHints { diff --git a/crates/ide/src/inlay_hints/param_name.rs b/crates/ide/src/inlay_hints/param_name.rs index a03ff6a52b..a7b066700c 100644 --- a/crates/ide/src/inlay_hints/param_name.rs +++ b/crates/ide/src/inlay_hints/param_name.rs @@ -269,7 +269,7 @@ mod tests { }; #[track_caller] - fn check_params(ra_fixture: &str) { + fn check_params(#[rust_analyzer::rust_fixture] ra_fixture: &str) { check_with_config( InlayHintsConfig { parameter_hints: true, ..DISABLED_CONFIG }, ra_fixture, diff --git a/crates/ide/src/moniker.rs b/crates/ide/src/moniker.rs index 51f2809618..d97c12ebaf 100644 --- a/crates/ide/src/moniker.rs +++ b/crates/ide/src/moniker.rs @@ -405,7 +405,7 @@ mod tests { #[allow(dead_code)] #[track_caller] - fn no_moniker(ra_fixture: &str) { + fn no_moniker(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position) = fixture::position(ra_fixture); if let Some(x) = analysis.moniker(position).unwrap() { assert_eq!(x.info.len(), 0, "Moniker found but no moniker expected: {x:?}"); @@ -413,7 +413,12 @@ mod tests { } #[track_caller] - fn check_local_moniker(ra_fixture: &str, identifier: &str, package: &str, kind: MonikerKind) { + fn check_local_moniker( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + identifier: &str, + package: &str, + kind: MonikerKind, + ) { let (analysis, position) = fixture::position(ra_fixture); let x = analysis.moniker(position).unwrap().expect("no moniker found").info; assert_eq!(x.len(), 1); @@ -433,7 +438,12 @@ mod tests { } #[track_caller] - fn check_moniker(ra_fixture: &str, identifier: &str, package: &str, kind: MonikerKind) { + fn check_moniker( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + identifier: &str, + package: &str, + kind: MonikerKind, + ) { let (analysis, position) = fixture::position(ra_fixture); let x = analysis.moniker(position).unwrap().expect("no moniker found").info; assert_eq!(x.len(), 1); diff --git a/crates/ide/src/move_item.rs b/crates/ide/src/move_item.rs index a232df2b82..b0df9257ba 100644 --- a/crates/ide/src/move_item.rs +++ b/crates/ide/src/move_item.rs @@ -180,7 +180,11 @@ mod tests { use crate::Direction; - fn check(ra_fixture: &str, expect: Expect, direction: Direction) { + fn check( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, + direction: Direction, + ) { let (analysis, range) = fixture::range(ra_fixture); let edit = analysis.move_item(range, direction).unwrap().unwrap_or_default(); let mut file = analysis.file_text(range.file_id).unwrap().to_string(); diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index b51a5cc4f4..7a0c28d925 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -70,7 +70,7 @@ mod tests { use crate::fixture; - fn check(ra_fixture: &str) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let (analysis, position, expected) = fixture::annotations(ra_fixture); let navs = analysis.parent_module(position).unwrap(); let navs = navs diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 46714df8d6..b1079312d3 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -1255,11 +1255,15 @@ impl Foo { ); } - fn check(ra_fixture: &str, expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { check_with_scope(ra_fixture, None, expect) } - fn check_with_scope(ra_fixture: &str, search_scope: Option, expect: Expect) { + fn check_with_scope( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + search_scope: Option, + expect: Expect, + ) { let (analysis, pos) = fixture::position(ra_fixture); let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap(); diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs index 11bbd99110..fdf8fe452b 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -494,14 +494,22 @@ mod tests { }; } - fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) { + fn check_expect( + new_name: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, + ) { let (analysis, position) = fixture::position(ra_fixture); let source_change = analysis.rename(position, new_name).unwrap().expect("Expect returned a RenameError"); expect.assert_eq(&filter_expect(source_change)) } - fn check_expect_will_rename_file(new_name: &str, ra_fixture: &str, expect: Expect) { + fn check_expect_will_rename_file( + new_name: &str, + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect: Expect, + ) { let (analysis, position) = fixture::position(ra_fixture); let source_change = analysis .will_rename_file(position.file_id, new_name) @@ -510,7 +518,7 @@ mod tests { expect.assert_eq(&filter_expect(source_change)) } - fn check_prepare(ra_fixture: &str, expect: Expect) { + fn check_prepare(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let result = analysis .prepare_rename(position) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 3e39c750b1..32edacee51 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -748,7 +748,7 @@ mod tests { use crate::fixture; - fn check(ra_fixture: &str, expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let result = analysis .runnables(position.file_id) @@ -769,7 +769,7 @@ mod tests { expect.assert_debug_eq(&result); } - fn check_tests(ra_fixture: &str, expect: Expect) { + fn check_tests(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); let tests = analysis.related_tests(position, None).unwrap(); let navigation_targets = tests.into_iter().map(|runnable| runnable.nav).collect::>(); diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs index 84ccadc8c4..f8c60418eb 100644 --- a/crates/ide/src/signature_help.rs +++ b/crates/ide/src/signature_help.rs @@ -692,7 +692,9 @@ mod tests { use crate::RootDatabase; /// Creates analysis from a multi-file fixture, returns positions marked with $0. - pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { + pub(crate) fn position( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + ) -> (RootDatabase, FilePosition) { let change_fixture = ChangeFixture::parse(ra_fixture); let mut database = RootDatabase::default(); database.apply_change(change_fixture.change); @@ -703,7 +705,7 @@ mod tests { } #[track_caller] - fn check(ra_fixture: &str, expect: Expect) { + fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let fixture = format!( r#" //- minicore: sized, fn diff --git a/crates/ide/src/ssr.rs b/crates/ide/src/ssr.rs index 6def28e0b7..77a011cac1 100644 --- a/crates/ide/src/ssr.rs +++ b/crates/ide/src/ssr.rs @@ -67,7 +67,10 @@ mod tests { use super::ssr_assists; - fn get_assists(ra_fixture: &str, resolve: AssistResolveStrategy) -> Vec { + fn get_assists( + #[rust_analyzer::rust_fixture] 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(test_fixture::WORKSPACE); diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs index 60d8259c53..8050a38b3c 100644 --- a/crates/ide/src/static_index.rs +++ b/crates/ide/src/static_index.rs @@ -291,7 +291,10 @@ mod tests { use super::VendoredLibrariesConfig; - fn check_all_ranges(ra_fixture: &str, vendored_libs_config: VendoredLibrariesConfig<'_>) { + fn check_all_ranges( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + vendored_libs_config: VendoredLibrariesConfig<'_>, + ) { let (analysis, ranges) = fixture::annotations_without_marker(ra_fixture); let s = StaticIndex::compute(&analysis, vendored_libs_config); let mut range_set: FxHashSet<_> = ranges.iter().map(|it| it.0).collect(); @@ -310,7 +313,10 @@ mod tests { } #[track_caller] - fn check_definitions(ra_fixture: &str, vendored_libs_config: VendoredLibrariesConfig<'_>) { + fn check_definitions( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + vendored_libs_config: VendoredLibrariesConfig<'_>, + ) { let (analysis, ranges) = fixture::annotations_without_marker(ra_fixture); let s = StaticIndex::compute(&analysis, vendored_libs_config); let mut range_set: FxHashSet<_> = ranges.iter().map(|it| it.0).collect(); diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 1a9c1beba1..1be90ad6a1 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -28,7 +28,14 @@ pub(super) fn ra_fixture( expanded: &ast::String, ) -> Option<()> { let active_parameter = ActiveParameter::at_token(sema, expanded.syntax().clone())?; - if !active_parameter.ident().is_some_and(|name| name.text().starts_with("ra_fixture")) { + let has_rust_fixture_attr = active_parameter.attrs().is_some_and(|attrs| { + attrs.filter_map(|attr| attr.as_simple_path()).any(|path| { + path.segments() + .zip(["rust_analyzer", "rust_fixture"]) + .all(|(seg, name)| seg.name_ref().map_or(false, |nr| nr.text() == name)) + }) + }); + if !has_rust_fixture_attr { return None; } let value = literal.value().ok()?; diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html index 6c3fbcfcf4..5fbed35192 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html @@ -45,7 +45,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; } .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
fn fixture(ra_fixture: &str) {}
+
fn fixture(#[rust_analyzer::rust_fixture] ra_fixture: &str) {}
 
 fn main() {
     fixture(r#"
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index a20147add3..af52b33de6 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -990,7 +990,7 @@ impl t for foo {
 fn test_injection() {
     check_highlighting(
         r##"
-fn fixture(ra_fixture: &str) {}
+fn fixture(#[rust_analyzer::rust_fixture] ra_fixture: &str) {}
 
 fn main() {
     fixture(r#"
@@ -1188,7 +1188,11 @@ fn foo(x: &fn(&dyn Trait)) {}
 /// Highlights the code given by the `ra_fixture` argument, renders the
 /// result as HTML, and compares it with the HTML file given as `snapshot`.
 /// Note that the `snapshot` file is overwritten by the rendered HTML.
-fn check_highlighting(ra_fixture: &str, expect: ExpectFile, rainbow: bool) {
+fn check_highlighting(
+    #[rust_analyzer::rust_fixture] ra_fixture: &str,
+    expect: ExpectFile,
+    rainbow: bool,
+) {
     let (analysis, file_id) = fixture::file(ra_fixture.trim());
     let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
     expect.assert_eq(actual_html)
diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs
index 8998934e0e..0ef9c4185b 100644
--- a/crates/ide/src/typing.rs
+++ b/crates/ide/src/typing.rs
@@ -889,7 +889,7 @@ fn main() {
         type_char_noop(
             '{',
             r##"
-fn check_with(ra_fixture: &str, expect: Expect) {
+fn check_with(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
     let base = r#"
 enum E { T(), R$0, C }
 use self::E::X;
@@ -1191,7 +1191,7 @@ fn f(n: a<>b::::c) {}
         type_char_noop(
             '(',
             r##"
-fn check_with(ra_fixture: &str, expect: Expect) {
+fn check_with(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
     let base = r#"
 enum E { T(), R$0, C }
 use self::E::X;
diff --git a/crates/ide/src/view_memory_layout.rs b/crates/ide/src/view_memory_layout.rs
index 830c39e21e..ff74e05e94 100644
--- a/crates/ide/src/view_memory_layout.rs
+++ b/crates/ide/src/view_memory_layout.rs
@@ -220,7 +220,9 @@ mod tests {
     use crate::fixture;
     use expect_test::expect;
 
-    fn make_memory_layout(ra_fixture: &str) -> Option {
+    fn make_memory_layout(
+        #[rust_analyzer::rust_fixture] ra_fixture: &str,
+    ) -> Option {
         let (analysis, position, _) = fixture::annotations(ra_fixture);
 
         view_memory_layout(&analysis.db, position)
diff --git a/crates/ide/src/view_syntax_tree.rs b/crates/ide/src/view_syntax_tree.rs
index b2adff0f36..218ee15a7d 100644
--- a/crates/ide/src/view_syntax_tree.rs
+++ b/crates/ide/src/view_syntax_tree.rs
@@ -148,7 +148,7 @@ mod tests {
 
     use crate::fixture;
 
-    fn check(ra_fixture: &str, expect: expect_test::Expect) {
+    fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: expect_test::Expect) {
         let (analysis, file_id) = fixture::file(ra_fixture);
         let syn = analysis.view_syntax_tree(file_id).unwrap();
         expect.assert_eq(&syn)
diff --git a/crates/proc-macro-srv/src/tests/utils.rs b/crates/proc-macro-srv/src/tests/utils.rs
index 42f0a7f59b..4ce4544243 100644
--- a/crates/proc-macro-srv/src/tests/utils.rs
+++ b/crates/proc-macro-srv/src/tests/utils.rs
@@ -28,13 +28,18 @@ fn parse_string_spanned(
     ))
 }
 
-pub fn assert_expand(macro_name: &str, ra_fixture: &str, expect: Expect, expect_s: Expect) {
+pub fn assert_expand(
+    macro_name: &str,
+    #[rust_analyzer::rust_fixture] ra_fixture: &str,
+    expect: Expect,
+    expect_s: Expect,
+) {
     assert_expand_impl(macro_name, ra_fixture, None, expect, expect_s);
 }
 
 pub fn assert_expand_attr(
     macro_name: &str,
-    ra_fixture: &str,
+    #[rust_analyzer::rust_fixture] ra_fixture: &str,
     attr_args: &str,
     expect: Expect,
     expect_s: Expect,
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index 6ca7d9ac05..dc0f722aae 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -518,7 +518,7 @@ mod test {
     use test_fixture::ChangeFixture;
     use vfs::VfsPath;
 
-    fn position(ra_fixture: &str) -> (AnalysisHost, FilePosition) {
+    fn position(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (AnalysisHost, FilePosition) {
         let mut host = AnalysisHost::default();
         let change_fixture = ChangeFixture::parse(ra_fixture);
         host.raw_database_mut().apply_change(change_fixture.change);
@@ -530,7 +530,7 @@ mod test {
 
     /// If expected == "", then assert that there are no symbols (this is basically local symbol)
     #[track_caller]
-    fn check_symbol(ra_fixture: &str, expected: &str) {
+    fn check_symbol(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: &str) {
         let (host, position) = position(ra_fixture);
 
         let analysis = host.analysis();
diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs
index fe4d02dcb4..0dda7044f1 100644
--- a/crates/rust-analyzer/src/lsp/to_proto.rs
+++ b/crates/rust-analyzer/src/lsp/to_proto.rs
@@ -1993,7 +1993,7 @@ fn bar(_: usize) {}
 
     #[track_caller]
     fn check_rendered_snippets_in_source(
-        ra_fixture: &str,
+        #[rust_analyzer::rust_fixture] ra_fixture: &str,
         edit: TextEdit,
         snippets: SnippetEdit,
         expect: Expect,
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 81c7e15bcb..56f94b965e 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -185,6 +185,14 @@ impl ast::Attr {
         Some((self.simple_name()?, tt))
     }
 
+    pub fn as_simple_path(&self) -> Option {
+        let meta = self.meta()?;
+        if meta.eq_token().is_some() || meta.token_tree().is_some() {
+            return None;
+        }
+        self.path()
+    }
+
     pub fn simple_name(&self) -> Option {
         let path = self.meta()?.path()?;
         match (path.segment(), path.qualifier()) {
diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs
index 422aa08e35..866379d940 100644
--- a/crates/test-fixture/src/lib.rs
+++ b/crates/test-fixture/src/lib.rs
@@ -30,7 +30,9 @@ pub const WORKSPACE: base_db::SourceRootId = base_db::SourceRootId(0);
 
 pub trait WithFixture: Default + ExpandDatabase + SourceRootDatabase + 'static {
     #[track_caller]
-    fn with_single_file(ra_fixture: &str) -> (Self, EditionedFileId) {
+    fn with_single_file(
+        #[rust_analyzer::rust_fixture] ra_fixture: &str,
+    ) -> (Self, EditionedFileId) {
         let fixture = ChangeFixture::parse(ra_fixture);
         let mut db = Self::default();
         fixture.change.apply(&mut db);
@@ -39,7 +41,9 @@ pub trait WithFixture: Default + ExpandDatabase + SourceRootDatabase + 'static {
     }
 
     #[track_caller]
-    fn with_many_files(ra_fixture: &str) -> (Self, Vec) {
+    fn with_many_files(
+        #[rust_analyzer::rust_fixture] ra_fixture: &str,
+    ) -> (Self, Vec) {
         let fixture = ChangeFixture::parse(ra_fixture);
         let mut db = Self::default();
         fixture.change.apply(&mut db);
@@ -48,7 +52,7 @@ pub trait WithFixture: Default + ExpandDatabase + SourceRootDatabase + 'static {
     }
 
     #[track_caller]
-    fn with_files(ra_fixture: &str) -> Self {
+    fn with_files(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> Self {
         let fixture = ChangeFixture::parse(ra_fixture);
         let mut db = Self::default();
         fixture.change.apply(&mut db);
@@ -58,7 +62,7 @@ pub trait WithFixture: Default + ExpandDatabase + SourceRootDatabase + 'static {
 
     #[track_caller]
     fn with_files_extra_proc_macros(
-        ra_fixture: &str,
+        #[rust_analyzer::rust_fixture] ra_fixture: &str,
         proc_macros: Vec<(String, ProcMacro)>,
     ) -> Self {
         let fixture = ChangeFixture::parse_with_proc_macros(ra_fixture, proc_macros);
@@ -69,21 +73,23 @@ pub trait WithFixture: Default + ExpandDatabase + SourceRootDatabase + 'static {
     }
 
     #[track_caller]
-    fn with_position(ra_fixture: &str) -> (Self, FilePosition) {
+    fn with_position(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (Self, FilePosition) {
         let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture);
         let offset = range_or_offset.expect_offset();
         (db, FilePosition { file_id, offset })
     }
 
     #[track_caller]
-    fn with_range(ra_fixture: &str) -> (Self, FileRange) {
+    fn with_range(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (Self, FileRange) {
         let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture);
         let range = range_or_offset.expect_range();
         (db, FileRange { file_id, range })
     }
 
     #[track_caller]
-    fn with_range_or_offset(ra_fixture: &str) -> (Self, EditionedFileId, RangeOrOffset) {
+    fn with_range_or_offset(
+        #[rust_analyzer::rust_fixture] ra_fixture: &str,
+    ) -> (Self, EditionedFileId, RangeOrOffset) {
         let fixture = ChangeFixture::parse(ra_fixture);
         let mut db = Self::default();
         fixture.change.apply(&mut db);
@@ -116,12 +122,12 @@ pub struct ChangeFixture {
 const SOURCE_ROOT_PREFIX: &str = "/";
 
 impl ChangeFixture {
-    pub fn parse(ra_fixture: &str) -> ChangeFixture {
+    pub fn parse(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> ChangeFixture {
         Self::parse_with_proc_macros(ra_fixture, Vec::new())
     }
 
     pub fn parse_with_proc_macros(
-        ra_fixture: &str,
+        #[rust_analyzer::rust_fixture] ra_fixture: &str,
         mut proc_macro_defs: Vec<(String, ProcMacro)>,
     ) -> ChangeFixture {
         let FixtureWithProjectMeta {
diff --git a/crates/test-utils/src/fixture.rs b/crates/test-utils/src/fixture.rs
index 54c9db7aac..7fe26d53bf 100644
--- a/crates/test-utils/src/fixture.rs
+++ b/crates/test-utils/src/fixture.rs
@@ -168,7 +168,7 @@ impl FixtureWithProjectMeta {
     /// That will set toolchain to nightly and include predefined proc macros and a subset of
     /// `libcore` into the fixture, see `minicore.rs` for what's available. Note that toolchain
     /// defaults to stable.
-    pub fn parse(ra_fixture: &str) -> Self {
+    pub fn parse(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> Self {
         let fixture = trim_indent(ra_fixture);
         let mut fixture = fixture.as_str();
         let mut toolchain = None;