mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Omit lenses for not runnable doctests
This commit is contained in:
parent
e65d48d1fb
commit
cdd75a699a
3 changed files with 25 additions and 5 deletions
|
@ -92,7 +92,7 @@ pub use crate::completion::{
|
||||||
/// already present, it should give all possible variants for the identifier at
|
/// already present, it should give all possible variants for the identifier at
|
||||||
/// the caret. In other words, for
|
/// the caret. In other words, for
|
||||||
///
|
///
|
||||||
/// ```no-run
|
/// ```no_run
|
||||||
/// fn f() {
|
/// fn f() {
|
||||||
/// let foo = 92;
|
/// let foo = 92;
|
||||||
/// let _ = bar<|>
|
/// let _ = bar<|>
|
||||||
|
|
|
@ -160,7 +160,7 @@ fn runnable_fn(
|
||||||
RunnableKind::Test { test_id, attr }
|
RunnableKind::Test { test_id, attr }
|
||||||
} else if fn_def.has_atom_attr("bench") {
|
} else if fn_def.has_atom_attr("bench") {
|
||||||
RunnableKind::Bench { test_id }
|
RunnableKind::Bench { test_id }
|
||||||
} else if has_doc_test(&fn_def) {
|
} else if has_runnable_doc_test(&fn_def) {
|
||||||
RunnableKind::DocTest { test_id }
|
RunnableKind::DocTest { test_id }
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
|
@ -211,8 +211,13 @@ fn has_test_related_attribute(fn_def: &ast::Fn) -> bool {
|
||||||
.any(|attribute_text| attribute_text.contains("test"))
|
.any(|attribute_text| attribute_text.contains("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_doc_test(fn_def: &ast::Fn) -> bool {
|
fn has_runnable_doc_test(fn_def: &ast::Fn) -> bool {
|
||||||
fn_def.doc_comment_text().map_or(false, |comment| comment.contains("```"))
|
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(
|
fn runnable_mod(
|
||||||
|
@ -417,6 +422,21 @@ fn main() {}
|
||||||
/// let x = 5;
|
/// let x = 5;
|
||||||
/// ```
|
/// ```
|
||||||
fn foo() {}
|
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],
|
&[&BIN, &DOCTEST],
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn ancestors_at_offset(
|
||||||
/// imprecise: if the cursor is strictly between two nodes of the desired type,
|
/// imprecise: if the cursor is strictly between two nodes of the desired type,
|
||||||
/// as in
|
/// as in
|
||||||
///
|
///
|
||||||
/// ```no-run
|
/// ```no_run
|
||||||
/// struct Foo {}|struct Bar;
|
/// struct Foo {}|struct Bar;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue