aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/runnables.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/runnables.rs')
-rw-r--r--crates/ide/src/runnables.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index e15411777..646f63704 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -6,7 +6,7 @@ use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
6use ide_db::RootDatabase; 6use ide_db::RootDatabase;
7use itertools::Itertools; 7use itertools::Itertools;
8use syntax::{ 8use syntax::{
9 ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner}, 9 ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner},
10 match_ast, SyntaxNode, 10 match_ast, SyntaxNode,
11}; 11};
12 12
@@ -118,6 +118,7 @@ fn runnable_fn(
118) -> Option<Runnable> { 118) -> Option<Runnable> {
119 let name_string = fn_def.name()?.text().to_string(); 119 let name_string = fn_def.name()?.text().to_string();
120 120
121 let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def));
121 let kind = if name_string == "main" { 122 let kind = if name_string == "main" {
122 RunnableKind::Bin 123 RunnableKind::Bin
123 } else { 124 } else {
@@ -162,14 +163,13 @@ fn runnable_fn(
162 RunnableKind::Test { test_id, attr } 163 RunnableKind::Test { test_id, attr }
163 } else if fn_def.has_atom_attr("bench") { 164 } else if fn_def.has_atom_attr("bench") {
164 RunnableKind::Bench { test_id } 165 RunnableKind::Bench { test_id }
165 } else if has_runnable_doc_test(&fn_def) { 166 } else if has_runnable_doc_test(&attrs) {
166 RunnableKind::DocTest { test_id } 167 RunnableKind::DocTest { test_id }
167 } else { 168 } else {
168 return None; 169 return None;
169 } 170 }
170 }; 171 };
171 172
172 let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def));
173 let cfg = attrs.cfg(); 173 let cfg = attrs.cfg();
174 174
175 let nav = if let RunnableKind::DocTest { .. } = kind { 175 let nav = if let RunnableKind::DocTest { .. } = kind {
@@ -189,13 +189,13 @@ fn runnable_struct(
189 struct_def: ast::Struct, 189 struct_def: ast::Struct,
190 file_id: FileId, 190 file_id: FileId,
191) -> Option<Runnable> { 191) -> Option<Runnable> {
192 if !has_runnable_doc_test(&struct_def) {
193 return None;
194 }
195 let name_string = struct_def.name()?.text().to_string(); 192 let name_string = struct_def.name()?.text().to_string();
196 193
197 let attrs = 194 let attrs =
198 Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def)); 195 Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def));
196 if !has_runnable_doc_test(&attrs) {
197 return None;
198 }
199 let cfg = attrs.cfg(); 199 let cfg = attrs.cfg();
200 200
201 let test_id = match sema.to_def(&struct_def).map(|def| def.module(sema.db)) { 201 let test_id = match sema.to_def(&struct_def).map(|def| def.module(sema.db)) {
@@ -240,11 +240,11 @@ const RUSTDOC_FENCE: &str = "```";
240const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] = 240const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] =
241 &["", "rust", "should_panic", "edition2015", "edition2018"]; 241 &["", "rust", "should_panic", "edition2015", "edition2018"];
242 242
243fn has_runnable_doc_test(def: &dyn DocCommentsOwner) -> bool { 243fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
244 def.doc_comment_text().map_or(false, |comments_text| { 244 attrs.docs().map_or(false, |doc| {
245 let mut in_code_block = false; 245 let mut in_code_block = false;
246 246
247 for line in comments_text.lines() { 247 for line in String::from(doc).lines() {
248 if let Some(header) = line.strip_prefix(RUSTDOC_FENCE) { 248 if let Some(header) = line.strip_prefix(RUSTDOC_FENCE) {
249 in_code_block = !in_code_block; 249 in_code_block = !in_code_block;
250 250