From 03735be3174d195c3de53051dd7194283266368c Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sun, 17 May 2020 00:43:42 +0200 Subject: fix doctest inside impl block #4449 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/runnables.rs | 70 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index fa8a9d92c..009ea813a 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::Semantics; +use hir::{AsAssocItem, HirDisplay, Semantics}; use itertools::Itertools; use ra_ide_db::RootDatabase; use ra_syntax::{ @@ -65,14 +65,36 @@ fn runnable_fn(sema: &Semantics, fn_def: ast::FnDef) -> Option { + Some(trait_item.name(sema.db).to_string()) + } + hir::AssocItemContainer::ImplDef(impl_def) => impl_def + .target_ty(sema.db) + .as_adt() + .map(|adt| adt.name(sema.db).to_string()), + } + }); + + let path_iter = module .path_to_root(sema.db) .into_iter() .rev() .filter_map(|it| it.name(sema.db)) - .map(|name| name.to_string()) - .chain(std::iter::once(name_string)) - .join("::"); + .map(|name| name.to_string()); + + let path = if let Some(impl_trait_name) = impl_trait_name { + path_iter + .chain(std::iter::once(impl_trait_name)) + .chain(std::iter::once(name_string)) + .join("::") + } else { + path_iter.chain(std::iter::once(name_string)).join("::") + }; + TestId::Path(path) } else { TestId::Name(name_string) @@ -237,6 +259,44 @@ mod tests { ); } + #[test] + fn test_runnables_doc_test_in_impl() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + fn main() {} + + struct Data; + impl Data { + /// ``` + /// let x = 5; + /// ``` + fn foo() {} + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_debug_snapshot!(&runnables, + @r###" + [ + Runnable { + range: 1..21, + kind: Bin, + }, + Runnable { + range: 52..106, + kind: DocTest { + test_id: Path( + "Data::foo", + ), + }, + }, + ] + "### + ); + } + #[test] fn test_runnables_module() { let (analysis, pos) = analysis_and_position( -- cgit v1.2.3 From 947f95193a52ebdda3f727500144fe1f6d292868 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sun, 17 May 2020 11:09:38 +0200 Subject: fix doctest inside impl block #4449 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/runnables.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 009ea813a..72eced343 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{AsAssocItem, HirDisplay, Semantics}; +use hir::{AsAssocItem, Semantics}; use itertools::Itertools; use ra_ide_db::RootDatabase; use ra_syntax::{ @@ -266,7 +266,7 @@ mod tests { //- /lib.rs <|> //empty fn main() {} - + struct Data; impl Data { /// ``` -- cgit v1.2.3 From 01688f8d4f21a8c22582ff68ee995dd0d4a134b9 Mon Sep 17 00:00:00 2001 From: Coenen Benjamin Date: Sun, 17 May 2020 12:10:35 +0200 Subject: Fix doctests in an Impl block --- crates/ra_ide/src/runnables.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 72eced343..131b8f307 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -285,7 +285,7 @@ mod tests { kind: Bin, }, Runnable { - range: 52..106, + range: 51..105, kind: DocTest { test_id: Path( "Data::foo", -- cgit v1.2.3