Unify style

This commit is contained in:
Aleksey Kladov 2020-06-25 08:59:55 +02:00
parent dab8808e82
commit 5a184fe855
4 changed files with 19 additions and 19 deletions

View file

@ -56,13 +56,13 @@ pub struct FlycheckHandle {
impl FlycheckHandle { impl FlycheckHandle {
pub fn spawn( pub fn spawn(
sender: Box<dyn Fn(CheckTask) + Send>,
config: FlycheckConfig, config: FlycheckConfig,
workspace_root: PathBuf, workspace_root: PathBuf,
sender: Box<dyn Fn(CheckTask) + Send>,
) -> FlycheckHandle { ) -> FlycheckHandle {
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
let handle = jod_thread::spawn(move || { let handle = jod_thread::spawn(move || {
FlycheckActor::new(config, workspace_root, sender).run(&cmd_recv); FlycheckActor::new(sender, config, workspace_root).run(&cmd_recv);
}); });
FlycheckHandle { cmd_send, handle } FlycheckHandle { cmd_send, handle }
} }
@ -114,9 +114,9 @@ struct FlycheckActor {
impl FlycheckActor { impl FlycheckActor {
fn new( fn new(
sender: Box<dyn Fn(CheckTask) + Send>,
config: FlycheckConfig, config: FlycheckConfig,
workspace_root: PathBuf, workspace_root: PathBuf,
sender: Box<dyn Fn(CheckTask) + Send>,
) -> FlycheckActor { ) -> FlycheckActor {
FlycheckActor { FlycheckActor {
sender, sender,

View file

@ -28,7 +28,7 @@ pub fn load_cargo(
let mut vfs = vfs::Vfs::default(); let mut vfs = vfs::Vfs::default();
let mut loader = { let mut loader = {
let loader = let loader =
vfs_notify::LoaderHandle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); vfs_notify::NotifyHandle::spawn(Box::new(move |msg| sender.send(msg).unwrap()));
Box::new(loader) Box::new(loader)
}; };

View file

@ -37,7 +37,7 @@ fn create_flycheck(
let (sender, receiver) = unbounded(); let (sender, receiver) = unbounded();
let sender = Box::new(move |msg| sender.send(msg).unwrap()); let sender = Box::new(move |msg| sender.send(msg).unwrap());
let cargo_project_root = cargo.workspace_root().to_path_buf(); let cargo_project_root = cargo.workspace_root().to_path_buf();
let flycheck = FlycheckHandle::spawn(config.clone(), cargo_project_root.into(), sender); let flycheck = FlycheckHandle::spawn(sender, config.clone(), cargo_project_root.into());
Some((flycheck, receiver)) Some((flycheck, receiver))
} }
ProjectWorkspace::Json { .. } => { ProjectWorkspace::Json { .. } => {
@ -121,7 +121,7 @@ impl GlobalState {
}; };
let mut loader = { let mut loader = {
let loader = vfs_notify::LoaderHandle::spawn(Box::new(move |msg| { let loader = vfs_notify::NotifyHandle::spawn(Box::new(move |msg| {
task_sender.send(msg).unwrap() task_sender.send(msg).unwrap()
})); }));
Box::new(loader) Box::new(loader)

View file

@ -20,7 +20,7 @@ use walkdir::WalkDir;
use crate::include::Include; use crate::include::Include;
#[derive(Debug)] #[derive(Debug)]
pub struct LoaderHandle { pub struct NotifyHandle {
// Relative order of fields below is significant. // Relative order of fields below is significant.
sender: crossbeam_channel::Sender<Message>, sender: crossbeam_channel::Sender<Message>,
_thread: jod_thread::JoinHandle, _thread: jod_thread::JoinHandle,
@ -32,12 +32,12 @@ enum Message {
Invalidate(AbsPathBuf), Invalidate(AbsPathBuf),
} }
impl loader::Handle for LoaderHandle { impl loader::Handle for NotifyHandle {
fn spawn(sender: loader::Sender) -> LoaderHandle { fn spawn(sender: loader::Sender) -> NotifyHandle {
let actor = LoaderActor::new(sender); let actor = NotifyActor::new(sender);
let (sender, receiver) = unbounded::<Message>(); let (sender, receiver) = unbounded::<Message>();
let thread = jod_thread::spawn(move || actor.run(receiver)); let thread = jod_thread::spawn(move || actor.run(receiver));
LoaderHandle { sender, _thread: thread } NotifyHandle { sender, _thread: thread }
} }
fn set_config(&mut self, config: loader::Config) { fn set_config(&mut self, config: loader::Config) {
self.sender.send(Message::Config(config)).unwrap() self.sender.send(Message::Config(config)).unwrap()
@ -52,10 +52,10 @@ impl loader::Handle for LoaderHandle {
type NotifyEvent = notify::Result<notify::Event>; type NotifyEvent = notify::Result<notify::Event>;
struct LoaderActor { struct NotifyActor {
sender: loader::Sender,
config: Vec<(AbsPathBuf, Include, bool)>, config: Vec<(AbsPathBuf, Include, bool)>,
watched_paths: FxHashSet<AbsPathBuf>, watched_paths: FxHashSet<AbsPathBuf>,
sender: loader::Sender,
// Drop order of fields bellow is significant, // Drop order of fields bellow is significant,
watcher: Option<RecommendedWatcher>, watcher: Option<RecommendedWatcher>,
watcher_receiver: Receiver<NotifyEvent>, watcher_receiver: Receiver<NotifyEvent>,
@ -67,19 +67,19 @@ enum Event {
NotifyEvent(NotifyEvent), NotifyEvent(NotifyEvent),
} }
impl LoaderActor { impl NotifyActor {
fn new(sender: loader::Sender) -> LoaderActor { fn new(sender: loader::Sender) -> NotifyActor {
let (watcher_sender, watcher_receiver) = unbounded(); let (watcher_sender, watcher_receiver) = unbounded();
let watcher = log_notify_error(Watcher::new_immediate(move |event| { let watcher = log_notify_error(Watcher::new_immediate(move |event| {
watcher_sender.send(event).unwrap() watcher_sender.send(event).unwrap()
})); }));
LoaderActor { NotifyActor {
watcher,
watcher_receiver,
watched_paths: FxHashSet::default(),
sender, sender,
config: Vec::new(), config: Vec::new(),
watched_paths: FxHashSet::default(),
watcher,
watcher_receiver,
} }
} }