diff options
Diffstat (limited to 'libeditor/src/lib.rs')
-rw-r--r-- | libeditor/src/lib.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libeditor/src/lib.rs b/libeditor/src/lib.rs index ef31efe35..387859d4a 100644 --- a/libeditor/src/lib.rs +++ b/libeditor/src/lib.rs | |||
@@ -26,6 +26,18 @@ pub struct Symbol { | |||
26 | pub range: TextRange, | 26 | pub range: TextRange, |
27 | } | 27 | } |
28 | 28 | ||
29 | #[derive(Debug)] | ||
30 | pub struct Runnable { | ||
31 | pub range: TextRange, | ||
32 | pub kind: RunnableKind, | ||
33 | } | ||
34 | |||
35 | #[derive(Debug)] | ||
36 | pub enum RunnableKind { | ||
37 | Test { name: String }, | ||
38 | Bin, | ||
39 | } | ||
40 | |||
29 | impl File { | 41 | impl File { |
30 | pub fn new(text: &str) -> File { | 42 | pub fn new(text: &str) -> File { |
31 | File { | 43 | File { |
@@ -78,6 +90,28 @@ impl File { | |||
78 | let syntax = self.inner.syntax(); | 90 | let syntax = self.inner.syntax(); |
79 | extend_selection::extend_selection(syntax.as_ref(), range) | 91 | extend_selection::extend_selection(syntax.as_ref(), range) |
80 | } | 92 | } |
93 | |||
94 | pub fn runnables(&self) -> Vec<Runnable> { | ||
95 | self.inner | ||
96 | .functions() | ||
97 | .filter_map(|f| { | ||
98 | let name = f.name()?.text(); | ||
99 | let kind = if name == "main" { | ||
100 | RunnableKind::Bin | ||
101 | } else if f.has_atom_attr("test") { | ||
102 | RunnableKind::Test { | ||
103 | name: name.to_string() | ||
104 | } | ||
105 | } else { | ||
106 | return None; | ||
107 | }; | ||
108 | Some(Runnable { | ||
109 | range: f.syntax().range(), | ||
110 | kind, | ||
111 | }) | ||
112 | }) | ||
113 | .collect() | ||
114 | } | ||
81 | } | 115 | } |
82 | 116 | ||
83 | 117 | ||