From 9d0a6aaee388c6bba43806c72e81a21ac7e07008 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:28:51 +0200 Subject: display Doctest code lens before comment #4785 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/display/navigation_target.rs | 25 +++++++++++++++++++++++-- crates/ra_ide/src/runnables.rs | 10 +++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index c7bb1e69f..820be583f 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -4,6 +4,7 @@ use either::Either; use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource}; use ra_db::{FileId, SourceDatabase}; use ra_ide_db::{defs::Definition, RootDatabase}; +use ra_syntax::ast::AstToken; use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, match_ast, AstNode, SmolStr, @@ -135,8 +136,8 @@ impl NavigationTarget { db: &RootDatabase, node: InFile<&dyn ast::NameOwner>, ) -> NavigationTarget { - //FIXME: use `_` instead of empty string - let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default(); + let name = + node.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_")); let focus_range = node.value.name().map(|it| original_range(db, node.with_value(it.syntax())).range); let frange = original_range(db, node.map(|it| it.syntax())); @@ -150,6 +151,26 @@ impl NavigationTarget { ) } + /// Allows `NavigationTarget` to be created from a `DocCommentsOwner` and a `NameOwner` + pub(crate) fn from_doc_commented( + db: &RootDatabase, + named: InFile<&dyn ast::NameOwner>, + node: InFile<&dyn ast::DocCommentsOwner>, + ) -> NavigationTarget { + let name = + named.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_")); + let focus_range = node.value.doc_comments().next().map(|it| it.syntax().text_range()); + let frange = original_range(db, node.map(|it| it.syntax())); + + NavigationTarget::from_syntax( + frange.file_id, + name, + focus_range, + frange.range, + node.value.syntax().kind(), + ) + } + fn from_syntax( file_id: FileId, name: SmolStr, diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index fc57dc33d..be60b5323 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -171,7 +171,15 @@ fn runnable_fn( let cfg_exprs = attrs.by_key("cfg").tt_values().map(|subtree| ra_cfg::parse_cfg(subtree)).collect(); - let nav = NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def)); + let nav = if let RunnableKind::DocTest { .. } = kind { + NavigationTarget::from_doc_commented( + sema.db, + InFile::new(file_id.into(), &fn_def), + InFile::new(file_id.into(), &fn_def), + ) + } else { + NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def)) + }; Some(Runnable { nav, kind, cfg_exprs }) } -- cgit v1.2.3 From 36d9105d0e3b023b30e1c232701952395c68ce01 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:50:24 +0200 Subject: display Doctest code lens before comment #4785 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 be60b5323..7c505a765 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -428,7 +428,7 @@ mod tests { name: "foo", kind: FN_DEF, focus_range: Some( - 56..59, + 22..29, ), container_name: None, description: None, @@ -495,7 +495,7 @@ mod tests { name: "foo", kind: FN_DEF, focus_range: Some( - 97..100, + 51..58, ), container_name: None, description: None, -- cgit v1.2.3 From 2732fdb5956851671d9e0339d80371e39a5a2361 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Thu, 18 Jun 2020 11:31:15 +0200 Subject: display Doctest code lens before comment #4785 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/display/navigation_target.rs | 4 +--- crates/ra_ide/src/runnables.rs | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 820be583f..0b52b01ab 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -4,7 +4,6 @@ use either::Either; use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource}; use ra_db::{FileId, SourceDatabase}; use ra_ide_db::{defs::Definition, RootDatabase}; -use ra_syntax::ast::AstToken; use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, match_ast, AstNode, SmolStr, @@ -159,13 +158,12 @@ impl NavigationTarget { ) -> NavigationTarget { let name = named.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_")); - let focus_range = node.value.doc_comments().next().map(|it| it.syntax().text_range()); let frange = original_range(db, node.map(|it| it.syntax())); NavigationTarget::from_syntax( frange.file_id, name, - focus_range, + None, frange.range, node.value.syntax().kind(), ) diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 7c505a765..8105ef373 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -427,9 +427,7 @@ mod tests { full_range: 22..64, name: "foo", kind: FN_DEF, - focus_range: Some( - 22..29, - ), + focus_range: None, container_name: None, description: None, docs: None, @@ -494,9 +492,7 @@ mod tests { full_range: 51..105, name: "foo", kind: FN_DEF, - focus_range: Some( - 51..58, - ), + focus_range: None, container_name: None, description: None, docs: None, -- cgit v1.2.3