From 755077e3720bd97e1e506bf8fbe0a2534389f282 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 18:10:25 +0100 Subject: Doctest autoimport --- crates/ra_assists/src/assists/auto_import.rs | 4 +++- crates/ra_assists/src/doc_tests.rs | 10 ++-------- crates/ra_assists/src/doc_tests/generated.rs | 4 +++- 3 files changed, 8 insertions(+), 10 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 219051063..f16b08c43 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs @@ -18,14 +18,16 @@ use ra_ide_db::imports_locator::ImportsLocatorIde; // fn main() { // let map = HashMap<|>::new(); // } +// # pub mod std { pub mod collections { pub struct HashMap { } } } // ``` // -> // ``` // use std::collections::HashMap; // // fn main() { -// let map = HashMap<|>::new(); +// let map = HashMap::new(); // } +// # pub mod std { pub mod collections { pub struct HashMap { } } } // ``` pub(crate) fn auto_import(ctx: AssistCtx) -> Option { let path_to_import: ast::Path = ctx.find_node_at_offset()?; diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs index 370b64225..56020028c 100644 --- a/crates/ra_assists/src/doc_tests.rs +++ b/crates/ra_assists/src/doc_tests.rs @@ -5,18 +5,12 @@ mod generated; -use ra_db::{fixture::WithFixture, FileRange}; +use ra_db::FileRange; use test_utils::{assert_eq_text, extract_range_or_offset}; -use ra_ide_db::RootDatabase; - fn check(assist_id: &str, before: &str, after: &str) { - // FIXME we cannot get the imports search functionality here yet, but still need to generate a test and a doc for an assist - if assist_id == "auto_import" { - return; - } let (selection, before) = extract_range_or_offset(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = crate::helpers::with_single_file(&before); let frange = FileRange { file_id, range: selection.into() }; let assist = crate::assists(&db, frange) diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs index ec4587ce7..0d95b957b 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs @@ -222,13 +222,15 @@ fn doctest_auto_import() { fn main() { let map = HashMap<|>::new(); } +pub mod std { pub mod collections { pub struct HashMap { } } } "#####, r#####" use std::collections::HashMap; fn main() { - let map = HashMap<|>::new(); + let map = HashMap::new(); } +pub mod std { pub mod collections { pub struct HashMap { } } } "#####, ) } -- cgit v1.2.3