Moved to new version of neovim-lib, that fixes some issues

This commit is contained in:
daa 2017-04-01 17:48:11 +03:00
parent e717c92f33
commit 41ac04f5c2
5 changed files with 98 additions and 48 deletions

36
Cargo.lock generated
View File

@ -10,7 +10,7 @@ dependencies = [
"glib-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"gtk 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gtk-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"neovim-lib 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"neovim-lib 0.2.1 (git+https://github.com/daa84/neovim-lib)",
"pango 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pangocairo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
@ -71,6 +71,11 @@ dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cfg-if"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gdk"
version = "0.5.2"
@ -235,11 +240,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "neovim-lib"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.2.1"
source = "git+https://github.com/daa84/neovim-lib#c0d5edd74cd43264019cd42ec33f61bd8c9f4d39"
dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rmp 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rmpv 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -349,11 +356,29 @@ dependencies = [
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rmpv"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"rmp 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "siphasher"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unix_socket"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.8"
@ -367,6 +392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum c_vec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0059f5a658f62a4bd3937a7addc52ccfda144b75cce7a92b187e528629cdc507"
"checksum cairo-rs 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "efce5d4fc3d3369f0b6d249ece7807b8f05c3e08a149bdfe85f99ad5740b7919"
"checksum cairo-sys-rs 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee7f9df649493d57a37ae84f57e0d5848714802276151ad742c4ff75ef8e8cd8"
"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
"checksum gdk 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "763c9a7cc10e18660c80f04d49a12da55743ef3363af4718320b119b60aaa49e"
"checksum gdk-pixbuf 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "792bacc7473ab6da4aaaba55f0b8b359f70ed1dee297af3decfb44c44f6e1fb8"
"checksum gdk-pixbuf-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "878cb15fd8a6d8bc7e429b9648630dc91beefda8e1cb0d3a97172dbe9fdcfeff"
@ -380,7 +406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum gtk-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7445eb281879ac472e5f5816058d53eaceff2bab7b78a095a4044f4c0cccc754"
"checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum neovim-lib 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eb0ce042e5a820f9b832fab374f9cdebf99ed805cee89cf70a1303ceefa5eb2"
"checksum neovim-lib 0.2.1 (git+https://github.com/daa84/neovim-lib)" = "<none>"
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum pango 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "21d777a87f13107b96be840dec1c34e0fe1a7b5630dd90c74b4eec923c439187"
"checksum pango-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f29f64bc081e778cb897e3ef20aae178150d165d0eb77065b9e20437407c5546"
@ -393,5 +419,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum rmp 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "41db0e2867a9baf8ae20c8b5f7167eb287c7e9532d7e6f09c8b4a54001a678b8"
"checksum rmpv 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "45368daa6c60116376d8813ec6a2556df640229709becb8f80df1651f882e7af"
"checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84"
"checksum unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"

View File

@ -12,12 +12,12 @@ glib = "0.1"
glib-sys = "0.3"
gdk = "0.5"
gdk-sys = "0.3"
neovim-lib = "0.2"
#neovim-lib = "0.2"
phf = "0.7"
gio = "0.1"
#[dependencies.neovim-lib]
#git = "https://github.com/daa84/neovim-lib"
[dependencies.neovim-lib]
git = "https://github.com/daa84/neovim-lib"
[build-dependencies]
phf_codegen = "0.7"

View File

@ -1,4 +1,4 @@
use neovim_lib::{Neovim, NeovimApi, Session, Value, Integer, UiAttachOptions, CallError};
use neovim_lib::{Handler, Neovim, NeovimApi, Session, Value, UiAttachOptions, CallError};
use std::io::{Result, Error, ErrorKind};
use std::result;
use ui_model::{UiModel, ModelRect};
@ -43,30 +43,27 @@ pub trait GuiApi {
}
macro_rules! try_str {
($exp:expr) => (match $exp {
Value::String(ref val) => val,
($exp:expr) => (match $exp.as_str() {
Some(val) => val,
_ => return Err("Can't convert argument to string".to_owned())
})
}
macro_rules! try_int {
($expr:expr) => (match $expr {
Value::Integer(Integer::U64(val)) => val as i64,
Value::Integer(Integer::I64(val)) => val,
($expr:expr) => (match $expr.as_i64() {
Some(val) => val,
_ => return Err("Can't convert argument to int".to_owned())
})
}
macro_rules! try_uint {
($exp:expr) => (match $exp {
Value::Integer(Integer::U64(val)) => val,
($exp:expr) => (match $exp.as_u64() {
Some(val) => val,
_ => return Err("Can't convert argument to u64".to_owned())
})
}
pub fn initialize(ui: &mut Shell,
nvim_bin_path: Option<&String>)
-> Result<()> {
pub fn initialize(ui: &mut Shell, nvim_bin_path: Option<&String>) -> Result<()> {
let session = if let Some(path) = nvim_bin_path {
Session::new_child_path(path)?
} else {
@ -79,7 +76,7 @@ pub fn initialize(ui: &mut Shell,
let mut nvim = ui.nvim();
nvim.session.start_event_loop_cb(move |m, p| nvim_cb(m, p));
nvim.session.start_event_loop_handler(NvimHandler::new());
nvim.ui_attach(80, 24, UiAttachOptions::new()).map_err(|e| Error::new(ErrorKind::Other, e))?;
nvim.command("runtime! ginit.vim").map_err(|e| Error::new(ErrorKind::Other, e))?;
@ -92,6 +89,20 @@ pub fn open_file(nvim: &mut NeovimApi, file: Option<&String>) {
}
}
pub struct NvimHandler {}
impl NvimHandler {
pub fn new() -> NvimHandler {
NvimHandler {}
}
}
impl Handler for NvimHandler {
fn handle_notify(&mut self, name: &str, args: &Vec<Value>) {
nvim_cb(name, args.clone());
}
}
fn nvim_cb(method: &str, params: Vec<Value>) {
match method {
"redraw" => {
@ -99,8 +110,8 @@ fn nvim_cb(method: &str, params: Vec<Value>) {
let mut repaint_mode = RepaintMode::Nothing;
for ev in &params {
if let &Value::Array(ref ev_args) = ev {
if let Value::String(ref ev_name) = ev_args[0] {
if let Some(ev_args) = ev.as_array() {
if let Some(ev_name) = ev_args[0].as_str() {
for ref local_args in ev_args.iter().skip(1) {
let args = match *local_args {
&Value::Array(ref ar) => ar.clone(),
@ -123,7 +134,7 @@ fn nvim_cb(method: &str, params: Vec<Value>) {
}
"Gui" => {
if params.len() > 0 {
if let Value::String(ev_name) = params[0].clone() {
if let Some(ev_name) = params[0].as_str().map(String::from) {
let args = params.iter().skip(1).cloned().collect();
safe_call(move |ui| {
call_gui_event(ui, &ev_name, &args)?;
@ -183,7 +194,7 @@ fn call(ui: &mut Shell, method: &str, args: &Vec<Value>) -> result::Result<Repai
_ => {
println!("Event {}({:?})", method, args);
RepaintMode::Nothing
},
}
})
}
@ -191,9 +202,11 @@ fn safe_call<F>(cb: F)
where F: Fn(&mut Shell) -> result::Result<(), String> + 'static + Send
{
glib::idle_add(move || {
SHELL!(shell = { if let Err(msg) = cb(&mut shell) {
println!("Error call function: {}", msg);
}});
SHELL!(shell = {
if let Err(msg) = cb(&mut shell) {
println!("Error call function: {}", msg);
}
});
glib::Continue(false)
});
}
@ -250,7 +263,7 @@ mod tests {
assert_eq!(1, rect.left);
assert_eq!(1, rect.right);
}
_ => panic!("mode is worng")
_ => panic!("mode is worng"),
}
}
}

View File

@ -11,7 +11,7 @@ use glib;
use gtk::prelude::*;
use gtk::DrawingArea;
use neovim_lib::{Neovim, NeovimApi, Value, Integer};
use neovim_lib::{Neovim, NeovimApi, Value};
use settings;
use ui_model::{UiModel, Cell, Attrs, Color, ModelRect, COLOR_BLACK, COLOR_WHITE, COLOR_RED};
@ -298,8 +298,8 @@ fn draw(shell: &Shell, ctx: &cairo::Context) {
let line_height = shell.line_height.unwrap();
let char_width = shell.char_width.unwrap();
let clip = ctx.clip_extents();
let mut model_clip = ModelRect::from_area(line_height, char_width,
clip.0, clip.1, clip.2, clip.3);
let mut model_clip =
ModelRect::from_area(line_height, char_width, clip.0, clip.1, clip.2, clip.3);
shell.model.limit_to_model(&mut model_clip);
let line_x = model_clip.left as f64 * char_width;
@ -356,7 +356,13 @@ fn draw(shell: &Shell, ctx: &cairo::Context) {
let (bg, fg) = shell.colors(cell);
if row == line_idx && col == col_idx {
shell.cursor.draw(ctx, shell, char_width, line_height, line_y, double_width, bg);
shell.cursor.draw(ctx,
shell,
char_width,
line_height,
line_y,
double_width,
bg);
ctx.move_to(current_point.0, current_point.1);
}
@ -536,8 +542,7 @@ impl RedrawEvents for Shell {
&RepaintMode::Area(ref rect) => {
match (&self.line_height, &self.char_width) {
(&Some(line_height), &Some(char_width)) => {
let (x, y, width, height) =
rect.to_area(line_height, char_width);
let (x, y, width, height) = rect.to_area(line_height, char_width);
self.drawing_area.queue_draw_area(x, y, width, height);
}
_ => self.drawing_area.queue_draw(),
@ -560,20 +565,20 @@ impl RedrawEvents for Shell {
let mut model_attrs = Attrs::new();
for &(ref key_val, ref val) in attrs {
if let &Value::String(ref key) = key_val {
match key.as_ref() {
if let Some(key) = key_val.as_str() {
match key {
"foreground" => {
if let &Value::Integer(Integer::U64(fg)) = val {
if let Some(fg) = val.as_u64() {
model_attrs.foreground = Some(split_color(fg));
}
}
"background" => {
if let &Value::Integer(Integer::U64(bg)) = val {
if let Some(bg) = val.as_u64() {
model_attrs.background = Some(split_color(bg));
}
}
"special" => {
if let &Value::Integer(Integer::U64(bg)) = val {
if let Some(bg) = val.as_u64() {
model_attrs.special = Some(split_color(bg));
}
}

View File

@ -12,7 +12,7 @@ pub fn can_close_window(ui: &Ui) -> bool {
} else {
true
}
},
}
Err(ref err) => {
println!("Error getting info from nvim: {}", err);
true
@ -22,11 +22,11 @@ pub fn can_close_window(ui: &Ui) -> bool {
fn show_not_saved_dlg(ui: &Ui, changed_bufs: &Vec<String>) -> bool {
let flags = gtk::DIALOG_MODAL | gtk::DIALOG_DESTROY_WITH_PARENT;
let dlg = Dialog::new_with_buttons(Some("Question"), ui.window.as_ref(), flags, &[
("_OK", gtk_sys::GTK_RESPONSE_ACCEPT as i32),
("_Cancel",
gtk_sys::GTK_RESPONSE_REJECT as i32)
]);
let dlg = Dialog::new_with_buttons(Some("Question"),
ui.window.as_ref(),
flags,
&[("_OK", gtk_sys::GTK_RESPONSE_ACCEPT as i32),
("_Cancel", gtk_sys::GTK_RESPONSE_REJECT as i32)]);
dlg.run();
@ -36,23 +36,27 @@ fn show_not_saved_dlg(ui: &Ui, changed_bufs: &Vec<String>) -> bool {
fn get_changed_buffers() -> Result<Vec<String>, CallError> {
SHELL!(shell = {
let mut nvim = shell.nvim();
let buffers = nvim.get_buffers()?;
let buffers = nvim.get_buffers().unwrap();
Ok(buffers.iter()
.map(|buf| {
(match buf.get_option(&mut nvim, "modified") {
Ok(Value::Boolean(val)) => val,
_ => {
Ok(_) => {
println!("Value must be boolean");
false
},
}
Err(ref err) => {
println!("Something going wrong while getting buffer option: {}", err);
false
}
},
match buf.get_name(&mut nvim) {
Ok(name) => name,
Err(ref err) => {
println!("Something going wrong while getting buffer name: {}", err);
"<Error>".to_owned()
},
}
})
})
.filter(|e| e.0)