diff options
Diffstat (limited to 'crates/libanalysis')
-rw-r--r-- | crates/libanalysis/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/libanalysis/src/job.rs | 49 | ||||
-rw-r--r-- | crates/libanalysis/src/lib.rs | 4 |
3 files changed, 54 insertions, 0 deletions
diff --git a/crates/libanalysis/Cargo.toml b/crates/libanalysis/Cargo.toml index 1f072533c..9c7977e92 100644 --- a/crates/libanalysis/Cargo.toml +++ b/crates/libanalysis/Cargo.toml | |||
@@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
6 | [dependencies] | 6 | [dependencies] |
7 | relative-path = "0.3.7" | 7 | relative-path = "0.3.7" |
8 | log = "0.4.2" | 8 | log = "0.4.2" |
9 | crossbeam-channel = "0.2.4" | ||
9 | parking_lot = "0.6.3" | 10 | parking_lot = "0.6.3" |
10 | once_cell = "0.1.4" | 11 | once_cell = "0.1.4" |
11 | rayon = "1.0.2" | 12 | rayon = "1.0.2" |
diff --git a/crates/libanalysis/src/job.rs b/crates/libanalysis/src/job.rs new file mode 100644 index 000000000..4d393b915 --- /dev/null +++ b/crates/libanalysis/src/job.rs | |||
@@ -0,0 +1,49 @@ | |||
1 | use crossbeam_channel::{bounded, Receiver, Sender}; | ||
2 | |||
3 | pub struct JobHandle { | ||
4 | job_alive: Receiver<Never>, | ||
5 | _job_canceled: Sender<Never>, | ||
6 | } | ||
7 | |||
8 | pub struct JobToken { | ||
9 | _job_alive: Sender<Never>, | ||
10 | job_canceled: Receiver<Never>, | ||
11 | } | ||
12 | |||
13 | impl JobHandle { | ||
14 | pub fn new() -> (JobHandle, JobToken) { | ||
15 | let (sender_alive, receiver_alive) = bounded(0); | ||
16 | let (sender_canceled, receiver_canceled) = bounded(0); | ||
17 | let token = JobToken { _job_alive: sender_alive, job_canceled: receiver_canceled }; | ||
18 | let handle = JobHandle { job_alive: receiver_alive, _job_canceled: sender_canceled }; | ||
19 | (handle, token) | ||
20 | } | ||
21 | pub fn is_alive(&self) -> bool { | ||
22 | !is_closed(&self.job_alive) | ||
23 | } | ||
24 | pub fn cancel(self) { | ||
25 | } | ||
26 | } | ||
27 | |||
28 | impl JobToken { | ||
29 | pub fn is_canceled(&self) -> bool { | ||
30 | is_closed(&self.job_canceled) | ||
31 | } | ||
32 | } | ||
33 | |||
34 | |||
35 | // We don't actually send messages through the channels, | ||
36 | // and instead just check if the channel is closed, | ||
37 | // so we use uninhabited enum as a message type | ||
38 | enum Never {} | ||
39 | |||
40 | /// Nonblocking | ||
41 | fn is_closed(chan: &Receiver<Never>) -> bool { | ||
42 | select! { | ||
43 | recv(chan, msg) => match msg { | ||
44 | None => true, | ||
45 | Some(never) => match never {} | ||
46 | } | ||
47 | default => false, | ||
48 | } | ||
49 | } | ||
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index c25d31f4b..20ddb69d6 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -7,10 +7,13 @@ extern crate libeditor; | |||
7 | extern crate fst; | 7 | extern crate fst; |
8 | extern crate rayon; | 8 | extern crate rayon; |
9 | extern crate relative_path; | 9 | extern crate relative_path; |
10 | #[macro_use] | ||
11 | extern crate crossbeam_channel; | ||
10 | 12 | ||
11 | mod symbol_index; | 13 | mod symbol_index; |
12 | mod module_map; | 14 | mod module_map; |
13 | mod imp; | 15 | mod imp; |
16 | mod job; | ||
14 | 17 | ||
15 | use std::sync::Arc; | 18 | use std::sync::Arc; |
16 | 19 | ||
@@ -22,6 +25,7 @@ pub use libeditor::{ | |||
22 | StructureNode, LineIndex, FileSymbol, | 25 | StructureNode, LineIndex, FileSymbol, |
23 | Runnable, RunnableKind, HighlightedRange, CompletionItem, | 26 | Runnable, RunnableKind, HighlightedRange, CompletionItem, |
24 | }; | 27 | }; |
28 | pub use job::{JobToken, JobHandle}; | ||
25 | 29 | ||
26 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 30 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
27 | pub struct FileId(pub u32); | 31 | pub struct FileId(pub u32); |