|
|
@ -4,13 +4,38 @@ use rmpv::Value;
|
|
|
|
use nvim_rs::{Neovim, Handler, compat::tokio::Compat};
|
|
|
|
use nvim_rs::{Neovim, Handler, compat::tokio::Compat};
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use tokio::process::ChildStdin;
|
|
|
|
use tokio::process::ChildStdin;
|
|
|
|
|
|
|
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::error_handling::ResultPanicExplanation;
|
|
|
|
use crate::error_handling::ResultPanicExplanation;
|
|
|
|
use crate::editor::{EDITOR, Editor};
|
|
|
|
use crate::editor::{EDITOR, Editor};
|
|
|
|
use super::events::parse_neovim_event;
|
|
|
|
use super::events::{RedrawEvent, parse_neovim_event};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct NeovimHandler { }
|
|
|
|
pub struct NeovimHandler {
|
|
|
|
|
|
|
|
sender: UnboundedSender<RedrawEvent>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl NeovimHandler {
|
|
|
|
|
|
|
|
pub fn new() -> NeovimHandler {
|
|
|
|
|
|
|
|
let (sender, mut receiver) = unbounded_channel::<RedrawEvent>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
|
|
|
while let Some(event) = receiver.recv().await {
|
|
|
|
|
|
|
|
let mut editor = EDITOR.lock().unwrap();
|
|
|
|
|
|
|
|
editor.handle_redraw_event(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NeovimHandler {
|
|
|
|
|
|
|
|
sender
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn handle_redraw_event(&self, event: RedrawEvent) {
|
|
|
|
|
|
|
|
self.sender.send(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
#[async_trait]
|
|
|
|
impl Handler for NeovimHandler {
|
|
|
|
impl Handler for NeovimHandler {
|
|
|
@ -20,8 +45,7 @@ impl Handler for NeovimHandler {
|
|
|
|
let parsed_events = parse_neovim_event(event_name, arguments)
|
|
|
|
let parsed_events = parse_neovim_event(event_name, arguments)
|
|
|
|
.unwrap_or_explained_panic("Could not parse event", "Could not parse event from neovim");
|
|
|
|
.unwrap_or_explained_panic("Could not parse event", "Could not parse event from neovim");
|
|
|
|
for event in parsed_events {
|
|
|
|
for event in parsed_events {
|
|
|
|
let mut editor = EDITOR.lock().unwrap();
|
|
|
|
self.handle_redraw_event(event);
|
|
|
|
editor.handle_redraw_event(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|