aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorBenjamin Coenen <[email protected]>2020-06-09 20:28:51 +0100
committerBenjamin Coenen <[email protected]>2020-06-09 20:28:51 +0100
commit9d0a6aaee388c6bba43806c72e81a21ac7e07008 (patch)
treec8df3efb4f08daca0328e51df29af23ce4feddf7 /crates/ra_ide/src
parentba821afa248153a58eede29048d2b21d30a2ea55 (diff)
display Doctest code lens before comment #4785
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs25
-rw-r--r--crates/ra_ide/src/runnables.rs10
2 files changed, 32 insertions, 3 deletions
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;
4use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource}; 4use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource};
5use ra_db::{FileId, SourceDatabase}; 5use ra_db::{FileId, SourceDatabase};
6use ra_ide_db::{defs::Definition, RootDatabase}; 6use ra_ide_db::{defs::Definition, RootDatabase};
7use ra_syntax::ast::AstToken;
7use ra_syntax::{ 8use ra_syntax::{
8 ast::{self, DocCommentsOwner, NameOwner}, 9 ast::{self, DocCommentsOwner, NameOwner},
9 match_ast, AstNode, SmolStr, 10 match_ast, AstNode, SmolStr,
@@ -135,8 +136,8 @@ impl NavigationTarget {
135 db: &RootDatabase, 136 db: &RootDatabase,
136 node: InFile<&dyn ast::NameOwner>, 137 node: InFile<&dyn ast::NameOwner>,
137 ) -> NavigationTarget { 138 ) -> NavigationTarget {
138 //FIXME: use `_` instead of empty string 139 let name =
139 let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default(); 140 node.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_"));
140 let focus_range = 141 let focus_range =
141 node.value.name().map(|it| original_range(db, node.with_value(it.syntax())).range); 142 node.value.name().map(|it| original_range(db, node.with_value(it.syntax())).range);
142 let frange = original_range(db, node.map(|it| it.syntax())); 143 let frange = original_range(db, node.map(|it| it.syntax()));
@@ -150,6 +151,26 @@ impl NavigationTarget {
150 ) 151 )
151 } 152 }
152 153
154 /// Allows `NavigationTarget` to be created from a `DocCommentsOwner` and a `NameOwner`
155 pub(crate) fn from_doc_commented(
156 db: &RootDatabase,
157 named: InFile<&dyn ast::NameOwner>,
158 node: InFile<&dyn ast::DocCommentsOwner>,
159 ) -> NavigationTarget {
160 let name =
161 named.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_"));
162 let focus_range = node.value.doc_comments().next().map(|it| it.syntax().text_range());
163 let frange = original_range(db, node.map(|it| it.syntax()));
164
165 NavigationTarget::from_syntax(
166 frange.file_id,
167 name,
168 focus_range,
169 frange.range,
170 node.value.syntax().kind(),
171 )
172 }
173
153 fn from_syntax( 174 fn from_syntax(
154 file_id: FileId, 175 file_id: FileId,
155 name: SmolStr, 176 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(
171 let cfg_exprs = 171 let cfg_exprs =
172 attrs.by_key("cfg").tt_values().map(|subtree| ra_cfg::parse_cfg(subtree)).collect(); 172 attrs.by_key("cfg").tt_values().map(|subtree| ra_cfg::parse_cfg(subtree)).collect();
173 173
174 let nav = NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def)); 174 let nav = if let RunnableKind::DocTest { .. } = kind {
175 NavigationTarget::from_doc_commented(
176 sema.db,
177 InFile::new(file_id.into(), &fn_def),
178 InFile::new(file_id.into(), &fn_def),
179 )
180 } else {
181 NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def))
182 };
175 Some(Runnable { nav, kind, cfg_exprs }) 183 Some(Runnable { nav, kind, cfg_exprs })
176} 184}
177 185