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 <mail4score@gmail.com>
This commit is contained in:
bors[bot] 2020-08-24 11:08:11 +00:00 committed by GitHub
commit 150e3843b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 5 deletions

View file

@ -92,7 +92,7 @@ pub use crate::completion::{
/// already present, it should give all possible variants for the identifier at
/// the caret. In other words, for
///
/// ```no-run
/// ```no_run
/// fn f() {
/// let foo = 92;
/// let _ = bar<|>

View file

@ -160,7 +160,7 @@ fn runnable_fn(
RunnableKind::Test { test_id, attr }
} else if fn_def.has_atom_attr("bench") {
RunnableKind::Bench { test_id }
} else if has_doc_test(&fn_def) {
} else if has_runnable_doc_test(&fn_def) {
RunnableKind::DocTest { test_id }
} else {
return None;
@ -211,8 +211,13 @@ fn has_test_related_attribute(fn_def: &ast::Fn) -> bool {
.any(|attribute_text| attribute_text.contains("test"))
}
fn has_doc_test(fn_def: &ast::Fn) -> bool {
fn_def.doc_comment_text().map_or(false, |comment| comment.contains("```"))
fn has_runnable_doc_test(fn_def: &ast::Fn) -> bool {
fn_def.doc_comment_text().map_or(false, |comments_text| {
comments_text.contains("```")
&& !comments_text.contains("```ignore")
&& !comments_text.contains("```no_run")
&& !comments_text.contains("```compile_fail")
})
}
fn runnable_mod(
@ -417,6 +422,21 @@ fn main() {}
/// let x = 5;
/// ```
fn foo() {}
/// ```no_run
/// let z = 55;
/// ```
fn should_have_no_runnable() {}
/// ```ignore
/// let z = 55;
/// ```
fn should_have_no_runnable_2() {}
/// ```compile_fail
/// let z = 55;
/// ```
fn should_have_no_runnable_3() {}
"#,
&[&BIN, &DOCTEST],
expect![[r#"

View file

@ -32,7 +32,7 @@ pub fn ancestors_at_offset(
/// imprecise: if the cursor is strictly between two nodes of the desired type,
/// as in
///
/// ```no-run
/// ```no_run
/// struct Foo {}|struct Bar;
/// ```
///