mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
parent
6908268712
commit
05daa86634
8 changed files with 288 additions and 63 deletions
|
@ -22,7 +22,7 @@ pub use self::{
|
|||
use ra_text_edit::{TextEdit, TextEditBuilder};
|
||||
use ra_syntax::{
|
||||
algo::find_leaf_at_offset,
|
||||
ast::{self, AstNode, NameOwner},
|
||||
ast::{self, AstNode},
|
||||
SourceFileNode,
|
||||
SyntaxKind::{self, *},
|
||||
SyntaxNodeRef, TextRange, TextUnit, Direction,
|
||||
|
@ -49,18 +49,6 @@ pub struct Diagnostic {
|
|||
pub fix: Option<LocalEdit>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Runnable {
|
||||
pub range: TextRange,
|
||||
pub kind: RunnableKind,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RunnableKind {
|
||||
Test { name: String },
|
||||
Bin,
|
||||
}
|
||||
|
||||
pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
|
||||
const BRACES: &[SyntaxKind] = &[
|
||||
L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE,
|
||||
|
@ -133,29 +121,6 @@ pub fn syntax_tree(file: &SourceFileNode) -> String {
|
|||
::ra_syntax::utils::dump_tree(file.syntax())
|
||||
}
|
||||
|
||||
pub fn runnables(file: &SourceFileNode) -> Vec<Runnable> {
|
||||
file.syntax()
|
||||
.descendants()
|
||||
.filter_map(ast::FnDef::cast)
|
||||
.filter_map(|f| {
|
||||
let name = f.name()?.text();
|
||||
let kind = if name == "main" {
|
||||
RunnableKind::Bin
|
||||
} else if f.has_atom_attr("test") {
|
||||
RunnableKind::Test {
|
||||
name: name.to_string(),
|
||||
}
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
Some(Runnable {
|
||||
range: f.syntax().range(),
|
||||
kind,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn find_node_at_offset<'a, N: AstNode<'a>>(
|
||||
syntax: SyntaxNodeRef<'a>,
|
||||
offset: TextUnit,
|
||||
|
@ -190,29 +155,6 @@ fn main() {}
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_runnables() {
|
||||
let file = SourceFileNode::parse(
|
||||
r#"
|
||||
fn main() {}
|
||||
|
||||
#[test]
|
||||
fn test_foo() {}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_foo() {}
|
||||
"#,
|
||||
);
|
||||
let runnables = runnables(&file);
|
||||
assert_eq_dbg(
|
||||
r#"[Runnable { range: [1; 13), kind: Bin },
|
||||
Runnable { range: [15; 39), kind: Test { name: "test_foo" } },
|
||||
Runnable { range: [41; 75), kind: Test { name: "test_foo" } }]"#,
|
||||
&runnables,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_matching_brace() {
|
||||
fn do_check(before: &str, after: &str) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue