mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Simplify
This commit is contained in:
parent
5d401092f0
commit
941d4bfa53
1 changed files with 6 additions and 15 deletions
|
@ -49,7 +49,7 @@ impl fmt::Display for FlycheckConfig {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FlycheckHandle {
|
pub struct FlycheckHandle {
|
||||||
// XXX: drop order is significant
|
// XXX: drop order is significant
|
||||||
cmd_send: Sender<CheckCommand>,
|
cmd_send: Sender<Restart>,
|
||||||
handle: jod_thread::JoinHandle,
|
handle: jod_thread::JoinHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ impl FlycheckHandle {
|
||||||
config: FlycheckConfig,
|
config: FlycheckConfig,
|
||||||
workspace_root: PathBuf,
|
workspace_root: PathBuf,
|
||||||
) -> FlycheckHandle {
|
) -> FlycheckHandle {
|
||||||
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
|
let (cmd_send, cmd_recv) = unbounded::<Restart>();
|
||||||
let handle = jod_thread::spawn(move || {
|
let handle = jod_thread::spawn(move || {
|
||||||
FlycheckActor::new(sender, config, workspace_root).run(&cmd_recv);
|
FlycheckActor::new(sender, config, workspace_root).run(&cmd_recv);
|
||||||
});
|
});
|
||||||
|
@ -68,7 +68,7 @@ impl FlycheckHandle {
|
||||||
|
|
||||||
/// Schedule a re-start of the cargo check worker.
|
/// Schedule a re-start of the cargo check worker.
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
self.cmd_send.send(CheckCommand::Update).unwrap();
|
self.cmd_send.send(Restart).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,10 +91,7 @@ pub enum Progress {
|
||||||
End,
|
End,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CheckCommand {
|
struct Restart;
|
||||||
/// Request re-start of check thread
|
|
||||||
Update,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FlycheckActor {
|
struct FlycheckActor {
|
||||||
sender: Box<dyn Fn(Message) + Send>,
|
sender: Box<dyn Fn(Message) + Send>,
|
||||||
|
@ -127,14 +124,14 @@ impl FlycheckActor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&mut self, cmd_recv: &Receiver<CheckCommand>) {
|
fn run(&mut self, cmd_recv: &Receiver<Restart>) {
|
||||||
// If we rerun the thread, we need to discard the previous check results first
|
// If we rerun the thread, we need to discard the previous check results first
|
||||||
self.clean_previous_results();
|
self.clean_previous_results();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
select! {
|
select! {
|
||||||
recv(&cmd_recv) -> cmd => match cmd {
|
recv(&cmd_recv) -> cmd => match cmd {
|
||||||
Ok(cmd) => self.handle_command(cmd),
|
Ok(Restart) => self.last_update_req = Some(Instant::now()),
|
||||||
Err(RecvError) => {
|
Err(RecvError) => {
|
||||||
// Command channel has closed, so shut down
|
// Command channel has closed, so shut down
|
||||||
break;
|
break;
|
||||||
|
@ -174,12 +171,6 @@ impl FlycheckActor {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_command(&mut self, cmd: CheckCommand) {
|
|
||||||
match cmd {
|
|
||||||
CheckCommand::Update => self.last_update_req = Some(Instant::now()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_message(&self, msg: CheckEvent) {
|
fn handle_message(&self, msg: CheckEvent) {
|
||||||
match msg {
|
match msg {
|
||||||
CheckEvent::Begin => {
|
CheckEvent::Begin => {
|
||||||
|
|
Loading…
Reference in a new issue