From a9146ba44e1b09d89889f6a2c60758da1cfdaab4 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Thu, 28 Oct 2021 18:46:05 +0200 Subject: [PATCH 1/3] fix api and double checkhealt crash --- lua/sniprun.lua | 2 +- lua/sniprun/api.lua | 4 ++-- src/lib.rs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/sniprun.lua b/lua/sniprun.lua index b68e758c..effcdd88 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -322,7 +322,7 @@ function M.health() local terminate_after = M.job_id == nil local path_log_file = os.getenv('HOME').."/.cache/sniprun/sniprun.log" local path_log_file_mac = os.getenv('HOME').."/Library/Caches/sniprun/sniprun.log" - os.remove(path_log_file) + -- os.remove(path_log_file) -- check if the log is recreated M.ping() diff --git a/lua/sniprun/api.lua b/lua/sniprun/api.lua index f5d1e8e3..4a1045e8 100644 --- a/lua/sniprun/api.lua +++ b/lua/sniprun/api.lua @@ -10,7 +10,7 @@ function M.run_range(range_start, range_end, filetype, config) override.filetype = filetype local lconfig = config or sniprun.config_values lconfig["sniprun_root_dir"] = sniprun_path - sniprun.notify('run', range_start, range_end, lconfig, override) + sniprun.notify('run', range_start, range_end, lconfig, "", override) end @@ -20,7 +20,7 @@ function M.run_string(codestring, filetype, config) override.filetype = filetype or "" local lconfig = config or sniprun.config_values lconfig["sniprun_root_dir"] = sniprun_path - sniprun.notify('run', 0, 0, lconfig, override) + sniprun.notify('run', 0, 0, lconfig, "", override) end diff --git a/src/lib.rs b/src/lib.rs index b229ddcf..4d5d874d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -202,7 +202,7 @@ impl EventHandler { /// fill the DataHolder with data from sniprun and Neovim pub fn fill_data(&mut self, values: &[Value]) { - // info!("[FILLDATA_ENTRY] received data from RPC: {:?}", values); + info!("[FILLDATA_ENTRY] received data from RPC: {:?}", values); let config = values[2].as_map().unwrap(); { self.data.interpreter_data = Some(self.interpreter_data.clone()); @@ -210,7 +210,7 @@ impl EventHandler { } info!("values length: {}", values.len()); - let cli_args = values[3].as_str().unwrap(); + let cli_args = values[3].as_str().unwrap_or({info!("cli arguments are not a string");""}); { if !cli_args.is_empty() { self.data.cli_args = cli_args.split(' ').map(|s| s.to_string()).collect(); @@ -366,11 +366,11 @@ impl EventHandler { } pub fn override_data(&mut self, values: Vec) { - if values.len() < 4 { + if values.len() < 5 { info!("[OVERRIDE] No data to override"); return; } - if let Some(override_map) = values[3].as_map() { + if let Some(override_map) = values[4].as_map() { { if let Some(i) = self.index_from_name("filetype", override_map) { if let Some(filetype_str) = override_map[i].1.as_str() { From 1e52e42985eda8d7ed084b4f71b90c6e5c332f08 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Thu, 28 Oct 2021 19:19:05 +0200 Subject: [PATCH 2/3] fix listener registration issue --- API.md | 2 ++ lua/sniprun.lua | 2 +- lua/sniprun/display.lua | 1 - src/display.rs | 14 +++++++++----- src/lib.rs | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/API.md b/API.md index c6280cea..251f48e5 100644 --- a/API.md +++ b/API.md @@ -60,6 +60,8 @@ end sa.register_listener(api_listener) ``` +(You must also enable the 'Api' display option, and in this particular case where things are printed to the command line area, disabling 'Classic' is recommended) + ​ If your function requires to be manually closed (on `SnipClose`), you can register a closer the same way: diff --git a/lua/sniprun.lua b/lua/sniprun.lua index effcdd88..aaa4d905 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -27,7 +27,7 @@ M.config_values = { -- "LongTempFloatingWindow", -- "TempFloatingWindow", -- "Terminal", - -- "Api, + -- "Api", -- "NvimNotify" }, diff --git a/lua/sniprun/display.lua b/lua/sniprun/display.lua index 61b74ee7..8fbcb279 100644 --- a/lua/sniprun/display.lua +++ b/lua/sniprun/display.lua @@ -138,7 +138,6 @@ function M.send_api(message, ok) else d.status = "error" end - local listeners = require('sniprun.api').listeners if type(next(listeners)) == "nil" then diff --git a/src/display.rs b/src/display.rs index f7a3427f..d5d20fa6 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,7 +1,7 @@ use crate::error::SniprunError; use crate::{DataHolder, ReturnMessageType}; use log::info; -use neovim_lib::{Neovim, NeovimApi, NeovimApiAsync}; +use neovim_lib::{Neovim, NeovimApi}; use std::fmt; use std::str::FromStr; use std::sync::{Arc, Mutex}; @@ -97,23 +97,27 @@ pub fn send_api( nvim: &Arc>, data: &DataHolder, ) { - match message { + let res = match message { Ok(result) => { let mut nvim_instance = nvim.lock().unwrap(); - nvim_instance.command_async(&format!( + nvim_instance.command(&format!( "lua require\"sniprun.display\".send_api(\"{}\", true)", no_output_wrap(result, data, &DisplayType::Terminal), )) } Err(result) => { let mut nvim_instance = nvim.lock().unwrap(); - nvim_instance.command_async(&format!( + nvim_instance.command(&format!( "lua require\"sniprun.display\".send_api(\"{}\", false)", no_output_wrap(&result.to_string(), data, &DisplayType::Terminal), )) } }; - info!("!done displyaing notify"); + if res.is_ok() { + info!("done displaying api"); + } else { + info!("failed to display via api"); + } } pub fn display_virtual_text( diff --git a/src/lib.rs b/src/lib.rs index 4d5d874d..81da43a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -202,7 +202,7 @@ impl EventHandler { /// fill the DataHolder with data from sniprun and Neovim pub fn fill_data(&mut self, values: &[Value]) { - info!("[FILLDATA_ENTRY] received data from RPC: {:?}", values); + // info!("[FILLDATA_ENTRY] received data from RPC: {:?}", values); let config = values[2].as_map().unwrap(); { self.data.interpreter_data = Some(self.interpreter_data.clone()); From bcf7637df245696610da083513b86b0b9ddd1d21 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Thu, 28 Oct 2021 19:23:15 +0200 Subject: [PATCH 3/3] version bump --- CHANGELOG.md | 4 ++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c8674c..8383e40f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.0.2 +- fix issue with API functions & callbacks +- fix double checkhealt crash issue + ## v1.0.1 - fix issue when using sniprun with an empty config diff --git a/Cargo.lock b/Cargo.lock index 1dd69fbf..21436ca9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -336,7 +336,7 @@ checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "sniprun" -version = "1.0.0" +version = "1.0.2" dependencies = [ "dirs", "libc", diff --git a/Cargo.toml b/Cargo.toml index 1b569ae3..e641a485 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.0.1" +version = "1.0.2" authors = ["michaelb "] edition = "2018"