Skip to content

Commit 150e384

Browse files
Merge #5845
5845: Omit lenses for not runnable doctests r=matklad a=SomeoneToIgnore Ideally, we should properly parse the doctest attributes before, but since I need it for the code lens only, this way should suffice for now Co-authored-by: Kirill Bulatov <[email protected]>
2 parents b00702b + cdd75a6 commit 150e384

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

crates/ide/src/completion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub use crate::completion::{
9292
/// already present, it should give all possible variants for the identifier at
9393
/// the caret. In other words, for
9494
///
95-
/// ```no-run
95+
/// ```no_run
9696
/// fn f() {
9797
/// let foo = 92;
9898
/// let _ = bar<|>

crates/ide/src/runnables.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn runnable_fn(
160160
RunnableKind::Test { test_id, attr }
161161
} else if fn_def.has_atom_attr("bench") {
162162
RunnableKind::Bench { test_id }
163-
} else if has_doc_test(&fn_def) {
163+
} else if has_runnable_doc_test(&fn_def) {
164164
RunnableKind::DocTest { test_id }
165165
} else {
166166
return None;
@@ -211,8 +211,13 @@ fn has_test_related_attribute(fn_def: &ast::Fn) -> bool {
211211
.any(|attribute_text| attribute_text.contains("test"))
212212
}
213213

214-
fn has_doc_test(fn_def: &ast::Fn) -> bool {
215-
fn_def.doc_comment_text().map_or(false, |comment| comment.contains("```"))
214+
fn has_runnable_doc_test(fn_def: &ast::Fn) -> bool {
215+
fn_def.doc_comment_text().map_or(false, |comments_text| {
216+
comments_text.contains("```")
217+
&& !comments_text.contains("```ignore")
218+
&& !comments_text.contains("```no_run")
219+
&& !comments_text.contains("```compile_fail")
220+
})
216221
}
217222

218223
fn runnable_mod(
@@ -417,6 +422,21 @@ fn main() {}
417422
/// let x = 5;
418423
/// ```
419424
fn foo() {}
425+
426+
/// ```no_run
427+
/// let z = 55;
428+
/// ```
429+
fn should_have_no_runnable() {}
430+
431+
/// ```ignore
432+
/// let z = 55;
433+
/// ```
434+
fn should_have_no_runnable_2() {}
435+
436+
/// ```compile_fail
437+
/// let z = 55;
438+
/// ```
439+
fn should_have_no_runnable_3() {}
420440
"#,
421441
&[&BIN, &DOCTEST],
422442
expect![[r#"

crates/syntax/src/algo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn ancestors_at_offset(
3232
/// imprecise: if the cursor is strictly between two nodes of the desired type,
3333
/// as in
3434
///
35-
/// ```no-run
35+
/// ```no_run
3636
/// struct Foo {}|struct Bar;
3737
/// ```
3838
///

0 commit comments

Comments
 (0)