|
|
|
@ -11,13 +11,16 @@ use nvim_rs::{create::tokio as create, UiAttachOptions};
|
|
|
|
|
use tokio::runtime::Runtime;
|
|
|
|
|
use tokio::process::Command;
|
|
|
|
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
|
|
|
|
use log::{info, error, trace};
|
|
|
|
|
|
|
|
|
|
pub use events::*;
|
|
|
|
|
pub use keybindings::*;
|
|
|
|
|
pub use ui_commands::UiCommand;
|
|
|
|
|
use handler::NeovimHandler;
|
|
|
|
|
use crate::error_handling::ResultPanicExplanation;
|
|
|
|
|
use crate::settings::SETTINGS;
|
|
|
|
|
use crate::INITIAL_DIMENSIONS;
|
|
|
|
|
use handler::NeovimHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
pub static ref BRIDGE: Bridge = Bridge::new();
|
|
|
|
@ -31,8 +34,10 @@ fn set_windows_creation_flags(cmd: &mut Command) {
|
|
|
|
|
fn create_nvim_command() -> Command {
|
|
|
|
|
let mut cmd = Command::new("nvim");
|
|
|
|
|
|
|
|
|
|
let args = SETTINGS.neovim_arguments.swap(None).unwrap();
|
|
|
|
|
|
|
|
|
|
cmd.arg("--embed")
|
|
|
|
|
.args(std::env::args().skip(1))
|
|
|
|
|
.args(args.iter().skip(1))
|
|
|
|
|
.stderr(Stdio::inherit());
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
@ -56,14 +61,15 @@ async fn drain(receiver: &mut UnboundedReceiver<UiCommand>) -> Option<Vec<UiComm
|
|
|
|
|
async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
|
|
|
|
|
let (width, height) = INITIAL_DIMENSIONS;
|
|
|
|
|
let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler::new()).await
|
|
|
|
|
.unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process");
|
|
|
|
|
.unwrap_or_explained_panic("Could not locate or start the neovim process");
|
|
|
|
|
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
info!("Close watcher started");
|
|
|
|
|
match io_handler.await {
|
|
|
|
|
Err(join_error) => eprintln!("Error joining IO loop: '{}'", join_error),
|
|
|
|
|
Ok(Err(error)) => {
|
|
|
|
|
if !error.is_channel_closed() {
|
|
|
|
|
eprintln!("Error: '{}'", error);
|
|
|
|
|
error!("Error: '{}'", error);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Ok(Ok(())) => {}
|
|
|
|
@ -73,24 +79,26 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
|
|
|
|
|
|
|
|
|
|
if let Ok(Value::Integer(correct_version)) = nvim.eval("has(\"nvim-0.4\")").await {
|
|
|
|
|
if correct_version.as_i64() != Some(1) {
|
|
|
|
|
println!("Neovide requires version 0.4 or higher");
|
|
|
|
|
error!("Neovide requires version 0.4 or higher");
|
|
|
|
|
std::process::exit(0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
println!("Neovide requires version 0.4 or higher");
|
|
|
|
|
error!("Neovide requires version 0.4 or higher");
|
|
|
|
|
std::process::exit(0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nvim.set_var("neovide", Value::Boolean(true)).await
|
|
|
|
|
.unwrap_or_explained_panic("Could not communicate.", "Could not communicate with neovim process");
|
|
|
|
|
.unwrap_or_explained_panic("Could not communicate with neovim process");
|
|
|
|
|
let mut options = UiAttachOptions::new();
|
|
|
|
|
options.set_linegrid_external(true);
|
|
|
|
|
options.set_rgb(true);
|
|
|
|
|
nvim.ui_attach(width as i64, height as i64, &options).await
|
|
|
|
|
.unwrap_or_explained_panic("Could not attach.", "Could not attach ui to neovim process");
|
|
|
|
|
.unwrap_or_explained_panic("Could not attach ui to neovim process");
|
|
|
|
|
info!("Neovim process attached");
|
|
|
|
|
|
|
|
|
|
let nvim = Arc::new(nvim);
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
info!("UiCommand processor started");
|
|
|
|
|
loop {
|
|
|
|
|
if let Some(commands) = drain(&mut receiver).await {
|
|
|
|
|
let (resize_list, other_commands): (Vec<UiCommand>, Vec<UiCommand>) = commands
|
|
|
|
@ -103,6 +111,7 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
|
|
|
|
|
|
|
|
|
|
let nvim = nvim.clone();
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
trace!("Executing UiCommand: {:?}", &command);
|
|
|
|
|
command.execute(&nvim).await;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -131,9 +140,9 @@ impl Bridge {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn queue_command(&self, command: UiCommand) {
|
|
|
|
|
trace!("UiCommand queued: {:?}", &command);
|
|
|
|
|
self.sender.send(command)
|
|
|
|
|
.unwrap_or_explained_panic(
|
|
|
|
|
"Could Not Send UI Command",
|
|
|
|
|
"Could not send UI command from the window system to the neovim process.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|