|
|
@ -1,8 +1,11 @@
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
|
|
|
use futures::lock::Mutex;
|
|
|
|
use log::trace;
|
|
|
|
use log::trace;
|
|
|
|
use nvim_rs::{Handler, Neovim};
|
|
|
|
use nvim_rs::{Handler, Neovim};
|
|
|
|
use rmpv::Value;
|
|
|
|
use rmpv::Value;
|
|
|
|
use tokio::task;
|
|
|
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use std::thread;
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
#[cfg(windows)]
|
|
|
|
use crate::bridge::ui_commands::{ParallelCommand, UiCommand};
|
|
|
|
use crate::bridge::ui_commands::{ParallelCommand, UiCommand};
|
|
|
@ -14,12 +17,54 @@ use crate::{
|
|
|
|
settings::SETTINGS,
|
|
|
|
settings::SETTINGS,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct NotificationEvent {
|
|
|
|
|
|
|
|
event_name: String,
|
|
|
|
|
|
|
|
arguments: Vec<Value>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct NeovimHandler {}
|
|
|
|
pub struct NeovimHandler {
|
|
|
|
|
|
|
|
sender: Arc<Mutex<Sender<NotificationEvent>>>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl NeovimHandler {
|
|
|
|
impl NeovimHandler {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {}
|
|
|
|
let (sender, receiver): (Sender<NotificationEvent>, Receiver<NotificationEvent>) =
|
|
|
|
|
|
|
|
channel();
|
|
|
|
|
|
|
|
thread::spawn(|| {
|
|
|
|
|
|
|
|
for event in receiver {
|
|
|
|
|
|
|
|
match event.event_name.as_ref() {
|
|
|
|
|
|
|
|
"redraw" => {
|
|
|
|
|
|
|
|
for events in event.arguments {
|
|
|
|
|
|
|
|
let parsed_events = parse_redraw_event(events)
|
|
|
|
|
|
|
|
.unwrap_or_explained_panic("Could not parse event from neovim");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for parsed_event in parsed_events {
|
|
|
|
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
|
|
|
|
.send(EditorCommand::NeovimRedrawEvent(parsed_event));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
"setting_changed" => {
|
|
|
|
|
|
|
|
SETTINGS.handle_changed_notification(event.arguments);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
|
|
|
"neovide.register_right_click" => {
|
|
|
|
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
|
|
|
|
.send(UiCommand::Parallel(ParallelCommand::RegisterRightClick));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
|
|
|
"neovide.unregister_right_click" => {
|
|
|
|
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
|
|
|
|
.send(UiCommand::Parallel(ParallelCommand::UnregisterRightClick));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
sender: Arc::new(Mutex::new(sender)),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -34,30 +79,12 @@ impl Handler for NeovimHandler {
|
|
|
|
_neovim: Neovim<TxWrapper>,
|
|
|
|
_neovim: Neovim<TxWrapper>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
trace!("Neovim notification: {:?}", &event_name);
|
|
|
|
trace!("Neovim notification: {:?}", &event_name);
|
|
|
|
|
|
|
|
let sender = self.sender.lock().await;
|
|
|
|
task::spawn_blocking(move || match event_name.as_ref() {
|
|
|
|
sender
|
|
|
|
"redraw" => {
|
|
|
|
.send(NotificationEvent {
|
|
|
|
for events in arguments {
|
|
|
|
event_name,
|
|
|
|
let parsed_events = parse_redraw_event(events)
|
|
|
|
arguments,
|
|
|
|
.unwrap_or_explained_panic("Could not parse event from neovim");
|
|
|
|
})
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
for parsed_event in parsed_events {
|
|
|
|
|
|
|
|
EVENT_AGGREGATOR.send(EditorCommand::NeovimRedrawEvent(parsed_event));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
"setting_changed" => {
|
|
|
|
|
|
|
|
SETTINGS.handle_changed_notification(arguments);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
|
|
|
"neovide.register_right_click" => {
|
|
|
|
|
|
|
|
EVENT_AGGREGATOR.send(UiCommand::Parallel(ParallelCommand::RegisterRightClick));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
|
|
|
"neovide.unregister_right_click" => {
|
|
|
|
|
|
|
|
EVENT_AGGREGATOR.send(UiCommand::Parallel(ParallelCommand::UnregisterRightClick));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|