fix tests and warnings

macos-click-through
Keith Simmons 4 years ago
parent ff1954f9a9
commit a490e5992a

@ -1,32 +1,33 @@
use std::sync::Arc; use std::sync::Arc;
use std::sync::mpsc::Sender;
use async_trait::async_trait; use async_trait::async_trait;
use crossfire::mpsc::TxUnbounded; use crossfire::mpsc::TxUnbounded;
use log::trace; use log::trace;
use nvim_rs::{compat::tokio::Compat, Handler, Neovim}; use nvim_rs::{compat::tokio::Compat, Handler, Neovim};
use parking_lot::Mutex;
use rmpv::Value; use rmpv::Value;
use tokio::sync::mpsc::UnboundedSender;
use tokio::process::ChildStdin; use tokio::process::ChildStdin;
use tokio::task; use tokio::task;
use parking_lot::Mutex;
use super::events::{parse_redraw_event, RedrawEvent}; use super::events::{parse_redraw_event, RedrawEvent};
use super::ui_commands::UiCommand; use super::ui_commands::UiCommand;
use crate::settings::SETTINGS;
use crate::error_handling::ResultPanicExplanation; use crate::error_handling::ResultPanicExplanation;
use crate::settings::SETTINGS;
#[derive(Clone)] #[derive(Clone)]
pub struct NeovimHandler { pub struct NeovimHandler {
ui_command_sender: Arc<Mutex<TxUnbounded<UiCommand>>>, ui_command_sender: Arc<Mutex<TxUnbounded<UiCommand>>>,
redraw_event_sender: Arc<Mutex<TxUnbounded<RedrawEvent>>> redraw_event_sender: Arc<Mutex<TxUnbounded<RedrawEvent>>>,
} }
impl NeovimHandler { impl NeovimHandler {
pub fn new(ui_command_sender: TxUnbounded<UiCommand>, redraw_event_sender: TxUnbounded<RedrawEvent>) -> NeovimHandler { pub fn new(
ui_command_sender: TxUnbounded<UiCommand>,
redraw_event_sender: TxUnbounded<RedrawEvent>,
) -> NeovimHandler {
NeovimHandler { NeovimHandler {
ui_command_sender: Arc::new(Mutex::new(ui_command_sender)), ui_command_sender: Arc::new(Mutex::new(ui_command_sender)),
redraw_event_sender: Arc::new(Mutex::new(redraw_event_sender)) redraw_event_sender: Arc::new(Mutex::new(redraw_event_sender)),
} }
} }
} }

@ -2,27 +2,21 @@
pub mod layouts; pub mod layouts;
mod events; mod events;
mod ui_commands;
mod handler; mod handler;
mod ui_commands;
use std::env; use std::env;
use std::path::Path; use std::path::Path;
use std::process::Stdio; use std::process::Stdio;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{Receiver, Sender};
use std::sync::Arc; use std::sync::Arc;
use std::thread;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
use crossfire::mpsc::{TxUnbounded, RxUnbounded}; use crossfire::mpsc::{RxUnbounded, TxUnbounded};
use log::{error, info, warn}; use log::{error, info, warn};
use nvim_rs::{create::tokio as create, UiAttachOptions}; use nvim_rs::{create::tokio as create, UiAttachOptions};
use rmpv::Value; use rmpv::Value;
use tokio::process::Command; use tokio::process::Command;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use crate::error_handling::ResultPanicExplanation; use crate::error_handling::ResultPanicExplanation;
use crate::settings::*; use crate::settings::*;
@ -122,10 +116,9 @@ async fn start_neovim_runtime(
) { ) {
let (width, height) = window_geometry_or_default(); let (width, height) = window_geometry_or_default();
let handler = NeovimHandler::new(ui_command_sender.clone(), redraw_event_sender.clone()); let handler = NeovimHandler::new(ui_command_sender.clone(), redraw_event_sender.clone());
let (mut nvim, io_handler, _) = let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), handler)
create::new_child_cmd(&mut create_nvim_command(), handler) .await
.await .unwrap_or_explained_panic("Could not locate or start neovim process");
.unwrap_or_explained_panic("Could not locate or start neovim process");
if nvim.get_api_info().await.is_err() { if nvim.get_api_info().await.is_err() {
error!("Cannot get neovim api info, either neovide is launched with an unknown command line option or neovim version not supported!"); error!("Cannot get neovim api info, either neovide is launched with an unknown command line option or neovim version not supported!");
@ -231,7 +224,9 @@ async fn start_neovim_runtime(
let mut options = UiAttachOptions::new(); let mut options = UiAttachOptions::new();
options.set_linegrid_external(true); options.set_linegrid_external(true);
options.set_multigrid_external(true); if env::args().any(|arg| arg == "--multiGrid") || env::var("NeovideMultiGrid").is_ok() {
options.set_multigrid_external(true);
}
options.set_rgb(true); options.set_rgb(true);
nvim.ui_attach(width as i64, height as i64, &options) nvim.ui_attach(width as i64, height as i64, &options)
.await .await
@ -276,11 +271,14 @@ pub fn start_bridge(
ui_command_sender: TxUnbounded<UiCommand>, ui_command_sender: TxUnbounded<UiCommand>,
ui_command_receiver: RxUnbounded<UiCommand>, ui_command_receiver: RxUnbounded<UiCommand>,
redraw_event_sender: TxUnbounded<RedrawEvent>, redraw_event_sender: TxUnbounded<RedrawEvent>,
running: Arc<AtomicBool> running: Arc<AtomicBool>,
) -> Bridge { ) -> Bridge {
let runtime = Runtime::new().unwrap(); let runtime = Runtime::new().unwrap();
runtime.spawn(start_neovim_runtime(ui_command_sender, ui_command_receiver, redraw_event_sender, running)); runtime.spawn(start_neovim_runtime(
Bridge { ui_command_sender,
_runtime: runtime ui_command_receiver,
} redraw_event_sender,
running,
));
Bridge { _runtime: runtime }
} }

@ -6,7 +6,7 @@ mod window;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::Sender;
use std::sync::Arc; use std::sync::Arc;
use std::thread; use std::thread;

@ -18,9 +18,9 @@ extern crate rust_embed;
extern crate lazy_static; extern crate lazy_static;
use std::process; use std::process;
use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::sync::Arc;
use crossfire::mpsc::unbounded_future; use crossfire::mpsc::unbounded_future;
@ -138,7 +138,7 @@ fn main() {
let (window_command_sender, window_command_receiver) = channel(); let (window_command_sender, window_command_receiver) = channel();
// We need to keep the bridge reference around to prevent the tokio runtime from getting freed // We need to keep the bridge reference around to prevent the tokio runtime from getting freed
let bridge = start_bridge( let _bridge = start_bridge(
ui_command_sender.clone(), ui_command_sender.clone(),
ui_command_receiver, ui_command_receiver,
redraw_event_sender, redraw_event_sender,

@ -69,7 +69,7 @@ impl Settings {
log_to_file = true; log_to_file = true;
false false
} else { } else {
!(arg.starts_with("--geometry=") || arg == "--wsl") !(arg.starts_with("--geometry=") || arg == "--wsl" || arg == "--multiGrid")
} }
}) })
.collect::<Vec<String>>(); .collect::<Vec<String>>();
@ -194,12 +194,30 @@ impl Settings {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use neovim_lib::{Neovim, NeovimApi, Session, UiAttachOptions}; use async_trait::async_trait;
use nvim_rs::create::tokio as create;
use nvim_rs::{compat::tokio::Compat, Handler, Neovim};
use tokio;
use super::*; use super::*;
use crate::bridge::create_nvim_command; use crate::bridge::create_nvim_command;
#[derive(Clone)]
pub struct NeovimHandler();
#[async_trait]
impl Handler for NeovimHandler {
type Writer = Compat<ChildStdin>;
async fn handle_notify(
&self,
_event_name: String,
_arguments: Vec<Value>,
_neovim: Neovim<Compat<ChildStdin>>,
) {
}
}
#[test] #[test]
fn test_set_setting_handlers() { fn test_set_setting_handlers() {
let settings = Settings::new(); let settings = Settings::new();
@ -271,8 +289,8 @@ mod tests {
assert_eq!(v2, r2); assert_eq!(v2, r2);
} }
#[test] #[tokio::test]
fn test_read_initial_values() { async fn test_read_initial_values() {
let settings = Settings::new(); let settings = Settings::new();
let v1: String = "foo".to_string(); let v1: String = "foo".to_string();
@ -281,12 +299,10 @@ mod tests {
let v4: String = format!("neovide_{}", v1); let v4: String = format!("neovide_{}", v1);
let v5: String = format!("neovide_{}", v2); let v5: String = format!("neovide_{}", v2);
let mut session = Session::new_child_cmd(&mut create_nvim_command()) let (nvim, _, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler())
.unwrap_or_explained_panic("Could not locate or start neovim process"); .await
session.start_event_loop_channel(); .unwrap_or_explained_panic("Could not locate or start the neovim process");
let mut nvim = Neovim::new(session); nvim.set_var(&v4, Value::from(v2.clone())).await.ok();
nvim.set_var(&v4, Value::from(v2.clone())).unwrap();
fn noop_update(_v: Value) {} fn noop_update(_v: Value) {}
@ -310,10 +326,10 @@ mod tests {
settings.readers.force_unlock_write(); settings.readers.force_unlock_write();
} }
settings.read_initial_values(&mut nvim); settings.read_initial_values(&nvim).await;
let rt1 = nvim.get_var(&v4).unwrap(); let rt1 = nvim.get_var(&v4).await.unwrap();
let rt2 = nvim.get_var(&v5).unwrap(); let rt2 = nvim.get_var(&v5).await.unwrap();
let r1 = rt1.as_str().unwrap(); let r1 = rt1.as_str().unwrap();
let r2 = rt2.as_str().unwrap(); let r2 = rt2.as_str().unwrap();

@ -3,7 +3,7 @@ mod settings;
mod window_wrapper; mod window_wrapper;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::Receiver;
use std::sync::Arc; use std::sync::Arc;
use crossfire::mpsc::TxUnbounded; use crossfire::mpsc::TxUnbounded;

Loading…
Cancel
Save