Skip to content

Commit

Permalink
Merge pull request #108 from michaelb/dev
Browse files Browse the repository at this point in the history
fix API
  • Loading branch information
michaelb authored Oct 28, 2021
2 parents 8ec3478 + bcf7637 commit 2fbf384
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
2 changes: 2 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sniprun"
version = "1.0.1"
version = "1.0.2"
authors = ["michaelb <[email protected]>"]
edition = "2018"

Expand Down
4 changes: 2 additions & 2 deletions lua/sniprun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ M.config_values = {
-- "LongTempFloatingWindow",
-- "TempFloatingWindow",
-- "Terminal",
-- "Api,
-- "Api",
-- "NvimNotify"
},

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions lua/sniprun/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand Down
1 change: 0 additions & 1 deletion lua/sniprun/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/display.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -97,23 +97,27 @@ pub fn send_api(
nvim: &Arc<Mutex<Neovim>>,
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(
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -366,11 +366,11 @@ impl EventHandler {
}

pub fn override_data(&mut self, values: Vec<Value>) {
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() {
Expand Down

0 comments on commit 2fbf384

Please sign in to comment.