Merge pull request #37 from KillTheMule/nvimrs

Port to nvim-rs
macos-click-through
Keith Simmons 5 years ago committed by GitHub
commit db223b616f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

194
Cargo.lock generated

@ -229,6 +229,16 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" checksum = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
[[package]]
name = "bytes"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
dependencies = [
"byteorder",
"iovec",
]
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "0.5.3" version = "0.5.3"
@ -776,6 +786,105 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
[[package]]
name = "futures"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866"
[[package]]
name = "futures-executor"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e274736563f686a837a0568b478bdabfeaec2dca794b5649b04e2fe1627c231"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff"
[[package]]
name = "futures-macro"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764"
dependencies = [
"proc-macro-hack",
"proc-macro2 1.0.7",
"quote 1.0.2",
"syn 1.0.13",
]
[[package]]
name = "futures-sink"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16"
[[package]]
name = "futures-task"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9"
[[package]]
name = "futures-util"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76"
dependencies = [
"futures 0.1.29",
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-utils",
"proc-macro-hack",
"proc-macro-nested",
"slab",
"tokio-io",
]
[[package]] [[package]]
name = "gdk" name = "gdk"
version = "0.8.0" version = "0.8.0"
@ -1369,7 +1478,6 @@ dependencies = [
"image", "image",
"lru", "lru",
"msgbox", "msgbox",
"neovim-lib",
"nvim-rs", "nvim-rs",
"rmpv", "rmpv",
"rust-embed", "rust-embed",
@ -1379,16 +1487,6 @@ dependencies = [
"winres", "winres",
] ]
[[package]]
name = "neovim-lib"
version = "0.6.0"
source = "git+https://github.com/daa84/neovim-lib#5291bf754bcfa55dcf6332808f72d09ebd78ce90"
dependencies = [
"log",
"rmpv",
"unix_socket",
]
[[package]] [[package]]
name = "net2" name = "net2"
version = "0.2.33" version = "0.2.33"
@ -1493,16 +1591,16 @@ dependencies = [
[[package]] [[package]]
name = "nvim-rs" name = "nvim-rs"
version = "0.1.0" version = "0.1.1-alpha.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/KillTheMule/nvim-rs?branch=futures#d2012790f7d3876f3bad88185d07a030e4933d37"
checksum = "24f920d183863ab5de29bf953921b286dc5d214620f385e1bfed82a2b0ec6f44"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"futures 0.3.1",
"log", "log",
"pin-project",
"rmp", "rmp",
"rmpv", "rmpv",
"tokio", "tokio",
"unix_socket",
] ]
[[package]] [[package]]
@ -1615,12 +1713,38 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94b90146c7216e4cb534069fb91366de4ea0ea353105ee45ed297e2d1619e469"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44ca92f893f0656d3cba8158dd0f2b99b94de256a4a54e870bd6922fcc6c8355"
dependencies = [
"proc-macro2 1.0.7",
"quote 1.0.2",
"syn 1.0.13",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.1.2" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8822eb8bb72452f038ebf6048efa02c3fe22bf83f76519c9583e47fc194a422" checksum = "e8822eb8bb72452f038ebf6048efa02c3fe22bf83f76519c9583e47fc194a422"
[[package]]
name = "pin-utils"
version = "0.1.0-alpha.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587"
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
version = "0.3.17" version = "0.3.17"
@ -1656,6 +1780,12 @@ dependencies = [
"syn 1.0.13", "syn 1.0.13",
] ]
[[package]]
name = "proc-macro-nested"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "0.4.30" version = "0.4.30"
@ -1863,8 +1993,6 @@ checksum = "ff4792131b8bf59f4b49a546de03c004eb4b54468d4816044af12c3b7942df5b"
dependencies = [ dependencies = [
"num-traits", "num-traits",
"rmp", "rmp",
"serde",
"serde_bytes",
] ]
[[package]] [[package]]
@ -2013,15 +2141,6 @@ version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
[[package]]
name = "serde_bytes"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "325a073952621257820e7a3469f55ba4726d8b28657e7e36653d1c36dc2c84ae"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.44" version = "1.0.44"
@ -2294,7 +2413,7 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffa2fdcfa937b20cb3c822a635ceecd5fc1a27a6a474527e5516aa24b8c8820a" checksum = "ffa2fdcfa937b20cb3c822a635ceecd5fc1a27a6a474527e5516aa24b8c8820a"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.3",
"fnv", "fnv",
"iovec", "iovec",
"lazy_static", "lazy_static",
@ -2310,6 +2429,17 @@ dependencies = [
"winapi 0.3.8", "winapi 0.3.8",
] ]
[[package]]
name = "tokio-io"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926"
dependencies = [
"bytes 0.4.12",
"futures 0.1.29",
"log",
]
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "0.2.3" version = "0.2.3"
@ -2362,16 +2492,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "unix_socket"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564"
dependencies = [
"cfg-if",
"libc",
]
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.8" version = "0.2.8"

@ -13,13 +13,14 @@ lru = "0.4.3"
skulpin = "0.5" skulpin = "0.5"
derive-new = "0.5" derive-new = "0.5"
env_logger = "0.7.1" env_logger = "0.7.1"
neovim-lib = { git = "https://github.com/daa84/neovim-lib", version = "0.6" } #neovim-lib = { git = "https://github.com/daa84/neovim-lib", version = "0.6" }
rmpv = "0.4.2" rmpv = "0.4.2"
msgbox = "0.4.0" msgbox = "0.4.0"
rust-embed = { version = "5.2.0", features = ["debug-embed"] } rust-embed = { version = "5.2.0", features = ["debug-embed"] }
image = "0.22.3" image = "0.22.3"
nvim-rs = "0.1.0" #nvim-rs = "0.1.0"
tokio = { version = "0.2.9", features = [ "blocking" ] } nvim-rs = { git = "https://github.com/KillTheMule/nvim-rs", branch = "futures", features = [ "use_tokio" ] }
tokio = { version = "0.2.9", features = [ "blocking", "process" ] }
async-trait = "0.1.18" async-trait = "0.1.18"
[build-dependencies] [build-dependencies]

@ -8,21 +8,21 @@ mod renderer;
mod error_handling; mod error_handling;
mod ui_commands; mod ui_commands;
#[macro_use] extern crate async_trait;
#[macro_use] extern crate derive_new; #[macro_use] extern crate derive_new;
#[macro_use] extern crate rust_embed; #[macro_use] extern crate rust_embed;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::thread; //use std::thread;
use std::process::Stdio; use std::process::Stdio;
use std::sync::mpsc::{channel, Receiver, Sender}; use std::sync::mpsc::{channel, Receiver};
use async_trait::async_trait; use async_trait::async_trait;
use rmpv::Value; use rmpv::Value;
use nvim_rs::runtime::ChildStdin; use tokio::process::ChildStdin;
use nvim_rs::{create, Neovim, UiAttachOptions, Handler}; use nvim_rs::{create::tokio as create, Neovim, UiAttachOptions, Handler,
compat::tokio::Compat};
use tokio::process::Command; use tokio::process::Command;
use tokio::task::spawn_blocking; use tokio::runtime::Runtime;
use window::ui_loop; use window::ui_loop;
use editor::Editor; use editor::Editor;
@ -54,11 +54,17 @@ fn create_nvim_command() -> Command {
struct NeovimHandler(Arc<Mutex<Editor>>); struct NeovimHandler(Arc<Mutex<Editor>>);
impl Clone for NeovimHandler {
fn clone(&self) -> Self {
NeovimHandler(Arc::clone(&self.0))
}
}
#[async_trait] #[async_trait]
impl Handler for NeovimHandler { impl Handler for NeovimHandler {
type Writer = ChildStdin; type Writer = Compat<ChildStdin>;
async fn handle_request(&self, event_name: String, arguments: Vec<Value>, neovim: Neovim<ChildStdin>) -> Result<Value, Value> { async fn handle_notify(&self, event_name: String, arguments: Vec<Value>, _neovim: Neovim<Compat<ChildStdin>>) {
dbg!(&event_name); dbg!(&event_name);
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");
@ -66,12 +72,10 @@ impl Handler for NeovimHandler {
let mut editor = self.0.lock().unwrap(); let mut editor = self.0.lock().unwrap();
editor.handle_redraw_event(event); editor.handle_redraw_event(event);
} }
Ok(Value::Nil)
} }
} }
#[tokio::main] async fn start_nvim(editor: Arc<Mutex<Editor>>, receiver: Receiver<UiCommand>) {
async fn start_nvim(editor: Arc<Mutex<Editor>>) -> Sender<UiCommand> {
let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler(editor.clone())).await let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler(editor.clone())).await
.unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process"); .unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process");
@ -87,23 +91,31 @@ async fn start_nvim(editor: Arc<Mutex<Editor>>) -> Sender<UiCommand> {
let mut options = UiAttachOptions::new(); let mut options = UiAttachOptions::new();
options.set_linegrid_external(true); options.set_linegrid_external(true);
options.set_rgb(true); options.set_rgb(true);
nvim.set_var("neovide", Value::Boolean(true)).await; nvim.set_var("neovide", Value::Boolean(true)).await
.unwrap_or_explained_panic("Could not communicate.", "Could not communicate with neovim process");
nvim.ui_attach(INITIAL_WIDTH as i64, INITIAL_HEIGHT as i64, &options).await nvim.ui_attach(INITIAL_WIDTH as i64, INITIAL_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.", "Could not attach ui to neovim process");
let (mut sender, receiver) = channel::<UiCommand>(); loop {
tokio::spawn(async move { let r = receiver.recv();
while let Ok(ui_command) = spawn_blocking(|| receiver.recv()).await.unwrap() {
dbg!(&ui_command);
ui_command.execute(&nvim).await;
}
});
sender if let Ok(ui_command) = r {
dbg!(&ui_command);
ui_command.execute(&nvim).await;
} else {
return
}
}
} }
fn main() { fn main() {
let rt = Runtime::new().unwrap();
let editor = Arc::new(Mutex::new(Editor::new(INITIAL_WIDTH, INITIAL_HEIGHT))); let editor = Arc::new(Mutex::new(Editor::new(INITIAL_WIDTH, INITIAL_HEIGHT)));
let sender = start_nvim(editor.clone()); let (sender, receiver) = channel::<UiCommand>();
let editor_clone = editor.clone();
rt.spawn_blocking(async move {
start_nvim(editor_clone, receiver).await;
});
ui_loop(editor, sender, (INITIAL_WIDTH, INITIAL_HEIGHT)); ui_loop(editor, sender, (INITIAL_WIDTH, INITIAL_HEIGHT));
} }

@ -1,5 +1,6 @@
use nvim_rs::Neovim; use nvim_rs::Neovim;
use nvim_rs::runtime::ChildStdin; use nvim_rs::compat::tokio::Compat;
use tokio::process::ChildStdin;
#[derive(Debug)] #[derive(Debug)]
pub enum UiCommand { pub enum UiCommand {
@ -11,7 +12,7 @@ pub enum UiCommand {
} }
impl UiCommand { impl UiCommand {
pub async fn execute(&self, nvim: &Neovim<ChildStdin>) { pub async fn execute(&self, nvim: &Neovim<Compat<ChildStdin>>) {
match self { match self {
UiCommand::Resize { width, height } => UiCommand::Resize { width, height } =>
nvim.ui_try_resize(*width.max(&10), *height.max(&3)).await nvim.ui_try_resize(*width.max(&10), *height.max(&3)).await

Loading…
Cancel
Save