From 0d58135d037ce09cfa92f5f829d979a0fa56c876 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 29 Jun 2024 18:27:39 +0200 Subject: [PATCH 01/12] bump dev cargo.toml version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5019354..6831ada 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.3.14" +version = "1.3.15-beta" authors = ["michaelb "] rust-version = "1.65" edition = "2018" From 3d1f37a718d247048ab7124f8849166728a99671 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 20 Jul 2024 12:35:45 +0200 Subject: [PATCH 02/12] add plantuml --- CHANGELOG.md | 3 + Cargo.lock | 2 +- doc/sources/interpreters/Plantuml_original.md | 22 ++ lua/sniprun/display.lua | 4 +- ressources/install_all_compilers_ci.sh | 4 + src/interpreters/Plantuml_original.rs | 258 ++++++++++++++++++ 6 files changed, 291 insertions(+), 2 deletions(-) create mode 100644 doc/sources/interpreters/Plantuml_original.md create mode 100644 src/interpreters/Plantuml_original.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index a4b5870..33fc4bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.3.15 +- Add PlantUML support (ascii output) + ## v1.3.14 - Improve Lua\_nvim's handling of 'local' requires in REPL mode diff --git a/Cargo.lock b/Cargo.lock index de3f02d..0064595 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -795,7 +795,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "sniprun" -version = "1.3.14-beta" +version = "1.3.15-beta" dependencies = [ "close_fds", "dirs", diff --git a/doc/sources/interpreters/Plantuml_original.md b/doc/sources/interpreters/Plantuml_original.md new file mode 100644 index 0000000..6fc39e9 --- /dev/null +++ b/doc/sources/interpreters/Plantuml_original.md @@ -0,0 +1,22 @@ +## PlantUML original + +This interpreter relies on `plantuml`, which needs to be available on the $PATH + + + +This interpreter supports the following options: + +```lua +require'sniprun'.setup({ + interpreter_options = { + Plantuml_original = { + output_mode = "-tutxt", --# one of the options allowed by plantuml + compiler = "/home/user/my_custom_plantuml_install/plantuml" + } + } + } +}) +``` +You can add options to the 'compiler' key, but do not set "-pipe" (or it'll break output), and "-failfast2", "-nbthread auto" are already set. + + diff --git a/lua/sniprun/display.lua b/lua/sniprun/display.lua index aca3b5b..c5649f8 100644 --- a/lua/sniprun/display.lua +++ b/lua/sniprun/display.lua @@ -29,7 +29,9 @@ function M.fw_open(row, column, message, ok, temp) vim.api.nvim_buf_set_lines(bufnr,h,h+1,false,{line}) vim.api.nvim_buf_add_highlight(bufnr, namespace_id, hl, h,0,-1) -- highlight lines in floating window end - M.fw_handle = vim.api.nvim_open_win(bufnr, false, {relative='win', width=w+1, height=h, bufpos=bp, focusable=false, style='minimal',border=M.borders}) + if h ~= 0 then + M.fw_handle = vim.api.nvim_open_win(bufnr, false, {relative='win', width=w+1, height=h, bufpos=bp, focusable=false, style='minimal',border=M.borders}) + end end function M.term_set_window_handle() diff --git a/ressources/install_all_compilers_ci.sh b/ressources/install_all_compilers_ci.sh index a41a95b..51216ac 100755 --- a/ressources/install_all_compilers_ci.sh +++ b/ressources/install_all_compilers_ci.sh @@ -74,6 +74,10 @@ then sudo apt-get install clojure fi +if ! command -v plantuml &> /dev/null +then + sudo apt-get install plantuml +fi if ! command -v go &> /dev/null diff --git a/src/interpreters/Plantuml_original.rs b/src/interpreters/Plantuml_original.rs new file mode 100644 index 0000000..861910f --- /dev/null +++ b/src/interpreters/Plantuml_original.rs @@ -0,0 +1,258 @@ +// Be sure to read the CONTRIBUTING.md file :-) + +#[derive(Clone)] +#[allow(non_camel_case_types)] +// For example, Rust_original is a good name for the first rust interpreter +pub struct Plantuml_original { + support_level: SupportLevel, + data: DataHolder, + code: String, + + language_work_dir: String, + main_file_path: String, + output_mode: String, +} + +//necessary boilerplate, you don't need to implement that if you want a Bloc support level +//interpreter (the easiest && most common) +impl ReplLikeInterpreter for Plantuml_original {} + +impl Interpreter for Plantuml_original { + fn new_with_level(data: DataHolder, support_level: SupportLevel) -> Box { + //create a subfolder in the cache folder + let lwd = data.work_dir.clone() + "/plantuml_original"; + let mut builder = DirBuilder::new(); + builder.recursive(true); + builder + .create(&lwd) + .expect("Could not create directory for example"); + + let mfp = lwd.clone() + "/main.uml"; + Box::new(Plantuml_original { + data, + support_level, + code: String::new(), + language_work_dir: lwd, + main_file_path: mfp, + output_mode: String::new(), + }) + } + + fn get_supported_languages() -> Vec { + vec![ + String::from("PlantUML"), // in 1st position of vector, used for info only + //':set ft?' in nvim to get the filetype of opened file + String::from("puml"), + String::from("uml"), + String::from("pu"), + String::from("iuml"), + String::from("plantuml"), + ] + } + + fn get_name() -> String { + // get your interpreter name + String::from("Plantuml_original") + } + + fn get_current_level(&self) -> SupportLevel { + self.support_level + } + fn set_current_level(&mut self, level: SupportLevel) { + self.support_level = level; + } + + fn get_data(&self) -> DataHolder { + self.data.clone() + } + + fn default_for_filetype() -> bool { + true + } + + fn behave_repl_like_default() -> bool { + false + } + + fn has_repl_capability() -> bool { + false + } + + fn get_max_support_level() -> SupportLevel { + //define the max level support of the interpreter (see readme for definitions) + SupportLevel::Bloc + } + + fn fetch_code(&mut self) -> Result<(), SniprunError> { + if let Some(nvim_instance) = self.data.nvim_instance.clone() { + let mut real_nvim_instance = nvim_instance.lock().unwrap(); + //note: you probably don't have to modify, or even understand this function + + //check if we not on boundary of block, if so replace self.code with whole bloc + let line_n = self.data.range[0]; + if self + .data + .current_line + .trim_start() + .to_lowercase() + .starts_with("@startuml") + { + let end_line = real_nvim_instance + .get_current_buf() + .unwrap() + .line_count(&mut real_nvim_instance) + .unwrap(); + let capped_end_line = std::cmp::min(line_n + 400, end_line); // in case there is a very long file, don't search for nothing up to line 500k + let it = line_n + 1..capped_end_line + 1; + + let mut code_bloc = vec![]; + for i in it { + let line_i = real_nvim_instance + .get_current_buf() + .unwrap() + .get_lines(&mut real_nvim_instance, i - 1, i, false) + .unwrap() + .join(""); + if line_i.trim_start().to_lowercase().starts_with("@enduml") { + //found end of bloc + info!("found end of bloc at line {}", i); + self.data.current_bloc = code_bloc.join("\n"); + } else { + info!("adding line {} to current bloc", i); + code_bloc.push(line_i.to_string()); + } + } + } + } + // + //add code from data to self.code + if !self + .data + .current_bloc + .replace(&[' ', '\t', '\n', '\r'][..], "") + .is_empty() + && self.support_level >= SupportLevel::Bloc + { + // if bloc is not pseudo empty and has Bloc current support level, + // add fetched code to self + self.code = self.data.current_bloc.clone(); + + // if there is only data on current line / or Line is the max support level + } else if !self.data.current_line.replace(" ", "").is_empty() + && self.support_level >= SupportLevel::Line + { + self.code = self.data.current_line.clone(); + } else { + // no code was retrieved + self.code = String::from(""); + } + + // now self.code contains the line or bloc of code wanted :-) + Ok(()) + } + + fn add_boilerplate(&mut self) -> Result<(), SniprunError> { + if !self.code.contains("@startuml") { + self.code = String::from("@startuml\n") + &self.code; + } + if !self.code.contains("@enduml") { + self.code = self.code.clone() + "\n@enduml\n"; + } + Ok(()) + } + + fn build(&mut self) -> Result<(), SniprunError> { + let mut _file = File::create(&self.main_file_path) + .expect("Failed to create file for plantuml_original"); + // IO errors can be ignored, or handled into a proper SniprunError + // If you panic, it should not be too dangerous for anyone + write(&self.main_file_path, &self.code) + .expect("Unable to write to file for plantuml_original"); + + self.output_mode = String::from("-tutxt"); + + if let Some(config_value) = + Plantuml_original::get_interpreter_option(&self.data, "output_mode") + { + if let Some(config_value_valid_string) = config_value.as_str() { + self.output_mode = config_value_valid_string.to_string(); + } + } + let allowed_output_modes = [ + "-tutxt", + "-thtml", + "-tsvg", + "-tpng", + "-tpdf", + "-teps", + "-teps:text", + "-tlatex", + "-tlatex:nopreamble", + "-ttxt", + ]; + if !allowed_output_modes.contains(&self.output_mode.as_str()) { + return Err(SniprunError::CustomError(format!( + "invalid output mode {}, allowed modes are {:?}", + self.output_mode, allowed_output_modes + ))); + } + + let compiler = Plantuml_original::get_compiler_or(&self.data, "plantuml"); + //compile it (to the bin_path that already points to the rigth path) + let output = Command::new(compiler.split_whitespace().next().unwrap()) + .args(compiler.split_whitespace().skip(1)) + .arg("-o") + .arg(&self.language_work_dir) + .arg(&self.output_mode) + .arg("-nbthread") + .arg("auto") + .arg("-failfast2") + .arg(self.main_file_path.clone()) + .output() + .expect("Unable to start process"); + if output.status.success() { + //return stdout + return Ok(()); + } else { + // return stderr + return Err(SniprunError::CompilationError( + String::from_utf8(output.stderr).unwrap(), + )); + } + } + + fn execute(&mut self) -> Result { + let extension = String::from(".") + &self.output_mode[2..]; + let content = std::fs::read_to_string(&self.main_file_path.replace(".uml", &extension)); + if let Ok(content) = content { + Ok(content) + } else { + return Err(SniprunError::RuntimeError(format!( + "could not read output file {}", + &self.main_file_path.replace(".uml", &extension) + ))); + } + } +} + +// You can add tests if you want to +#[cfg(test)] +mod test_plantuml_original { + use super::*; + + #[test] + fn simple_print() { + let mut data = DataHolder::new(); + + //inspired from Rust syntax + data.current_bloc = String::from("@startuml\nparticipant Bob"); + let mut interpreter = Plantuml_original::new(data); + let res = interpreter.run(); + + // -> should panic if not an Ok() + let string_result = res.unwrap(); + + // -> compare result with predicted + assert!(string_result.contains("Bob")); + } +} From 25471a314e8321f82d9dc80c8bbe79770bf142e8 Mon Sep 17 00:00:00 2001 From: Piotr Zaniewski Date: Mon, 22 Jul 2024 22:47:58 +0200 Subject: [PATCH 03/12] fix: correct string comparison operator for compatibility with sh --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 3ca2a4a..d445734 100755 --- a/install.sh +++ b/install.sh @@ -5,7 +5,7 @@ local_version="v$(grep ^version Cargo.toml | cut -d "\"" -f 2)" force_build=$1 current_branch=$(git rev-parse --abbrev-ref HEAD) -if [ "$current_branch" == "dev" ]; then +if [ "$current_branch" = "dev" ]; then force_build=1 fi From 71cf814552355fa6a4a406ae8c2f8f4da23f27bf Mon Sep 17 00:00:00 2001 From: Michael B Date: Sun, 21 Jul 2024 19:54:22 +0200 Subject: [PATCH 04/12] rework module tree for better LSP integration --- build.rs | 16 +++++++++--- src/interpreters/Ada_original.rs | 2 ++ src/interpreters/Bash_original.rs | 3 ++- src/interpreters/CS_original.rs | 2 ++ src/interpreters/CSharp_original.rs | 2 ++ src/interpreters/C_original.rs | 2 ++ src/interpreters/Clojure_fifo.rs | 2 ++ src/interpreters/Cpp_original.rs | 2 ++ src/interpreters/D_original.rs | 2 ++ src/interpreters/Elixir_original.rs | 2 ++ src/interpreters/FSharp_fifo.rs | 2 ++ src/interpreters/GFM_original.rs | 2 ++ src/interpreters/Generic.rs | 2 ++ src/interpreters/Go_original.rs | 2 ++ src/interpreters/Haskell_original.rs | 2 ++ src/interpreters/Http_original.rs | 2 ++ src/interpreters/JS_TS_bun.rs | 2 ++ src/interpreters/JS_TS_deno.rs | 2 ++ src/interpreters/JS_original.rs | 2 ++ src/interpreters/Java_original.rs | 2 ++ src/interpreters/Julia_jupyter.rs | 2 ++ src/interpreters/Julia_original.rs | 2 ++ src/interpreters/Lua_nvim.rs | 4 ++- src/interpreters/Lua_original.rs | 4 ++- src/interpreters/Mathematica_original.rs | 2 ++ src/interpreters/Neorg_original.rs | 2 ++ src/interpreters/OCaml_fifo.rs | 10 +++++++- src/interpreters/OrgMode_original.rs | 2 ++ src/interpreters/Plantuml_original.rs | 2 ++ src/interpreters/Prolog_original.rs | 4 ++- src/interpreters/Python3_fifo.rs | 2 ++ src/interpreters/Python3_jupyter.rs | 2 ++ src/interpreters/Python3_original.rs | 2 ++ src/interpreters/R_original.rs | 2 ++ src/interpreters/Ruby_original.rs | 2 ++ src/interpreters/Rust_original.rs | 2 ++ src/interpreters/Sage_fifo.rs | 2 ++ src/interpreters/Scala_original.rs | 2 ++ src/interpreters/TypeScript_original.rs | 2 ++ src/interpreters/example.rs | 1 + src/interpreters/import.rs | 32 ++++++++++++------------ src/launcher.rs | 2 +- tests/integration.rs | 2 +- 43 files changed, 117 insertions(+), 27 deletions(-) diff --git a/build.rs b/build.rs index 7fd0d2f..334fbb3 100644 --- a/build.rs +++ b/build.rs @@ -20,9 +20,12 @@ fn main() -> Result<(), std::io::Error> { let mut string_to_write = "".to_string(); + string_to_write.push_str("#![allow(non_snake_case)]\n"); + string_to_write.push_str("pub mod import;\n"); + for path in fs::read_dir(out_dir).unwrap() { let plugin = path.unwrap().file_name().into_string().unwrap(); - if plugin == "mod.rs" || plugin == "example.rs" { + if plugin == "mod.rs" || plugin == "example.rs" || plugin == "import.rs" { continue; } if !plugin.ends_with(".rs") { @@ -30,10 +33,15 @@ fn main() -> Result<(), std::io::Error> { continue; } + let plugin = plugin[..plugin.len() - 3].to_string(); string_to_write.push_str(&format!( - "include!(\"{}\"); + "pub mod {}; +pub use {}::{} as {}; ", - plugin + plugin.clone(), + plugin.clone(), + plugin.clone(), + plugin + "_type", )); } @@ -58,7 +66,7 @@ fn main() -> Result<(), std::io::Error> { string_to_write.push('{'); string_to_write.push_str(&format!( " - type Current = interpreters::{}; + type Current = interpreters::{}_type; $( $code )* diff --git a/src/interpreters/Ada_original.rs b/src/interpreters/Ada_original.rs index 9bd06d2..4462878 100644 --- a/src/interpreters/Ada_original.rs +++ b/src/interpreters/Ada_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Ada_original { diff --git a/src/interpreters/Bash_original.rs b/src/interpreters/Bash_original.rs index 55d77c6..3a2a3f8 100644 --- a/src/interpreters/Bash_original.rs +++ b/src/interpreters/Bash_original.rs @@ -1,4 +1,5 @@ -#[derive(Clone)] +use crate::interpreters::import::*; + #[allow(non_camel_case_types)] pub struct Bash_original { support_level: SupportLevel, diff --git a/src/interpreters/CS_original.rs b/src/interpreters/CS_original.rs index ce333b2..3acc03d 100644 --- a/src/interpreters/CS_original.rs +++ b/src/interpreters/CS_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct CS_original { diff --git a/src/interpreters/CSharp_original.rs b/src/interpreters/CSharp_original.rs index ddb7d99..af01aed 100644 --- a/src/interpreters/CSharp_original.rs +++ b/src/interpreters/CSharp_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct CSharp_original { diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index 86dfbcd..123f659 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct C_original { diff --git a/src/interpreters/Clojure_fifo.rs b/src/interpreters/Clojure_fifo.rs index c6cf97d..c5914c0 100644 --- a/src/interpreters/Clojure_fifo.rs +++ b/src/interpreters/Clojure_fifo.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Clojure_fifo { diff --git a/src/interpreters/Cpp_original.rs b/src/interpreters/Cpp_original.rs index 156ac87..519777d 100644 --- a/src/interpreters/Cpp_original.rs +++ b/src/interpreters/Cpp_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Cpp_original { diff --git a/src/interpreters/D_original.rs b/src/interpreters/D_original.rs index eb48d9a..d327735 100644 --- a/src/interpreters/D_original.rs +++ b/src/interpreters/D_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct D_original { diff --git a/src/interpreters/Elixir_original.rs b/src/interpreters/Elixir_original.rs index 789e299..b4f42af 100644 --- a/src/interpreters/Elixir_original.rs +++ b/src/interpreters/Elixir_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Elixir_original { diff --git a/src/interpreters/FSharp_fifo.rs b/src/interpreters/FSharp_fifo.rs index 2e71938..6411231 100644 --- a/src/interpreters/FSharp_fifo.rs +++ b/src/interpreters/FSharp_fifo.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct FSharp_fifo { diff --git a/src/interpreters/GFM_original.rs b/src/interpreters/GFM_original.rs index bb7fbe4..b20614f 100644 --- a/src/interpreters/GFM_original.rs +++ b/src/interpreters/GFM_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct GFM_original { diff --git a/src/interpreters/Generic.rs b/src/interpreters/Generic.rs index 6e4d24c..c1350b5 100644 --- a/src/interpreters/Generic.rs +++ b/src/interpreters/Generic.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Generic { diff --git a/src/interpreters/Go_original.rs b/src/interpreters/Go_original.rs index 0ac019a..144509c 100644 --- a/src/interpreters/Go_original.rs +++ b/src/interpreters/Go_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Go_original { diff --git a/src/interpreters/Haskell_original.rs b/src/interpreters/Haskell_original.rs index 8280dbe..87d0333 100644 --- a/src/interpreters/Haskell_original.rs +++ b/src/interpreters/Haskell_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Haskell_original { diff --git a/src/interpreters/Http_original.rs b/src/interpreters/Http_original.rs index 24ddb4a..1938b11 100644 --- a/src/interpreters/Http_original.rs +++ b/src/interpreters/Http_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + use http_rest_file::model::{FileParseResult, HttpMethod, RequestTarget, WithDefault}; use std::io::Cursor; diff --git a/src/interpreters/JS_TS_bun.rs b/src/interpreters/JS_TS_bun.rs index 2e7e3ab..6dbd869 100644 --- a/src/interpreters/JS_TS_bun.rs +++ b/src/interpreters/JS_TS_bun.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct JS_TS_bun { diff --git a/src/interpreters/JS_TS_deno.rs b/src/interpreters/JS_TS_deno.rs index f30f1a4..01dbc62 100644 --- a/src/interpreters/JS_TS_deno.rs +++ b/src/interpreters/JS_TS_deno.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct JS_TS_deno { diff --git a/src/interpreters/JS_original.rs b/src/interpreters/JS_original.rs index b7d7cae..c681000 100644 --- a/src/interpreters/JS_original.rs +++ b/src/interpreters/JS_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct JS_original { diff --git a/src/interpreters/Java_original.rs b/src/interpreters/Java_original.rs index 0f4db95..431d71a 100644 --- a/src/interpreters/Java_original.rs +++ b/src/interpreters/Java_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Java_original { diff --git a/src/interpreters/Julia_jupyter.rs b/src/interpreters/Julia_jupyter.rs index 4b2b030..1a623d8 100644 --- a/src/interpreters/Julia_jupyter.rs +++ b/src/interpreters/Julia_jupyter.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Julia_jupyter { diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index 2a79353..2cd397f 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Julia_original { diff --git a/src/interpreters/Lua_nvim.rs b/src/interpreters/Lua_nvim.rs index feb2ac0..1be4f5f 100644 --- a/src/interpreters/Lua_nvim.rs +++ b/src/interpreters/Lua_nvim.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Lua_nvim { @@ -66,7 +68,7 @@ impl Interpreter for Lua_nvim { //that doesn't work in nvim context for some reason // note that since Lua_original is the default and if lua_nvim is selected, we should // never take this code path - let mut good_interpreter = crate::interpreters::Lua_original::new_with_level( + let mut good_interpreter = crate::interpreters::Lua_original::Lua_original::new_with_level( self.data.clone(), SupportLevel::Selected, //prevent fallback infinite loop ); diff --git a/src/interpreters/Lua_original.rs b/src/interpreters/Lua_original.rs index b38f8b8..2505fad 100644 --- a/src/interpreters/Lua_original.rs +++ b/src/interpreters/Lua_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Lua_original { @@ -66,7 +68,7 @@ impl Interpreter for Lua_original { self.fetch_code().expect("could not fetch code"); if self.code.contains("nvim") || self.code.contains("vim") { //then this is not pure lua code but lua-nvim one - let mut good_interpreter = crate::interpreters::Lua_nvim::new_with_level( + let mut good_interpreter = crate::interpreters::Lua_nvim::Lua_nvim::new_with_level( self.data.clone(), SupportLevel::Selected, //prevent fallbacking from fallback ); diff --git a/src/interpreters/Mathematica_original.rs b/src/interpreters/Mathematica_original.rs index f0d43a5..3231ecc 100644 --- a/src/interpreters/Mathematica_original.rs +++ b/src/interpreters/Mathematica_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Mathematica_original { diff --git a/src/interpreters/Neorg_original.rs b/src/interpreters/Neorg_original.rs index 9f9e808..4470a87 100644 --- a/src/interpreters/Neorg_original.rs +++ b/src/interpreters/Neorg_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Neorg_original { diff --git a/src/interpreters/OCaml_fifo.rs b/src/interpreters/OCaml_fifo.rs index 5fdadbe..5d541b4 100644 --- a/src/interpreters/OCaml_fifo.rs +++ b/src/interpreters/OCaml_fifo.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct OCaml_fifo { @@ -13,6 +15,12 @@ pub struct OCaml_fifo { } impl OCaml_fifo { + + fn get_nvim_pid(data: &DataHolder) -> String { + // associated utility function + data.nvim_pid.to_string() + } + fn wait_out_file( &self, out_path: String, @@ -253,7 +261,7 @@ impl ReplLikeInterpreter for OCaml_fifo { .args(&[ init_repl_cmd, self.cache_dir.clone(), - Sage_fifo::get_nvim_pid(&self.data), + OCaml_fifo::get_nvim_pid(&self.data), self.interpreter_repl.clone(), ]) .output() diff --git a/src/interpreters/OrgMode_original.rs b/src/interpreters/OrgMode_original.rs index 36d2d00..60e9f01 100644 --- a/src/interpreters/OrgMode_original.rs +++ b/src/interpreters/OrgMode_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct OrgMode_original { diff --git a/src/interpreters/Plantuml_original.rs b/src/interpreters/Plantuml_original.rs index 861910f..20908cf 100644 --- a/src/interpreters/Plantuml_original.rs +++ b/src/interpreters/Plantuml_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + // Be sure to read the CONTRIBUTING.md file :-) #[derive(Clone)] diff --git a/src/interpreters/Prolog_original.rs b/src/interpreters/Prolog_original.rs index 1f71c7c..bb012b4 100644 --- a/src/interpreters/Prolog_original.rs +++ b/src/interpreters/Prolog_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Prolog_original { @@ -54,7 +56,7 @@ impl Interpreter for Prolog_original { let default_interpreter = String::from("gprolog"); self.interpreter = default_interpreter; if let Some(used_interpreter) = - Python3_fifo::get_interpreter_option(&self.get_data(), "interpreter") + Prolog_original::get_interpreter_option(&self.get_data(), "interpreter") { if let Some(interpreter_string) = used_interpreter.as_str() { info!("Using custom interpreter: {}", interpreter_string); diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 2d234a7..111e2ea 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Python3_fifo { diff --git a/src/interpreters/Python3_jupyter.rs b/src/interpreters/Python3_jupyter.rs index 49202d7..f6fd3b8 100644 --- a/src/interpreters/Python3_jupyter.rs +++ b/src/interpreters/Python3_jupyter.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Python3_jupyter { diff --git a/src/interpreters/Python3_original.rs b/src/interpreters/Python3_original.rs index acfbaac..c5d0266 100644 --- a/src/interpreters/Python3_original.rs +++ b/src/interpreters/Python3_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Python3_original { diff --git a/src/interpreters/R_original.rs b/src/interpreters/R_original.rs index ce0bec0..7bf787f 100644 --- a/src/interpreters/R_original.rs +++ b/src/interpreters/R_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct R_original { diff --git a/src/interpreters/Ruby_original.rs b/src/interpreters/Ruby_original.rs index 5c44fce..1d61562 100644 --- a/src/interpreters/Ruby_original.rs +++ b/src/interpreters/Ruby_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Ruby_original { diff --git a/src/interpreters/Rust_original.rs b/src/interpreters/Rust_original.rs index 206b856..b8363e6 100644 --- a/src/interpreters/Rust_original.rs +++ b/src/interpreters/Rust_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Rust_original { diff --git a/src/interpreters/Sage_fifo.rs b/src/interpreters/Sage_fifo.rs index 76fb7ec..f4595fd 100644 --- a/src/interpreters/Sage_fifo.rs +++ b/src/interpreters/Sage_fifo.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Sage_fifo { diff --git a/src/interpreters/Scala_original.rs b/src/interpreters/Scala_original.rs index ce0c7c3..48b7187 100644 --- a/src/interpreters/Scala_original.rs +++ b/src/interpreters/Scala_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct Scala_original { diff --git a/src/interpreters/TypeScript_original.rs b/src/interpreters/TypeScript_original.rs index 79d27de..946af8f 100644 --- a/src/interpreters/TypeScript_original.rs +++ b/src/interpreters/TypeScript_original.rs @@ -1,3 +1,5 @@ +use crate::interpreters::import::*; + #[derive(Clone)] #[allow(non_camel_case_types)] pub struct TypeScript_original { diff --git a/src/interpreters/example.rs b/src/interpreters/example.rs index e3372bb..9342240 100644 --- a/src/interpreters/example.rs +++ b/src/interpreters/example.rs @@ -1,4 +1,5 @@ // Be sure to read the CONTRIBUTING.md file :-) +use crate::interpreters::import::*; #[derive(Clone)] #[allow(non_camel_case_types)] diff --git a/src/interpreters/import.rs b/src/interpreters/import.rs index 8c782dd..9775943 100644 --- a/src/interpreters/import.rs +++ b/src/interpreters/import.rs @@ -1,27 +1,27 @@ -use crate::error::SniprunError; -use crate::interpreter::{Interpreter, InterpreterUtils, ReplLikeInterpreter, SupportLevel, ErrTruncate}; -use crate::DataHolder; -use log::{info,warn}; +pub use crate::error::SniprunError; +pub use crate::interpreter::{Interpreter, InterpreterUtils, ReplLikeInterpreter, SupportLevel, ErrTruncate}; +pub use crate::DataHolder; +pub use log::{info,warn,error, debug}; -use crate::interpreters; -use crate::iter_types; +pub use crate::interpreters; +pub use crate::iter_types; -use std::fs::{write, DirBuilder, File}; -use std::process::Command; +pub use std::fs::{write, DirBuilder, File}; +pub use std::process::Command; -use neovim_lib::NeovimApi; +pub use neovim_lib::NeovimApi; -use std::env; +pub use std::env; -use crate::daemonizer::{daemon,Fork}; +pub use crate::daemonizer::{daemon,Fork}; //indentation -use unindent::unindent; +pub use unindent::unindent; -use std::io::prelude::*; +pub use std::io::prelude::*; -// use jupyter_client::Client; -// use std::collections::HashMap; +// pub use jupyter_client::Client; +// pub use std::collections::HashMap; -use regex::Regex; +pub use regex::Regex; diff --git a/src/launcher.rs b/src/launcher.rs index 2181b6e..bab36d0 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -2,7 +2,7 @@ use crate::interpreter::InterpreterUtils; use crate::*; use error::SniprunError; use interpreter::{Interpreter, SupportLevel}; -use interpreters::Generic; +use interpreters::Generic::Generic; use std::any::TypeId; use std::io::prelude::*; use std::process::Command; diff --git a/tests/integration.rs b/tests/integration.rs index 4950731..545f8cd 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,5 +1,5 @@ use sniprun::interpreter::{Interpreter, InterpreterUtils, ReplLikeInterpreter, SupportLevel}; -use sniprun::interpreters::JS_original; +use sniprun::interpreters::JS_original::JS_original; use sniprun::*; use std::sync::{Arc, Mutex}; From 35f603ac9ab773d83a4e21f71c4b3cd84ebc5051 Mon Sep 17 00:00:00 2001 From: Michael B Date: Wed, 24 Jul 2024 21:06:49 +0200 Subject: [PATCH 05/12] doc --- doc/sources/interpreters/Plantuml_original.md | 8 +++----- src/interpreter.rs | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/doc/sources/interpreters/Plantuml_original.md b/doc/sources/interpreters/Plantuml_original.md index 6fc39e9..6bcd212 100644 --- a/doc/sources/interpreters/Plantuml_original.md +++ b/doc/sources/interpreters/Plantuml_original.md @@ -2,8 +2,6 @@ This interpreter relies on `plantuml`, which needs to be available on the $PATH - - This interpreter supports the following options: ```lua @@ -17,6 +15,6 @@ require'sniprun'.setup({ } }) ``` -You can add options to the 'compiler' key, but do not set "-pipe" (or it'll break output), and "-failfast2", "-nbthread auto" are already set. - - +You can add options to the 'compiler' key, but do not +set "-pipe" (or it'll break output), and "-failfast2", +"-nbthread auto" are already set. diff --git a/src/interpreter.rs b/src/interpreter.rs index 12331ab..1363da1 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -21,8 +21,7 @@ pub enum SupportLevel { ///selected: don't use this support level, it is meant to communicate user's config choices Selected = 255, } - -impl Display for SupportLevel { +impl Display for SupportLevel{ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> { match *self { SupportLevel::Unsupported => f.write_str("None"), From 35bb7f6667bb17f93a8c62b1afdf40e3aba8caab Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 27 Jul 2024 15:42:14 +0200 Subject: [PATCH 06/12] basic input system --- lua/sniprun/display.lua | 1 - lua/sniprun/input.lua | 36 ++++++++++++++++++++++++++++++++++++ src/input.rs | 21 +++++++++++++++++++++ src/lib.rs | 1 + 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lua/sniprun/input.lua create mode 100644 src/input.rs diff --git a/lua/sniprun/display.lua b/lua/sniprun/display.lua index c5649f8..5d0e9c0 100644 --- a/lua/sniprun/display.lua +++ b/lua/sniprun/display.lua @@ -21,7 +21,6 @@ function M.fw_open(row, column, message, ok, temp) local w = 0 local h = -1 local bp = {row , column} - local message_map = {} local bufnr = vim.api.nvim_create_buf(false, true) for line in message:gmatch("([^\n]*)\n?") do h = h + 1 diff --git a/lua/sniprun/input.lua b/lua/sniprun/input.lua new file mode 100644 index 0000000..3e61e69 --- /dev/null +++ b/lua/sniprun/input.lua @@ -0,0 +1,36 @@ +local M = {} + +-- function M.floating_win_ask(message) +-- +-- local w = 0 +-- local h = -1 +-- local bp = vim.api.nvim_win_get_cursor(0) -- message at current cursor position +-- local bufnr = vim.api.nvim_create_buf(false, true) +-- for line in message:gmatch("([^\n]*)\n?") do +-- h = h + 1 +-- w = math.max(w, string.len(line)) +-- vim.api.nvim_buf_set_lines(bufnr, h, h + 1, false, { line }) +-- end +-- if h ~= 0 then +-- M.fw_handle = vim.api.nvim_open_win(bufnr, false, +-- { +-- relative = 'win', +-- width = w + 1, +-- height = h, +-- bufpos = bp, +-- focusable = false, +-- style = 'minimal', +-- border = "single" +-- }) +-- vim.api.nvim_win_call(M.fw_handle, function() +-- vim.api.nvim_exec_autocmds("BufWinEnter", { buffer = bufnr, modeline = false }) +-- end) +-- vim.api.nvim_set_current_win(M.fw_handle) +-- end +-- end + +function M.vim_input(message) + print(vim.fn.input(message)) +end + +return M diff --git a/src/input.rs b/src/input.rs new file mode 100644 index 0000000..4cc267a --- /dev/null +++ b/src/input.rs @@ -0,0 +1,21 @@ +use crate::error::SniprunError; +use neovim_lib::{Neovim, NeovimApi}; +use std::sync::{Arc, Mutex}; +use std::time::Duration; + +pub fn vim_input_ask(message: &str, nvim: &Arc>) -> Result { + nvim.lock() + .unwrap() + .session + .set_timeout(Duration::from_secs(20)); + let res = nvim.lock().unwrap().command_output(&format!( + "lua require\"sniprun.input\".vim_input(\"{}\")", + message.replace('\n', "\\n"), + )); + match res { + Err(_) => Err(SniprunError::CustomError( + "Timeout waiting for user input".into(), + )), + Ok(input) => Ok(input), + } +} diff --git a/src/lib.rs b/src/lib.rs index 364a351..19c331c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ use std::thread; pub mod daemonizer; pub mod display; +pub mod input; pub mod error; pub mod interpreter; pub mod interpreters; From 4bd289641bd436c65d9cd2a4231b2b051aea7ff7 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 27 Jul 2024 15:59:19 +0200 Subject: [PATCH 07/12] SQL interpreter based on usql --- doc/sources/README.md | 46 ++++--- doc/sources/interpreters/SQL_original.md | 27 ++++ src/interpreters/SQL_original.rs | 154 +++++++++++++++++++++++ 3 files changed, 207 insertions(+), 20 deletions(-) create mode 100644 doc/sources/interpreters/SQL_original.md create mode 100644 src/interpreters/SQL_original.rs diff --git a/doc/sources/README.md b/doc/sources/README.md index 17c7618..5d32ec7 100755 --- a/doc/sources/README.md +++ b/doc/sources/README.md @@ -399,43 +399,49 @@ println!("-> {}", alphabet); - -| Language | Support level | REPL Capabilities| +| Language | Support level | REPL Capabilities| | ------------ | ------------- | ---------------- | | Ada | Line | No | | Bash/Shell | Bloc | Yes\* | | C | Import | No | -| C++ | Import | No | -| C# | Bloc | No | -| Clojure | Bloc | Yes \*\* | -| Coffeescript | Bloc | No | -| D | Bloc | No | +| C++ | Import | No | +| C# | Bloc | No | +| Clojure | Bloc | Yes \*\* | +| CoffeeScript | Bloc | No | +| D | Bloc | No | | Elixir | Bloc | Yes \*\* | | F# | Bloc | No, but _could_ \*\* | -| Go | Import | No | -| Haskell | Line | No | -| Java | Bloc | No | -| JavaScript | Bloc | Yes\*\* (Deno) | -| Julia | Bloc | Yes\*\* | -| Lua | Bloc | No | +| Go | Import | No | +| Haskell | Line | No | +| Http | Bloc | No | +| Java | Bloc | No | +| JavaScript | Bloc | Yes\*\* (Deno) | +| Julia | Bloc | Yes\*\* | +| Lua | Bloc | No | | Lua-nvim | Bloc | Yes\*\* | | Markdown | Bloc | Yes\*\*\* | | Mathematica | Bloc | Yes\*\* | | Neorg | Bloc | Yes\*\*\* | | OCaml | Bloc | Yes\*\* | | OrgMode | Bloc | Yes\*\*\* | -| Perl/Perl6 | Line | No | +| Perl/Perl6 | Line | No | +| Plantuml | Bloc | No | | Python3 | Import | Yes\*\* | | R | Bloc | Yes\*\* | -| Ruby | Bloc | No | -| Rust | Bloc | No | +| Ruby | Bloc | No | +| Rust | Bloc | No | | SageMath | Import | Yes\*\* | -| Scala | Bloc | No | -| TypeScript | Bloc | Yes\*\* (Deno) | +| Scala | Bloc | No | +| SQL | Bloc | No | +| TypeScript | Bloc | Yes\*\* (Deno) | -Your language is not officially supported ? The [Generic interpreter](https://michaelb.github.io/sniprun/sources/Generic.html#community-examples-for-non-officially-supported-languages) can probably work with it ! +Your language is not officially supported ? The +[Generic interpreter](https://michaelb.github.io/sniprun/sources/Generic.html#community-examples-for-non-officially-supported-languages) +can probably work with it ! -Want (official) support for your language? Submit an [issue](https://github.com/michaelb/sniprun/issues/new?assignees=&labels=new-langage-support&template=support-for--language-.md&title=),or even better, contribute (see CONTRIBUTING.md), it's easy! +Want (official) support for your language? Submit an +[issue](https://github.com/michaelb/sniprun/issues/new?assignees=&labels=new-langage-support&template=support-for--language-.md&title=), +or even better, contribute (see CONTRIBUTING.md), it's easy! \* (fake) REPL-like functionality, with potential unwanted side effects diff --git a/doc/sources/interpreters/SQL_original.md b/doc/sources/interpreters/SQL_original.md new file mode 100644 index 0000000..c823dd8 --- /dev/null +++ b/doc/sources/interpreters/SQL_original.md @@ -0,0 +1,27 @@ +## SQL original + +This interpreter relies on `usql` being installed + +```lua +require'sniprun'.setup({ + interpreter_options = { + SQL_original = { + interpreter = "/home/user/my_usql_install/usql --myoption" + } + } + } +}) +``` + +the option "-w" (do not prompt for the password) and --file are already passed +by sniprun, so you should not pass conflicting/duplicate options. + +This interpreter will prompt you at first use what database you want to connect to, +that is an address (including user & password if applicable) as you would +pass to `usql` itself. In case the database is local (such as for sqlite), +you should input an absolute path or a path relative to neovim's current +working directory (`:pwd`). + +This address (and the possible user/password) is NOT stored anywhere, but sniprun +will remember it as long as the neovim session stays open. You can use `:SnipReset` +to clear sniprun's memory. diff --git a/src/interpreters/SQL_original.rs b/src/interpreters/SQL_original.rs new file mode 100644 index 0000000..2fe803a --- /dev/null +++ b/src/interpreters/SQL_original.rs @@ -0,0 +1,154 @@ +use crate::input; +use crate::interpreters::import::*; + +#[derive(Clone)] +#[allow(non_camel_case_types)] +pub struct SQL_original { + support_level: SupportLevel, + data: DataHolder, + code: String, + + main_file_path: String, +} +impl ReplLikeInterpreter for SQL_original {} +impl Interpreter for SQL_original { + fn new_with_level(data: DataHolder, support_level: SupportLevel) -> Box { + //create a subfolder in the cache folder + let rwd = data.work_dir.clone() + "/sql_original"; + let mut builder = DirBuilder::new(); + builder.recursive(true); + builder + .create(&rwd) + .expect("Could not create directory for sql-original"); + + //pre-create string pointing to main file's and binary's path + let mfp = rwd + "/main.sql"; + Box::new(SQL_original { + data, + support_level, + code: String::from(""), + main_file_path: mfp, + }) + } + + fn get_supported_languages() -> Vec { + vec![ + String::from("SQL"), + String::from("sql"), + String::from("usql"), + ] + } + + fn get_name() -> String { + String::from("SQL_original") + } + + fn get_current_level(&self) -> SupportLevel { + self.support_level + } + fn set_current_level(&mut self, level: SupportLevel) { + self.support_level = level; + } + + fn default_for_filetype() -> bool { + true + } + + fn get_data(&self) -> DataHolder { + self.data.clone() + } + + fn get_max_support_level() -> SupportLevel { + SupportLevel::Bloc + } + + fn fetch_code(&mut self) -> Result<(), SniprunError> { + //add code from data to self.code + if !self + .data + .current_bloc + .replace(&[' ', '\t', '\n', '\r'][..], "") + .is_empty() + && self.support_level >= SupportLevel::Bloc + { + self.code = self.data.current_bloc.clone(); + } else if !self.data.current_line.replace(' ', "").is_empty() + && self.support_level >= SupportLevel::Line + { + self.code = self.data.current_line.clone(); + } else { + self.code = String::from(""); + } + + if self.read_previous_code().is_empty() { + if let Some(nvim_instance) = self.data.nvim_instance.clone() { + let user_input = + input::vim_input_ask("Enter uSQL database address:", &nvim_instance)?; + self.save_code(user_input); + } + } + Ok(()) + } + + fn add_boilerplate(&mut self) -> Result<(), SniprunError> { + Ok(()) + } + + fn build(&mut self) -> Result<(), SniprunError> { + //write code to file + let mut _file = + File::create(&self.main_file_path).expect("Failed to create file for sql-original"); + write(&self.main_file_path, &self.code).expect("Unable to write to file for sql-original"); + Ok(()) + } + + fn execute(&mut self) -> Result { + //run th binary and get the std output (or stderr) + let interpreter = SQL_original::get_interpreter_or(&self.data, "usql"); + let output = Command::new(interpreter.split_whitespace().next().unwrap()) + .args(interpreter.split_whitespace().skip(1)) + .arg("-w") + .arg("--file") + .arg(&self.main_file_path) + .arg(&self.read_previous_code().replace('\n',"")) // contains database address + .current_dir(&self.data.projectroot) + .output() + .expect("Unable to start process"); + if output.status.success() { + Ok(String::from_utf8(output.stdout).unwrap()) + } else if SQL_original::error_truncate(&self.get_data()) == ErrTruncate::Short { + Err(SniprunError::RuntimeError( + String::from_utf8(output.stderr.clone()) + .unwrap() + .lines() + .next() + .unwrap_or(&String::from_utf8(output.stderr).unwrap()) + .to_owned(), + )) + } else { + Err(SniprunError::RuntimeError( + String::from_utf8(output.stderr).unwrap(), + )) + } + } +} + +#[cfg(test)] +mod test_d_original { + use super::*; + use serial_test::serial; + + #[test] + #[serial(d_original)] + fn simple_print() { + let mut data = DataHolder::new(); + data.current_bloc = + String::from("string yourName = \"a\";\nwritefln(\"Hi %s!\", yourName);"); + let mut interpreter = SQL_original::new(data); + let res = interpreter.run(); + + // should panic if not an Ok() + let string_result = res.unwrap(); + assert_eq!(string_result, "Hi a!\n"); + } +} From e55a14f254f32afbb99ea02db5d9b5e1cc35fdf6 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 27 Jul 2024 16:27:27 +0200 Subject: [PATCH 08/12] some clippy fixes --- src/interpreters/Http_original.rs | 6 +++--- src/interpreters/Plantuml_original.rs | 14 +++++++------- src/interpreters/Python3_jupyter.rs | 2 +- src/launcher.rs | 2 +- src/lib.rs | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/interpreters/Http_original.rs b/src/interpreters/Http_original.rs index 1938b11..2d8590c 100644 --- a/src/interpreters/Http_original.rs +++ b/src/interpreters/Http_original.rs @@ -177,7 +177,7 @@ mod test_http_original { let data = res.ok().unwrap(); let (body, status) = data.split_once("---").unwrap(); - let v: serde_json::Value = serde_json::from_str(&body).unwrap(); + let v: serde_json::Value = serde_json::from_str(body).unwrap(); println!("{}", serde_json::to_string_pretty(&v).unwrap()); assert_eq!(v["url"], "https://httpbin.org/get".to_owned()); @@ -202,7 +202,7 @@ mod test_http_original { let data = res.ok().unwrap(); let (body, status) = data.split_once("---").unwrap(); - let v: serde_json::Value = serde_json::from_str(&body).unwrap(); + let v: serde_json::Value = serde_json::from_str(body).unwrap(); println!("{}", serde_json::to_string_pretty(&v).unwrap()); assert_eq!(v["url"], "https://httpbin.org/get".to_owned()); @@ -259,7 +259,7 @@ POST https://httpbin.org/post let data = res.ok().unwrap(); let (body, status) = data.split_once("---").unwrap(); - let v: serde_json::Value = serde_json::from_str(&body).unwrap(); + let v: serde_json::Value = serde_json::from_str(body).unwrap(); // println!("{}", serde_json::to_string_pretty(&v).unwrap()); let j: serde_json::Value = serde_json::from_str(&v["json"].to_string()).unwrap(); diff --git a/src/interpreters/Plantuml_original.rs b/src/interpreters/Plantuml_original.rs index 20908cf..9528351 100644 --- a/src/interpreters/Plantuml_original.rs +++ b/src/interpreters/Plantuml_original.rs @@ -140,7 +140,7 @@ impl Interpreter for Plantuml_original { self.code = self.data.current_bloc.clone(); // if there is only data on current line / or Line is the max support level - } else if !self.data.current_line.replace(" ", "").is_empty() + } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { self.code = self.data.current_line.clone(); @@ -214,25 +214,25 @@ impl Interpreter for Plantuml_original { .expect("Unable to start process"); if output.status.success() { //return stdout - return Ok(()); + Ok(()) } else { // return stderr - return Err(SniprunError::CompilationError( + Err(SniprunError::CompilationError( String::from_utf8(output.stderr).unwrap(), - )); + )) } } fn execute(&mut self) -> Result { let extension = String::from(".") + &self.output_mode[2..]; - let content = std::fs::read_to_string(&self.main_file_path.replace(".uml", &extension)); + let content = std::fs::read_to_string(self.main_file_path.replace(".uml", &extension)); if let Ok(content) = content { Ok(content) } else { - return Err(SniprunError::RuntimeError(format!( + Err(SniprunError::RuntimeError(format!( "could not read output file {}", &self.main_file_path.replace(".uml", &extension) - ))); + ))) } } } diff --git a/src/interpreters/Python3_jupyter.rs b/src/interpreters/Python3_jupyter.rs index f6fd3b8..90e5f41 100644 --- a/src/interpreters/Python3_jupyter.rs +++ b/src/interpreters/Python3_jupyter.rs @@ -380,7 +380,7 @@ mod test_python3_jupyter { // should panic if not an Ok() let string_result = res.unwrap(); - assert!(string_result.contains(&"a 1")); + assert!(string_result.contains("a 1")); } #[allow(dead_code)] diff --git a/src/launcher.rs b/src/launcher.rs index bab36d0..0896302 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -151,7 +151,7 @@ impl Launcher { iter_types! { let line = format!("| {:<21}| {:<13}| {:<8}|{:^13}|{:^12}|{:^14}|", Current::get_name(), - Current::get_supported_languages().get(0).unwrap_or(&"".to_string()), + Current::get_supported_languages().first().unwrap_or(&"".to_string()), Current::get_max_support_level().to_string(), match Current::default_for_filetype() {true => "yes" ,false => "no"}, match Current::has_repl_capability() { true => "yes" ,false => "no"}, diff --git a/src/lib.rs b/src/lib.rs index 19c331c..7e9e4db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -449,7 +449,7 @@ enum HandleAction { pub fn start() { let mut event_handler = EventHandler::new(); let _ = log_to_file( - &format!("{}/{}", event_handler.data.work_dir, "sniprun.log"), + format!("{}/{}", event_handler.data.work_dir, "sniprun.log"), LevelFilter::Info, ); log_panics::init(); @@ -580,7 +580,7 @@ mod test_main { #[test] fn test_main() { let mut event_handler = fake_event(); - let _ = log_to_file(&"test_sniprun.log".to_string(), LevelFilter::Info); + let _ = log_to_file("test_sniprun.log", LevelFilter::Info); event_handler.fill_data(&fake_msgpack()); event_handler.data.filetype = String::from("javascript"); From 4593fdf545dfec9b93eb52f517d8f93ed9b7a290 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 27 Jul 2024 16:49:45 +0200 Subject: [PATCH 09/12] clippy fixes --- src/display.rs | 4 +- src/interpreter.rs | 2 +- src/interpreters/Ada_original.rs | 12 +++--- src/interpreters/Bash_original.rs | 10 +++-- src/interpreters/CS_original.rs | 4 +- src/interpreters/CSharp_original.rs | 4 +- src/interpreters/C_original.rs | 4 +- src/interpreters/Clojure_fifo.rs | 5 +-- src/interpreters/Cpp_original.rs | 16 +++++--- src/interpreters/D_original.rs | 4 +- src/interpreters/Elixir_original.rs | 4 +- src/interpreters/FSharp_fifo.rs | 4 +- src/interpreters/GFM_original.rs | 10 ++--- src/interpreters/Generic.rs | 8 ++-- src/interpreters/Go_original.rs | 4 +- src/interpreters/Haskell_original.rs | 4 +- src/interpreters/Http_original.rs | 4 +- src/interpreters/JS_TS_bun.rs | 9 +++-- src/interpreters/JS_TS_deno.rs | 7 ++-- src/interpreters/JS_original.rs | 4 +- src/interpreters/Java_original.rs | 4 +- src/interpreters/Julia_jupyter.rs | 10 ++--- src/interpreters/Julia_original.rs | 4 +- src/interpreters/Lua_nvim.rs | 13 ++++--- src/interpreters/Lua_original.rs | 4 +- src/interpreters/Mathematica_original.rs | 43 ++++++++++++--------- src/interpreters/Neorg_original.rs | 15 +++----- src/interpreters/OCaml_fifo.rs | 22 ++++------- src/interpreters/OrgMode_original.rs | 49 +++++++++++++++--------- src/interpreters/Plantuml_original.rs | 4 +- src/interpreters/Prolog_original.rs | 4 +- src/interpreters/Python3_fifo.rs | 30 ++++++++------- src/interpreters/Python3_jupyter.rs | 16 ++++---- src/interpreters/Python3_original.rs | 18 ++++----- src/interpreters/R_original.rs | 4 +- src/interpreters/Ruby_original.rs | 4 +- src/interpreters/Rust_original.rs | 4 +- src/interpreters/SQL_original.rs | 6 +-- src/interpreters/Sage_fifo.rs | 12 +++--- src/interpreters/Scala_original.rs | 4 +- src/interpreters/TypeScript_original.rs | 4 +- src/interpreters/example.rs | 4 +- src/interpreters/import.rs | 9 +++-- src/lib.rs | 2 +- 44 files changed, 219 insertions(+), 193 deletions(-) diff --git a/src/display.rs b/src/display.rs index b57da69..532a9a4 100644 --- a/src/display.rs +++ b/src/display.rs @@ -440,7 +440,7 @@ fn shorten_ok(message: &str) -> String { let mut marker = String::from("<- "); if message.lines().count() > 1 { - marker += &".".repeat(std::cmp::max(2, std::cmp::min(6, message.lines().count()))); + marker += &".".repeat(message.lines().count().clamp(2, 6)); } marker.to_string() @@ -457,7 +457,7 @@ fn shorten_err(message: &str) -> String { } let mut marker = String::from("<- ") + message.lines().next().unwrap_or(""); if message.lines().count() > 1 { - marker += &".".repeat(std::cmp::max(3, std::cmp::min(10, message.lines().count()))); + marker += &".".repeat(message.lines().count().clamp(3, 10)); } marker } diff --git a/src/interpreter.rs b/src/interpreter.rs index 1363da1..6403356 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -21,7 +21,7 @@ pub enum SupportLevel { ///selected: don't use this support level, it is meant to communicate user's config choices Selected = 255, } -impl Display for SupportLevel{ +impl Display for SupportLevel { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> { match *self { SupportLevel::Unsupported => f.write_str("None"), diff --git a/src/interpreters/Ada_original.rs b/src/interpreters/Ada_original.rs index 4462878..153f901 100644 --- a/src/interpreters/Ada_original.rs +++ b/src/interpreters/Ada_original.rs @@ -80,11 +80,11 @@ impl Interpreter for Ada_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -92,10 +92,10 @@ impl Interpreter for Ada_original { } fn add_boilerplate(&mut self) -> Result<(), SniprunError> { - self.code = String::from( - "with Ada.Text_IO;\nuse Ada.Text_IO;\nprocedure main is\n\nbegin\n", - ) + &self.code - + "\nend main;"; + self.code = + String::from("with Ada.Text_IO;\nuse Ada.Text_IO;\nprocedure main is\n\nbegin\n") + + &self.code + + "\nend main;"; Ok(()) } diff --git a/src/interpreters/Bash_original.rs b/src/interpreters/Bash_original.rs index 3a2a3f8..d0e9887 100644 --- a/src/interpreters/Bash_original.rs +++ b/src/interpreters/Bash_original.rs @@ -79,11 +79,11 @@ impl Interpreter for Bash_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -92,7 +92,11 @@ impl Interpreter for Bash_original { fn add_boilerplate(&mut self) -> Result<(), SniprunError> { //add shebang just in case - self.code = String::from("#!/usr/bin/env bash \n") + "sniprun_main123456789(){\n" + &self.code + "\n}\n" + "sniprun_main123456789\n"; + self.code = String::from("#!/usr/bin/env bash \n") + + "sniprun_main123456789(){\n" + + &self.code + + "\n}\n" + + "sniprun_main123456789\n"; Ok(()) } diff --git a/src/interpreters/CS_original.rs b/src/interpreters/CS_original.rs index 3acc03d..6ab0f07 100644 --- a/src/interpreters/CS_original.rs +++ b/src/interpreters/CS_original.rs @@ -1,5 +1,4 @@ use crate::interpreters::import::*; - #[derive(Clone)] #[allow(non_camel_case_types)] pub struct CS_original { @@ -71,11 +70,10 @@ impl Interpreter for CS_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); } else { self.code = String::from(""); } diff --git a/src/interpreters/CSharp_original.rs b/src/interpreters/CSharp_original.rs index af01aed..71ef744 100644 --- a/src/interpreters/CSharp_original.rs +++ b/src/interpreters/CSharp_original.rs @@ -97,11 +97,11 @@ impl Interpreter for CSharp_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/C_original.rs b/src/interpreters/C_original.rs index 123f659..729ea8b 100644 --- a/src/interpreters/C_original.rs +++ b/src/interpreters/C_original.rs @@ -130,9 +130,9 @@ impl Interpreter for C_original { .replace(&[' ', '\t', '\n', '\r'][..], "") .is_empty() { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Clojure_fifo.rs b/src/interpreters/Clojure_fifo.rs index c5914c0..bd078b0 100644 --- a/src/interpreters/Clojure_fifo.rs +++ b/src/interpreters/Clojure_fifo.rs @@ -196,11 +196,11 @@ impl Interpreter for Clojure_fifo { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -215,7 +215,6 @@ impl Interpreter for Clojure_fifo { Ok(()) } fn execute(&mut self) -> Result { - let output = Command::new(self.interpreter.split_whitespace().next().unwrap()) .args(self.interpreter.split_whitespace().skip(1)) .arg(&self.main_file_path) diff --git a/src/interpreters/Cpp_original.rs b/src/interpreters/Cpp_original.rs index 519777d..cd2050d 100644 --- a/src/interpreters/Cpp_original.rs +++ b/src/interpreters/Cpp_original.rs @@ -128,9 +128,9 @@ impl Interpreter for Cpp_original { .replace(&[' ', '\t', '\n', '\r'][..], "") .is_empty() { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -175,12 +175,18 @@ impl Interpreter for Cpp_original { )) } else { Err(SniprunError::CompilationError( - String::from_utf8(output.stderr.clone()).unwrap().lines().take(5).collect::>().join("\n") + String::from_utf8(output.stderr.clone()) + .unwrap() + .lines() + .take(5) + .collect::>() + .join("\n"), )) } } else { - Err(SniprunError::CompilationError(String::from_utf8(output.stderr.clone()).unwrap())) - + Err(SniprunError::CompilationError( + String::from_utf8(output.stderr.clone()).unwrap(), + )) } } else { Ok(()) diff --git a/src/interpreters/D_original.rs b/src/interpreters/D_original.rs index d327735..c524342 100644 --- a/src/interpreters/D_original.rs +++ b/src/interpreters/D_original.rs @@ -66,11 +66,11 @@ impl Interpreter for D_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Elixir_original.rs b/src/interpreters/Elixir_original.rs index b4f42af..3a4f52f 100644 --- a/src/interpreters/Elixir_original.rs +++ b/src/interpreters/Elixir_original.rs @@ -145,11 +145,11 @@ impl Interpreter for Elixir_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/FSharp_fifo.rs b/src/interpreters/FSharp_fifo.rs index 6411231..3e74b2b 100644 --- a/src/interpreters/FSharp_fifo.rs +++ b/src/interpreters/FSharp_fifo.rs @@ -178,11 +178,11 @@ impl Interpreter for FSharp_fifo { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/GFM_original.rs b/src/interpreters/GFM_original.rs index b20614f..5ae1f26 100644 --- a/src/interpreters/GFM_original.rs +++ b/src/interpreters/GFM_original.rs @@ -29,8 +29,8 @@ impl GFM_original { let mut counter = 0; let selection_line = self.data.range[0] as usize; let mut v = vec![]; - for (i,l) in lines.iter().enumerate() { - if (l.trim_start().starts_with("```") && !l.trim_start()[3..].trim().is_empty()) + for (i, l) in lines.iter().enumerate() { + if (l.trim_start().starts_with("```") && !l.trim_start()[3..].trim().is_empty()) && counter % 2 == 1 { return Err(SniprunError::CustomError(String::from( @@ -46,7 +46,7 @@ impl GFM_original { v[((counter - 1) / 2) as usize].1 = selection_line + i - 1; } } - } + } if counter >= 2 { info!("counting {} code blocs delimiters", counter); if counter % 2 == 1 { @@ -54,7 +54,7 @@ impl GFM_original { "Selection contains an odd number of code bloc delimiters", ))); } - info!("running separately ranges : {:?}",v); + info!("running separately ranges : {:?}", v); return Err(SniprunError::ReRunRanges(v)); } info!("no muliple bloc was found"); @@ -207,7 +207,7 @@ impl Interpreter for GFM_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self .data .current_line diff --git a/src/interpreters/Generic.rs b/src/interpreters/Generic.rs index c1350b5..f6867d9 100644 --- a/src/interpreters/Generic.rs +++ b/src/interpreters/Generic.rs @@ -171,7 +171,7 @@ impl Interpreter for Generic { Generic::generic_get_interpreter_option(&data, "compiler") { if let Some(compiler_string) = used_compiler.as_str() { - if ! compiler_string.is_empty() { + if !compiler_string.is_empty() { info!("Using compiler: {}", compiler_string); compiler = compiler_string.to_string(); config_name = fetched_config_name; @@ -184,7 +184,7 @@ impl Interpreter for Generic { Generic::generic_get_interpreter_option(&data, "interpreter") { if let Some(interpreter_string) = used_interpreter.as_str() { - if ! interpreter_string.is_empty() { + if !interpreter_string.is_empty() { info!("Using interpreter: {}", interpreter_string); interpreter = interpreter_string.to_string(); config_name = fetched_config_name; @@ -285,9 +285,9 @@ impl Interpreter for Generic { .replace(&[' ', '\t', '\n', '\r'][..], "") .is_empty() { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Go_original.rs b/src/interpreters/Go_original.rs index 144509c..00fcdae 100644 --- a/src/interpreters/Go_original.rs +++ b/src/interpreters/Go_original.rs @@ -200,11 +200,11 @@ impl Interpreter for Go_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Haskell_original.rs b/src/interpreters/Haskell_original.rs index 87d0333..e667f84 100644 --- a/src/interpreters/Haskell_original.rs +++ b/src/interpreters/Haskell_original.rs @@ -79,11 +79,11 @@ impl Interpreter for Haskell_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Http_original.rs b/src/interpreters/Http_original.rs index 2d8590c..65c7048 100644 --- a/src/interpreters/Http_original.rs +++ b/src/interpreters/Http_original.rs @@ -72,13 +72,13 @@ impl Interpreter for Http_original { { // if bloc is not pseudo empty and has Bloc current support level, // add fetched code to self - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); // if there is only data on current line / or Line is the max support level } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { // no code was retrieved self.code = String::from(""); diff --git a/src/interpreters/JS_TS_bun.rs b/src/interpreters/JS_TS_bun.rs index 6dbd869..40e3fcd 100644 --- a/src/interpreters/JS_TS_bun.rs +++ b/src/interpreters/JS_TS_bun.rs @@ -66,7 +66,10 @@ impl JS_TS_bun { } else { String::new() }; - return Ok(relevant_content[index + start_mark.len()..index_end].to_owned() + "\n" + &possible_other); + return Ok(relevant_content[index + start_mark.len()..index_end] + .to_owned() + + "\n" + + &possible_other); } } } @@ -157,11 +160,11 @@ impl Interpreter for JS_TS_bun { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { // no code was retrieved self.code = String::from(""); diff --git a/src/interpreters/JS_TS_deno.rs b/src/interpreters/JS_TS_deno.rs index 01dbc62..39dca01 100644 --- a/src/interpreters/JS_TS_deno.rs +++ b/src/interpreters/JS_TS_deno.rs @@ -183,11 +183,11 @@ impl Interpreter for JS_TS_deno { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { // no code was retrieved self.code = String::from(""); @@ -238,7 +238,8 @@ impl Interpreter for JS_TS_deno { .lines() .filter(|l| l.contains("Error:")) .last() - .unwrap_or(&String::from_utf8(output.stderr).unwrap()).to_string(), + .unwrap_or(&String::from_utf8(output.stderr).unwrap()) + .to_string(), )) } else { Err(SniprunError::RuntimeError( diff --git a/src/interpreters/JS_original.rs b/src/interpreters/JS_original.rs index c681000..f9930e6 100644 --- a/src/interpreters/JS_original.rs +++ b/src/interpreters/JS_original.rs @@ -71,11 +71,11 @@ impl Interpreter for JS_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Java_original.rs b/src/interpreters/Java_original.rs index 431d71a..f97c459 100644 --- a/src/interpreters/Java_original.rs +++ b/src/interpreters/Java_original.rs @@ -72,11 +72,11 @@ impl Interpreter for Java_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Julia_jupyter.rs b/src/interpreters/Julia_jupyter.rs index 1a623d8..74558d5 100644 --- a/src/interpreters/Julia_jupyter.rs +++ b/src/interpreters/Julia_jupyter.rs @@ -75,11 +75,11 @@ impl Interpreter for Julia_jupyter { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -197,9 +197,9 @@ impl ReplLikeInterpreter for Julia_jupyter { strip_ansi_escapes::strip_str(String::from_utf8_lossy(&output.stderr.clone())) .lines() .last() - .unwrap_or( - &strip_ansi_escapes::strip_str(String::from_utf8_lossy(&output.stderr)) - ) + .unwrap_or(&strip_ansi_escapes::strip_str(String::from_utf8_lossy( + &output.stderr, + ))) .to_owned(), )); } diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index 2cd397f..ab62e3b 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -161,11 +161,11 @@ impl Interpreter for Julia_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Lua_nvim.rs b/src/interpreters/Lua_nvim.rs index 1be4f5f..26099cb 100644 --- a/src/interpreters/Lua_nvim.rs +++ b/src/interpreters/Lua_nvim.rs @@ -68,10 +68,11 @@ impl Interpreter for Lua_nvim { //that doesn't work in nvim context for some reason // note that since Lua_original is the default and if lua_nvim is selected, we should // never take this code path - let mut good_interpreter = crate::interpreters::Lua_original::Lua_original::new_with_level( - self.data.clone(), - SupportLevel::Selected, //prevent fallback infinite loop - ); + let mut good_interpreter = + crate::interpreters::Lua_original::Lua_original::new_with_level( + self.data.clone(), + SupportLevel::Selected, //prevent fallback infinite loop + ); return Some(good_interpreter.run()); } None @@ -85,11 +86,11 @@ impl Interpreter for Lua_nvim { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Lua_original.rs b/src/interpreters/Lua_original.rs index 2505fad..0401a88 100644 --- a/src/interpreters/Lua_original.rs +++ b/src/interpreters/Lua_original.rs @@ -85,11 +85,11 @@ impl Interpreter for Lua_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Mathematica_original.rs b/src/interpreters/Mathematica_original.rs index 3231ecc..d63223b 100644 --- a/src/interpreters/Mathematica_original.rs +++ b/src/interpreters/Mathematica_original.rs @@ -77,13 +77,10 @@ impl Mathematica_original { } } info!("not found yet"); - } let index = contents.rfind(&start_mark).unwrap(); - Ok( - contents[index + start_mark.len()..contents.len() - end_mark.len() - 1].to_owned(), - ) + Ok(contents[index + start_mark.len()..contents.len() - end_mark.len() - 1].to_owned()) } } @@ -152,11 +149,11 @@ impl Interpreter for Mathematica_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -166,9 +163,10 @@ impl Interpreter for Mathematica_original { fn add_boilerplate(&mut self) -> Result<(), SniprunError> { let mut preload_graphics = String::from(""); let mut wait_for_graphics = String::from(""); - if let Some(use_javagraphics_msgpack) = - Mathematica_original::get_interpreter_option(&self.get_data(), "use_javagraphics_if_contains") - { + if let Some(use_javagraphics_msgpack) = Mathematica_original::get_interpreter_option( + &self.get_data(), + "use_javagraphics_if_contains", + ) { if let Some(use_javagraphics) = use_javagraphics_msgpack.as_array() { for test_contains_msgpack in use_javagraphics.iter() { if let Some(test_contains) = test_contains_msgpack.as_str() { @@ -177,12 +175,14 @@ impl Interpreter for Mathematica_original { preload_graphics = String::from("<= 0 { - wait_for_graphics = "Pause[".to_owned() + &time.to_string() + "];"; + wait_for_graphics = + "Pause[".to_owned() + &time.to_string() + "];"; } } } @@ -194,7 +194,10 @@ impl Interpreter for Mathematica_original { } if let Some(wrap_all_lines_with_print_msgpack) = - Mathematica_original::get_interpreter_option(&self.get_data(), "wrap_all_lines_with_print") + Mathematica_original::get_interpreter_option( + &self.get_data(), + "wrap_all_lines_with_print", + ) { if let Some(wrap_all_lines_with_print) = wrap_all_lines_with_print_msgpack.as_bool() { if wrap_all_lines_with_print { @@ -207,7 +210,10 @@ impl Interpreter for Mathematica_original { } } if let Some(wrap_last_line_with_print_msgpack) = - Mathematica_original::get_interpreter_option(&self.get_data(), "wrap_last_line_with_print") + Mathematica_original::get_interpreter_option( + &self.get_data(), + "wrap_last_line_with_print", + ) { if let Some(wrap_last_line_with_print) = wrap_last_line_with_print_msgpack.as_bool() { if wrap_last_line_with_print { @@ -318,9 +324,10 @@ impl ReplLikeInterpreter for Mathematica_original { fn add_boilerplate_repl(&mut self) -> Result<(), SniprunError> { info!("adding boilerplate"); let mut preload_graphics = ""; - if let Some(use_javagraphics_msgpack) = - Mathematica_original::get_interpreter_option(&self.get_data(), "use_javagraphics_if_contains") - { + if let Some(use_javagraphics_msgpack) = Mathematica_original::get_interpreter_option( + &self.get_data(), + "use_javagraphics_if_contains", + ) { if !self.read_previous_code().contains("JavaGraphics loaded") { if let Some(use_javagraphics) = use_javagraphics_msgpack.as_array() { for test_contains_msgpack in use_javagraphics.iter() { diff --git a/src/interpreters/Neorg_original.rs b/src/interpreters/Neorg_original.rs index 4470a87..283db79 100644 --- a/src/interpreters/Neorg_original.rs +++ b/src/interpreters/Neorg_original.rs @@ -81,7 +81,9 @@ impl Neorg_original { } if v.is_empty() { - return Err(SniprunError::CustomError("No matching tag #name was found".to_string())); + return Err(SniprunError::CustomError( + "No matching tag #name was found".to_string(), + )); } info!("running separately ranges : {:?}", v); @@ -164,11 +166,7 @@ impl Neorg_original { .unwrap() .join(""); if line_i.trim_start().to_lowercase().starts_with("@code") { - let flavor = line_i - .split_whitespace() - .nth(1) - .unwrap_or("") - .to_owned(); + let flavor = line_i.split_whitespace().nth(1).unwrap_or("").to_owned(); return Ok(self.filetype_from_str(&flavor)); } } @@ -280,8 +278,7 @@ impl Interpreter for Neorg_original { for (i, l) in lines.iter().enumerate() { info!("checking named tag {} in line {}", tag_name, i); if l.trim_start().to_lowercase().starts_with("#name") - && tag_name.to_lowercase() - == (*l.to_lowercase().replace("#name", "").trim()) + && tag_name.to_lowercase() == (*l.to_lowercase().replace("#name", "").trim()) { found = true; info!("found named tag {} in line: {}", tag_name, l); @@ -305,7 +302,7 @@ impl Interpreter for Neorg_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self .data .current_line diff --git a/src/interpreters/OCaml_fifo.rs b/src/interpreters/OCaml_fifo.rs index 5d541b4..74dc35f 100644 --- a/src/interpreters/OCaml_fifo.rs +++ b/src/interpreters/OCaml_fifo.rs @@ -15,17 +15,12 @@ pub struct OCaml_fifo { } impl OCaml_fifo { - fn get_nvim_pid(data: &DataHolder) -> String { // associated utility function data.nvim_pid.to_string() } - fn wait_out_file( - &self, - out_path: String, - id: u32, - ) -> Result { + fn wait_out_file(&self, out_path: String, id: u32) -> Result { //extra nils come from the stdout & stderr mark prints themselves let end_mark_ok = String::from("sniprun_finished_id=") + &id.to_string(); let start_mark_ok = String::from("sniprun_started_id=") + &id.to_string(); @@ -60,7 +55,7 @@ impl OCaml_fifo { if res.is_ok() { info!("file could be read : {:?}", out_contents); // info!("file : {:?}", contents); - out_contents = out_contents.replace("- : unit = ()\n",""); + out_contents = out_contents.replace("- : unit = ()\n", ""); if out_contents.contains(&end_mark_ok) { info!("out found"); let index = out_contents.rfind(&start_mark_ok).unwrap(); @@ -81,8 +76,7 @@ impl OCaml_fifo { } fn fetch_config(&mut self) { - let default_interpreter_repl = - String::from("ocaml -noprompt"); + let default_interpreter_repl = String::from("ocaml -noprompt"); let default_interpreter = String::from("ocaml"); self.interpreter = default_interpreter; self.interpreter_repl = default_interpreter_repl; @@ -179,11 +173,11 @@ impl Interpreter for OCaml_fifo { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -270,9 +264,9 @@ impl ReplLikeInterpreter for OCaml_fifo { return Err(SniprunError::CustomError("ocaml REPL exited".to_owned())); } Ok(Fork::Parent(_)) => {} - Err(_) => info!( - "OCaml_fifo could not fork itself to the background to launch the kernel" - ), + Err(_) => { + info!("OCaml_fifo could not fork itself to the background to launch the kernel") + } }; self.save_code("kernel_launched\n".to_owned()); diff --git a/src/interpreters/OrgMode_original.rs b/src/interpreters/OrgMode_original.rs index 60e9f01..0903d5c 100644 --- a/src/interpreters/OrgMode_original.rs +++ b/src/interpreters/OrgMode_original.rs @@ -42,14 +42,18 @@ impl OrgMode_original { run_next_code_bloc = 2; } - info!("checking code bloc delimiter in : {}",l); + info!("checking code bloc delimiter in : {}", l); if l.trim_start().to_lowercase().starts_with("#+begin_src") { if run_next_code_bloc == 0 { continue; } run_next_code_bloc -= 1; - if counter % 2 == 1 { return Err(SniprunError::CustomError(String::from("Incomplete or nested code blocs")))} + if counter % 2 == 1 { + return Err(SniprunError::CustomError(String::from( + "Incomplete or nested code blocs", + ))); + } counter += 1; v.push((selection_line + i + 1, 0)); } @@ -58,7 +62,11 @@ impl OrgMode_original { continue; } run_next_code_bloc -= 1; - if counter % 2 == 0 { return Err(SniprunError::CustomError(String::from("Incomplete or nested code blocs")))} + if counter % 2 == 0 { + return Err(SniprunError::CustomError(String::from( + "Incomplete or nested code blocs", + ))); + } counter += 1; v[((counter - 1) / 2) as usize].1 = selection_line + i - 1; } @@ -71,7 +79,9 @@ impl OrgMode_original { ))); } if v.is_empty() { - return Err(SniprunError::CustomError("No matching tag #+NAME: was found".to_string())); + return Err(SniprunError::CustomError( + "No matching tag #+NAME: was found".to_string(), + )); } info!("running separately ranges : {:?}", v); return Err(SniprunError::ReRunRanges(v)); @@ -81,7 +91,12 @@ impl OrgMode_original { let mut line_n = self.data.range[0]; // no matter which one //first check if we not on boundary of block - if self.data.current_line.trim_start().to_lowercase().starts_with("#+name") + if self + .data + .current_line + .trim_start() + .to_lowercase() + .starts_with("#+name") { let next_line = real_nvim_instance .get_current_buf() @@ -95,9 +110,10 @@ impl OrgMode_original { if self .data .current_line - .trim_start().to_lowercase() + .trim_start() + .to_lowercase() .starts_with("#+begin_src") - { + { let flavor = self .data .current_line @@ -121,8 +137,7 @@ impl OrgMode_original { .get_lines(&mut real_nvim_instance, i - 1, i, false) .unwrap() .join(""); - if line_i.trim_start().to_lowercase().starts_with("#+end_src") - { + if line_i.trim_start().to_lowercase().starts_with("#+end_src") { //found end of bloc self.data.current_bloc = code_bloc.join("\n"); info!( @@ -146,13 +161,12 @@ impl OrgMode_original { .get_lines(&mut real_nvim_instance, i - 1, i, false) .unwrap() .join(""); - if line_i.trim_start().to_lowercase().starts_with("#+begin_src") + if line_i + .trim_start() + .to_lowercase() + .starts_with("#+begin_src") { - let flavor = line_i - .split_whitespace() - .nth(1) - .unwrap_or("") - .to_owned(); + let flavor = line_i.split_whitespace().nth(1).unwrap_or("").to_owned(); return Ok(self.filetype_from_str(&flavor)); } } @@ -268,8 +282,7 @@ impl Interpreter for OrgMode_original { for (i, l) in lines.iter().enumerate() { info!("checking named tag {} in line {}", tag_name, i); if l.trim_start().to_lowercase().starts_with("#name:") - && tag_name.to_lowercase() - == (*l.to_lowercase().replace("#name:", "").trim()) + && tag_name.to_lowercase() == (*l.to_lowercase().replace("#name:", "").trim()) { found = true; info!("found named tag {} in line: {}", tag_name, l); @@ -293,7 +306,7 @@ impl Interpreter for OrgMode_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self .data .current_line diff --git a/src/interpreters/Plantuml_original.rs b/src/interpreters/Plantuml_original.rs index 9528351..78a2a5f 100644 --- a/src/interpreters/Plantuml_original.rs +++ b/src/interpreters/Plantuml_original.rs @@ -137,13 +137,13 @@ impl Interpreter for Plantuml_original { { // if bloc is not pseudo empty and has Bloc current support level, // add fetched code to self - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); // if there is only data on current line / or Line is the max support level } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { // no code was retrieved self.code = String::from(""); diff --git a/src/interpreters/Prolog_original.rs b/src/interpreters/Prolog_original.rs index bb012b4..2da8976 100644 --- a/src/interpreters/Prolog_original.rs +++ b/src/interpreters/Prolog_original.rs @@ -71,11 +71,11 @@ impl Interpreter for Prolog_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 111e2ea..07d306a 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -41,13 +41,17 @@ impl Python3_fifo { // timeout after 30s if no result found if start.elapsed().as_secs() > 30 { - return Err(SniprunError::InterpreterLimitationError(String::from("reached the 30s timeout"))); + return Err(SniprunError::InterpreterLimitationError(String::from( + "reached the 30s timeout", + ))); } // Python3_fifo-specific things to workaround nonblocking plot issues if start.elapsed().as_millis() > 150 { let sync_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/sync_repl.sh"; - let res = Command::new(sync_repl_cmd).arg(self.cache_dir.clone()).output(); + let res = Command::new(sync_repl_cmd) + .arg(self.cache_dir.clone()) + .output(); info!( "had to sync the repl because of timeout on awaiting result:\ happens when a blocking command (plot, infinite loop) is run: {:?}", @@ -138,28 +142,29 @@ impl Python3_fifo { .replace(&[' ', '\t', '\n', '\r'][..], "") .is_empty() { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } let mut in_import_list = false; for line in v.iter().filter(|line| !line.trim().starts_with('#')) { // info!("lines are : {}", line); if in_import_list { self.imports = self.imports.clone() + "\n" + line; - if line.contains(')'){ + if line.contains(')') { in_import_list = false; } continue; } - if line.trim().starts_with("import ") || line.trim().starts_with("from") //basic selection + if line.trim().starts_with("import ") || line.trim().starts_with("from") + //basic selection { - if line.contains('('){ + if line.contains('(') { self.imports = self.imports.clone() + "\n" + line; in_import_list = true; continue; } // embed in try catch blocs in case uneeded module is unavailable - if self.module_used(line, &self.code){ + if self.module_used(line, &self.code) { let already_imported: String = self.read_previous_code(); if !already_imported.contains(line.trim()) { let line = line.trim_start(); @@ -328,11 +333,11 @@ impl Interpreter for Python3_fifo { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -421,9 +426,7 @@ impl ReplLikeInterpreter for Python3_fifo { .output() .unwrap(); - return Err(SniprunError::CustomError( - "python3 REPL exited".to_owned(), - )); + return Err(SniprunError::CustomError("python3 REPL exited".to_owned())); } Ok(Fork::Parent(_)) => {} Err(_) => info!( @@ -470,7 +473,7 @@ impl ReplLikeInterpreter for Python3_fifo { let mut lines = vec![]; for i in 0..(self.code.lines().count() - 1) { let l1 = self.code.lines().nth(i).unwrap(); - let l2 = self.code.lines().nth(i+1).unwrap(); + let l2 = self.code.lines().nth(i + 1).unwrap(); let nw1 = l1.len() - l1.trim_start().len(); let nw2 = l2.len() - l2.trim_start().len(); lines.push(l1); @@ -482,7 +485,6 @@ impl ReplLikeInterpreter for Python3_fifo { self.code = lines.join("\n"); - let mut run_ion = String::new(); let mut run_ioff = String::new(); if self.imports.contains("pyplot") { diff --git a/src/interpreters/Python3_jupyter.rs b/src/interpreters/Python3_jupyter.rs index 90e5f41..caf0240 100644 --- a/src/interpreters/Python3_jupyter.rs +++ b/src/interpreters/Python3_jupyter.rs @@ -44,7 +44,7 @@ impl Python3_jupyter { .replace(&[' ', '\t', '\n', '\r'][..], "") .is_empty() { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } for line in v.iter() { // info!("lines are : {}", line); @@ -101,7 +101,9 @@ impl Python3_jupyter { if let Some(remaining) = timeout.checked_sub(step) { timeout = remaining; } else { - return Err(SniprunError::CustomError(String::from("Timeout on jupyter kernel start expired"))); + return Err(SniprunError::CustomError(String::from( + "Timeout on jupyter kernel start expired", + ))); } } } @@ -178,11 +180,11 @@ impl Interpreter for Python3_jupyter { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -356,9 +358,9 @@ impl ReplLikeInterpreter for Python3_jupyter { strip_ansi_escapes::strip_str(String::from_utf8_lossy(&output.stderr.clone())) .lines() .last() - .unwrap_or( - &strip_ansi_escapes::strip_str(String::from_utf8_lossy(&output.stderr)) - ) + .unwrap_or(&strip_ansi_escapes::strip_str(String::from_utf8_lossy( + &output.stderr, + ))) .to_owned(), )); } diff --git a/src/interpreters/Python3_original.rs b/src/interpreters/Python3_original.rs index c5d0266..fdeb4e6 100644 --- a/src/interpreters/Python3_original.rs +++ b/src/interpreters/Python3_original.rs @@ -45,26 +45,26 @@ impl Python3_original { .replace(&[' ', '\t', '\n', '\r'][..], "") .is_empty() { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } let mut in_import_list = false; for line in v.iter().filter(|line| !line.trim().starts_with('#')) { // info!("lines are : {}", line); if in_import_list { self.imports = self.imports.clone() + "\n" + line; - if line.contains(')'){ + if line.contains(')') { in_import_list = false; } continue; } - if line.trim().starts_with("import ") || line.trim().starts_with("from ") { //basic selection - if line.contains('('){ + if line.trim().starts_with("import ") || line.trim().starts_with("from ") { + //basic selection + if line.contains('(') { self.imports = self.imports.clone() + "\n" + line; in_import_list = true; continue; } - if self.module_used(line, &self.code) - { + if self.module_used(line, &self.code) { // embed in try catch blocs in case uneeded module is unavailable let line = unindent(line); self.imports = self.imports.clone() + "\n" + &line; @@ -217,11 +217,11 @@ impl Interpreter for Python3_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -326,7 +326,7 @@ impl ReplLikeInterpreter for Python3_original { final_code.push(')'); } - self.code = final_code.clone(); + self.code.clone_from(&final_code); // info!("---{}---", &final_code); Ok(()) diff --git a/src/interpreters/R_original.rs b/src/interpreters/R_original.rs index 7bf787f..7110bb0 100644 --- a/src/interpreters/R_original.rs +++ b/src/interpreters/R_original.rs @@ -74,11 +74,11 @@ impl Interpreter for R_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Ruby_original.rs b/src/interpreters/Ruby_original.rs index 1d61562..24a5dd1 100644 --- a/src/interpreters/Ruby_original.rs +++ b/src/interpreters/Ruby_original.rs @@ -71,11 +71,11 @@ impl Interpreter for Ruby_original { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/Rust_original.rs b/src/interpreters/Rust_original.rs index b8363e6..957c1d5 100644 --- a/src/interpreters/Rust_original.rs +++ b/src/interpreters/Rust_original.rs @@ -99,11 +99,11 @@ impl Interpreter for Rust_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } diff --git a/src/interpreters/SQL_original.rs b/src/interpreters/SQL_original.rs index 2fe803a..62ff6ae 100644 --- a/src/interpreters/SQL_original.rs +++ b/src/interpreters/SQL_original.rs @@ -71,11 +71,11 @@ impl Interpreter for SQL_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -110,7 +110,7 @@ impl Interpreter for SQL_original { .arg("-w") .arg("--file") .arg(&self.main_file_path) - .arg(&self.read_previous_code().replace('\n',"")) // contains database address + .arg(&self.read_previous_code().replace('\n', "")) // contains database address .current_dir(&self.data.projectroot) .output() .expect("Unable to start process"); diff --git a/src/interpreters/Sage_fifo.rs b/src/interpreters/Sage_fifo.rs index f4595fd..27d4e04 100644 --- a/src/interpreters/Sage_fifo.rs +++ b/src/interpreters/Sage_fifo.rs @@ -106,7 +106,7 @@ impl Sage_fifo { for try_error_indicator in error_indicators.iter() { if out_contents_current.contains(try_error_indicator) { info!("stdout contains error indicator"); - err_contents = out_contents.clone(); + err_contents.clone_from(&out_contents); // info!("file : {:?}", contents); err_contents = err_contents.replace("sage: ", ""); err_contents = err_contents.replace("---------------------------------------------------------------------------\n",""); @@ -167,7 +167,7 @@ impl Sage_fifo { .replace(&[' ', '\t', '\n', '\r'][..], "") .is_empty() { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } for line in v.iter() { // info!("lines are : {}", line); @@ -311,11 +311,11 @@ impl Interpreter for Sage_fifo { .is_empty() && self.get_current_level() >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.get_current_level() >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { self.code = String::from(""); } @@ -386,9 +386,7 @@ impl ReplLikeInterpreter for Sage_fifo { .output() .unwrap(); - return Err(SniprunError::CustomError( - "sage REPL exited".to_owned(), - )); + return Err(SniprunError::CustomError("sage REPL exited".to_owned())); } Ok(Fork::Parent(_)) => {} Err(_) => { diff --git a/src/interpreters/Scala_original.rs b/src/interpreters/Scala_original.rs index 48b7187..6759208 100644 --- a/src/interpreters/Scala_original.rs +++ b/src/interpreters/Scala_original.rs @@ -78,13 +78,13 @@ impl Interpreter for Scala_original { { // if bloc is not pseudo empty and has Bloc current support level, // add fetched code to self - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); // if there is only data on current line / or Line is the max support level } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { // no code was retrieved self.code = String::from(""); diff --git a/src/interpreters/TypeScript_original.rs b/src/interpreters/TypeScript_original.rs index 946af8f..519e703 100644 --- a/src/interpreters/TypeScript_original.rs +++ b/src/interpreters/TypeScript_original.rs @@ -81,11 +81,11 @@ impl Interpreter for TypeScript_original { .is_empty() && self.support_level >= SupportLevel::Bloc { - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); } else if !self.data.current_line.replace(' ', "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { // no code was retrieved self.code = String::from(""); diff --git a/src/interpreters/example.rs b/src/interpreters/example.rs index 9342240..cb76a73 100644 --- a/src/interpreters/example.rs +++ b/src/interpreters/example.rs @@ -94,13 +94,13 @@ impl Interpreter for Language_subname { { // if bloc is not pseudo empty and has Bloc current support level, // add fetched code to self - self.code = self.data.current_bloc.clone(); + self.code.clone_from(&self.data.current_bloc); // if there is only data on current line / or Line is the max support level } else if !self.data.current_line.replace(" ", "").is_empty() && self.support_level >= SupportLevel::Line { - self.code = self.data.current_line.clone(); + self.code.clone_from(&self.data.current_line); } else { // no code was retrieved self.code = String::from(""); diff --git a/src/interpreters/import.rs b/src/interpreters/import.rs index 9775943..18969ff 100644 --- a/src/interpreters/import.rs +++ b/src/interpreters/import.rs @@ -1,7 +1,9 @@ pub use crate::error::SniprunError; -pub use crate::interpreter::{Interpreter, InterpreterUtils, ReplLikeInterpreter, SupportLevel, ErrTruncate}; +pub use crate::interpreter::{ + ErrTruncate, Interpreter, InterpreterUtils, ReplLikeInterpreter, SupportLevel, +}; pub use crate::DataHolder; -pub use log::{info,warn,error, debug}; +pub use log::{debug, error, info, warn}; pub use crate::interpreters; pub use crate::iter_types; @@ -9,12 +11,11 @@ pub use crate::iter_types; pub use std::fs::{write, DirBuilder, File}; pub use std::process::Command; - pub use neovim_lib::NeovimApi; pub use std::env; -pub use crate::daemonizer::{daemon,Fork}; +pub use crate::daemonizer::{daemon, Fork}; //indentation pub use unindent::unindent; diff --git a/src/lib.rs b/src/lib.rs index 7e9e4db..4c6c499 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,8 @@ use std::thread; pub mod daemonizer; pub mod display; -pub mod input; pub mod error; +pub mod input; pub mod interpreter; pub mod interpreters; pub mod launcher; From ad793862f4c46df21e53836e27815789abb140de Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 27 Jul 2024 17:14:00 +0200 Subject: [PATCH 10/12] format documentation --- doc/sources/README.md | 22 +++---- doc/sources/interpreters/Ada_original.md | 7 ++- doc/sources/interpreters/Bash_original.md | 8 ++- doc/sources/interpreters/CSharp_original.md | 5 +- doc/sources/interpreters/C_original.md | 20 +++++-- doc/sources/interpreters/Clojure_fifo.md | 17 +++--- doc/sources/interpreters/Cpp_original.md | 9 ++- doc/sources/interpreters/FSharp_fifo.md | 37 ++++++------ doc/sources/interpreters/GFM_original.md | 19 +++--- doc/sources/interpreters/Generic.md | 18 +++--- doc/sources/interpreters/Go_original.md | 4 +- doc/sources/interpreters/Http_original.md | 3 +- doc/sources/interpreters/JS_TS_bun.md | 5 +- doc/sources/interpreters/JS_TS_deno.md | 3 +- doc/sources/interpreters/Java_original.md | 3 +- doc/sources/interpreters/Julia_jupyter.md | 9 ++- doc/sources/interpreters/Julia_original.md | 5 +- doc/sources/interpreters/Lua_nvim.md | 18 ++---- doc/sources/interpreters/Lua_original.md | 1 + .../interpreters/Mathematica_original.md | 57 +++++++++--------- doc/sources/interpreters/Neorg_original.md | 30 +++++----- doc/sources/interpreters/OCaml_fifo.md | 6 +- doc/sources/interpreters/OrgMode_original.md | 14 ++--- doc/sources/interpreters/Plantuml_original.md | 1 + doc/sources/interpreters/Prolog_original.md | 7 +-- doc/sources/interpreters/Python3_fifo.md | 15 ++--- doc/sources/interpreters/Python3_jupyter.md | 58 ++++++------------- doc/sources/interpreters/Python3_original.md | 32 ++++++---- doc/sources/interpreters/R_original.md | 2 - doc/sources/interpreters/Ruby_original.md | 2 - doc/sources/interpreters/Rust_original.md | 2 - doc/sources/interpreters/Sage_fifo.md | 16 ++--- .../interpreters/TypeScript_original.md | 1 - 33 files changed, 229 insertions(+), 227 deletions(-) diff --git a/doc/sources/README.md b/doc/sources/README.md index 5d32ec7..3b5f8c3 100755 --- a/doc/sources/README.md +++ b/doc/sources/README.md @@ -1,10 +1,13 @@ # Introduction -Sniprun is a code runner plugin for neovim written in Lua and Rust. It aims to provide stupidly fast partial code testing for interpreted **and compiled** {ref}`languages `. Sniprun blurs the line between standard save/run workflow, jupyter-like notebook, and REPL/interpreters. +Sniprun is a code runner plugin for neovim written in Lua and Rust. It aims to +provide stupidly fast partial code testing for interpreted **and compiled** +{ref}`languages `. Sniprun blurs the line +between standard save/run workflow, jupyter-like notebooks, +and REPL/interpreters. - - -I know that this README is exhaustively long, but Sniprun itself is and will remain rather simple: don't be afraid, questions are welcome too. +I know that this README is exhaustively long, but Sniprun itself is and will +remain rather simple: don't be afraid, questions are welcome too. ## Demos @@ -13,7 +16,7 @@ A few lines of code are now within a print statement's reach :-) ([this may be c An example in C, look in the command area: -![](../../ressources/visual_assets/demo_c.gif) +![demo_c](../../ressources/visual_assets/demo_c.gif) **The result can be returned in multiple (even at the same time) ways:** @@ -28,11 +31,12 @@ An example in C, look in the command area: **send-to-REPL-like behavior is available for some languages** -Python, R, D, Mathematica, Sage, Julia, Javascript & Typescript (via deno), Clojure and Lua, coming soon for many other interpreted and compiled languages. Very versatile, you can even run things like GUI plots on the fly! +Python, R, D, Mathematica, Sage, Julia, Javascript & Typescript (via deno), +Clojure and Lua, coming soon for many other interpreted and compiled languages. +Very versatile, you can even run things like GUI plots on the fly! ![](../../ressources/visual_assets/demo_repl.png) - # What does it do ? Basically, it allows you to run a part of your code. @@ -48,7 +52,6 @@ Do either of: and ... that's it! - Sniprun will then: - **Get the code** you selected (selections are rounded line-wise) @@ -58,9 +61,6 @@ Sniprun will then: - **Execute** the code, or send it to an active REPL for evaluation - Display stdout, or stderr using the chosen method - - - # What it is && isn't **It is** a way to quickly run small snippets of code, on the fly, and iterate very quickly and conveniently. To quickly experiment with new features (not yet embedded in classes, a whole project etc...), or to develop simple code pipelines (like a machine learning exercise) that fit in a unique file, sniprun is probably _the_ best plugin out there. diff --git a/doc/sources/interpreters/Ada_original.md b/doc/sources/interpreters/Ada_original.md index afc9758..2a22f68 100644 --- a/doc/sources/interpreters/Ada_original.md +++ b/doc/sources/interpreters/Ada_original.md @@ -1,11 +1,12 @@ ## Ada original - dependencies: Need `gcc-ada` and `gnatmake` -Note: because Ada needs variables to be declared before the begin (in a non contiguous section of the file), SnipRun is not very useful here and will, in practice, only be able to run blocs like +Note: because Ada needs variables to be declared before the begin +(in a non contiguous section of the file), SnipRun is not very useful +here and will, in practice, only be able to run blocs like -``` +```ada Put_Line("raw text"); ``` diff --git a/doc/sources/interpreters/Bash_original.md b/doc/sources/interpreters/Bash_original.md index 469758b..850aa38 100644 --- a/doc/sources/interpreters/Bash_original.md +++ b/doc/sources/interpreters/Bash_original.md @@ -1,7 +1,9 @@ ## Bash original -Beware of Bash_original, as it runs as script on your system, with access to your ENV variables and PATH etc... +Beware of Bash_original, as it runs as script on your system, +with access to your ENV variables and PATH etc... -remove a file from absolute path will succeed! +removing a file from absolute path will succeed! -REPL mode has also many quirks (not a true repl, will rerun previously sniprun'd commands). Overall I strongly suggest _not_ using it +REPL mode has also many quirks (not a true repl, will rerun +previously sniprun'd commands). Overall I strongly suggest _not_ using it diff --git a/doc/sources/interpreters/CSharp_original.md b/doc/sources/interpreters/CSharp_original.md index 0e1a703..cd9ba54 100644 --- a/doc/sources/interpreters/CSharp_original.md +++ b/doc/sources/interpreters/CSharp_original.md @@ -1,6 +1,7 @@ ## C# original -This interpreter require the `mono` toolbox to be installed: `csc` and `mono` must be in your $PATH +This interpreter require the `mono` toolbox to be installed: +`csc` and `mono` must be in your $PATH a custom compiler can be specified : @@ -14,5 +15,3 @@ require'sniprun'.setup({ } }) ``` - - diff --git a/doc/sources/interpreters/C_original.md b/doc/sources/interpreters/C_original.md index 7ecbee7..dca13e5 100644 --- a/doc/sources/interpreters/C_original.md +++ b/doc/sources/interpreters/C_original.md @@ -1,7 +1,7 @@ ## C original -`gcc` is recommended, for that it's able to detect, compile and run nested functions, however you can change the default compiler with: - +`gcc` is recommended, for that it's able to detect, compile and run nested +functions, however you can change the default compiler with: ```lua require'sniprun'.setup({ @@ -14,9 +14,15 @@ require'sniprun'.setup({ }) ``` -If you run with GCC, Sniprun will be able to run function + code in the same snippet, or functions + main() function regardlessly, but only the latter is supported by `clang`. +If you run with GCC, Sniprun will be able to run function + code in the +same snippet, or functions + main() function regardlessly, but only the +latter is supported by `clang`. -This interpreter will also only import (all) #include \<...> but not any #include "..." (systems-wide include only, not the headers from your project, unless the environment variable `$C_INCLUDE_PATH` or `$CPLUS_INCLUDE_PATH` have been set). In this case, please make sure those variable cover **ALL** the paths needed to fetch every header file `#include`'d +This interpreter will also only import (all) #include \<...> but not +any #include "..." (systems-wide include only, not the headers from your +project, unless the environment variable `$C_INCLUDE_PATH` or +`$CPLUS_INCLUDE_PATH` have been set). In this case, please make sure those +variable cover **ALL** the paths needed to fetch every header file `#include`'d the C\_original interpreter will also make use of the following environment variables: @@ -27,7 +33,9 @@ the C\_original interpreter will also make use of the following environment vari - `$CFLAGS` -and will add them to the build options it uses. Please specify _absolute paths_, and not relative ones! +and will add them to the build options it uses. +Please specify _absolute paths_, and not relative ones! -Using a tool such as [direnv](https://direnv.net/) may be really useful to set up those variables when you `cd` into your project' directory. +Using a tool such as [direnv](https://direnv.net/) may be really useful +to set up those variables when you `cd` into your project' directory. diff --git a/doc/sources/interpreters/Clojure_fifo.md b/doc/sources/interpreters/Clojure_fifo.md index 7077b87..4b92607 100644 --- a/doc/sources/interpreters/Clojure_fifo.md +++ b/doc/sources/interpreters/Clojure_fifo.md @@ -2,9 +2,9 @@ This interpreter relies on `clojure` - -The default interpreter command is `clojure` (or `clojure -e "(clojure.main/repl :prompt (defn f[] ("")) )"`, that allow not displaying the repl prompt) but it can be changed via the configuration key - +The default interpreter command is `clojure` +(or `clojure -e "(clojure.main/repl :prompt (defn f[] ("")) )"`, that allow +not displaying the repl prompt) but it can be changed via the configuration key The defaults are equivalent to specifying: @@ -19,12 +19,13 @@ require'sniprun'.setup({ } }) ``` -You can change those values, (to use `clj` for example ?) but it could break sniprun anytime - +You can change those values, (to use `clj` for example ?) +but it could break sniprun anytime ### Blocked REPL -Clojure is a bit capricious and sometimes a typo will block forever (and a timeout will appear after 30s). - -Don't hesitate to `SnipReset`, even though it will lose all the currently in-memory variables +Clojure is a bit capricious and sometimes a typo will block forever +(and a timeout will appear after 30s). +Don't hesitate to `SnipReset`, even though it will lose all +the currently in-memory variables... diff --git a/doc/sources/interpreters/Cpp_original.md b/doc/sources/interpreters/Cpp_original.md index d561200..d4178d9 100644 --- a/doc/sources/interpreters/Cpp_original.md +++ b/doc/sources/interpreters/Cpp_original.md @@ -2,8 +2,13 @@ Limitations - - Will only look and load external imports (include) that are SYSTEM import; as sniprun does not have any way to differentiate between #include "math.h" (the system library) and #include "math2.h" (your custom header), it will NOT look for #include "....", but only #include \<....> (those are restricted to system libraries). - - Need `g++` (or specify another compiler in configuration) +- Will only look and load external imports (include) that are SYSTEM import; + as sniprun does not have any way to differentiate between #include "math.h" + (the system library) and #include "math2.h" (your custom header), + it will NOT look for #include "....", but only #include \<....> + (those are restricted to system libraries). + +- Need `g++` (or specify another compiler in configuration) ```lua require'sniprun'.setup({ diff --git a/doc/sources/interpreters/FSharp_fifo.md b/doc/sources/interpreters/FSharp_fifo.md index 36089ae..b38c829 100644 --- a/doc/sources/interpreters/FSharp_fifo.md +++ b/doc/sources/interpreters/FSharp_fifo.md @@ -2,9 +2,8 @@ ### This interpreter relies on dotnet fsi being available and on your path - -The default interpreter command is `dotnet fsi --nologo` but it can be changed via the configuration key - +The default interpreter command is `dotnet fsi --nologo` but it +can be changed via the configuration key ```lua require'sniprun'.setup({ @@ -17,18 +16,17 @@ require'sniprun'.setup({ }) ``` - ### REPL (would solve slowness issues) For now, REPL is broken due to dotnet fsi being capricious about its stdin. -I'll explain rapidly how sniprun implement a REPL interpreter around named pipes (FIFOs). +I'll explain rapidly how sniprun implements a REPL interpreter +around named pipes (FIFOs). -The first time a fifo-based interpreter receive a run command, it forks to the background and executes `ressources/init_repl.sh`. +The first time a fifo-based interpreter receive a run command, +it forks to the background and executes `ressources/init_repl.sh`. There is a lot of thing in that script but to replicate, you just have to: - - - `mkfifo pipe_in` - create a launcher script: @@ -40,24 +38,29 @@ cat pipe_in | dotnet fsi # or replace 'dotnet fsi' by whatever you cant to try ``` -- launch it in the background: `bash ./launcher.sh &`, (or `bash ./launcher.sh > out.txt & ` to redirect stdout to out.txt like sniprun does) +- launch it in the background: `bash ./launcher.sh &`, + (or `bash ./launcher.sh > out.txt & ` to redirect stdout to out.txt like sniprun does) -- ensure the pipe will stay open: `sleep 3600 > pipe_in &` (cat, exec 3> variations will also work) +- ensure the pipe will stay open: `sleep 3600 > pipe_in &` + (cat, exec 3> variations will also work) - `echo "printfn \" hey \" " > pipe_in` or `cat hello_world.fsx > pipe_in` -- normally, the result should be printed in the terminal that ran the launcher, or in the out file. - - - +- normally, the result should be printed in the terminal that ran + the launcher, or in the out file. #### The issue: -right now, dotnet fsi looks like it's blocked by the first sleep > pipe_in... but something **has** to keep the pipe open or when it closes, the fsi REPL reading from that will exit. +right now, dotnet fsi looks like it's blocked by the first sleep > pipe_in... +but something **has** to keep the pipe open or when it closes, the fsi REPL +reading from that will exit. I suspect the thing has something to do with interactive mode. -For example, `python` has a similar problem, but `python -i ` (forced interactive mode, even if no terminal is detected because it runs in the background / its stdin was hijacked) works fine in the above example. +For example, `python` has a similar problem, but `python -i ` +(forced interactive mode, even if no terminal is detected because it +runs in the background / its stdin was hijacked) works fine in the above example -If you find something to replace dotnet fsi with, that exhibits the same correct behavior as `python -i`, sniprun REPL mode _should_ work. +If you find something to replace dotnet fsi with, that exhibits the same +correct behavior as `python -i`, sniprun REPL mode _should_ work. diff --git a/doc/sources/interpreters/GFM_original.md b/doc/sources/interpreters/GFM_original.md index 1d5bc0c..7e78294 100644 --- a/doc/sources/interpreters/GFM_original.md +++ b/doc/sources/interpreters/GFM_original.md @@ -4,13 +4,10 @@ the GFM_original (Github flavored markdown) can help run code blocs embedded in ### example 1 - \```bash echo "lol" # << you can run sniprun on this line - - \# or the whole visual selection following: for i in {1..4};do @@ -31,10 +28,11 @@ println!("test"); \``` +**the language name must be there (otherwise the default * will be used) at the +bloc start** and has to match the github flavor syntax, and the underlying +interpreter must be callable (no missing compiler etc...) -**the language name must be there (otherwise the default * will be used) at the bloc start** and has to match the github flavor syntax, and the underlying interpreter must be callable (no missing compiler etc...) - -\* python, but you can ofc configure that: +\* python, but you can ofc configure that: ```lua require'sniprun'.setup({ @@ -46,9 +44,6 @@ require'sniprun'.setup({ }) ``` - -if GFM doesn't include a flavor that matches the language you want, well it's not really GFM anymore but you can but the filetype of the language you want, such as julia or lua - - - - +if GFM doesn't include a flavor that matches the language you want, well it's +not really GFM anymore but you can but the filetype of the language you want, +such as julia or lua diff --git a/doc/sources/interpreters/Generic.md b/doc/sources/interpreters/Generic.md index a74fc24..1aa32f8 100644 --- a/doc/sources/interpreters/Generic.md +++ b/doc/sources/interpreters/Generic.md @@ -1,8 +1,10 @@ ## Generic -This interpreter allows you to support virtually any language, provided it's not too strange, at up to bloc-level +This interpreter allows you to support virtually any language, +provided it's not too strange, at up to bloc-level -If you're trying to override an already-supported language, add Generic to the list of selected interpreters: +If you're trying to override an already-supported language, +add Generic to the list of selected interpreters: ```lua @@ -10,10 +12,8 @@ require'sniprun'.setup({ selected_interpreters = { 'Generic' }, }) ``` - to add support for, let's say, python2 - ```lua require'sniprun'.setup({ interpreter_options = { @@ -34,7 +34,6 @@ require'sniprun'.setup({ to also add support for, let's suppose it wasn't officially supported, C - ```lua require'sniprun'.setup({ interpreter_options = { @@ -84,11 +83,12 @@ require'sniprun'.setup({ 1. Sniprun receive a snippet of code to run 2. The snippet gets surrounded by boilerplate_pre and boilerplate_post -3. The whole thing is written to a temporary file with the given extension, named `_src.` -4. Sniprun runs ` _src.` , and if this has a non-success status, displays the stderr +3. The whole thing is written to a temporary file with the given extension, + named `_src.` +4. Sniprun runs ` _src.` , and if this has a + non-success status, displays the stderr 5. Sniprun runs `./` and displays the stdout/stderr - ### Community examples for non-officially supported languages -(contribute here: doc/sources/interpreters/Generic.md) +(contribute on github to the file: doc/sources/interpreters/Generic.md) diff --git a/doc/sources/interpreters/Go_original.md b/doc/sources/interpreters/Go_original.md index 8915336..9b466eb 100644 --- a/doc/sources/interpreters/Go_original.md +++ b/doc/sources/interpreters/Go_original.md @@ -1,5 +1,6 @@ ## Go original -the executable (`go` , `llgo` or whatever) executable used to _build_ the snippet can be configured via +the executable (`go` , `llgo` or whatever) executable used to +_build_ the snippet can be configured via ```lua @@ -13,4 +14,3 @@ require'sniprun'.setup({ }) ``` - diff --git a/doc/sources/interpreters/Http_original.md b/doc/sources/interpreters/Http_original.md index 3ab93df..49c74b8 100644 --- a/doc/sources/interpreters/Http_original.md +++ b/doc/sources/interpreters/Http_original.md @@ -1,5 +1,6 @@ ## Http original -This interpreter does not have any requirements, as it relies on the (embedded) Rust library [ureq](https://crates.io/crates/ureq/) +This interpreter does not have any requirements, as +it relies on the (embedded) Rust library [ureq](https://crates.io/crates/ureq/) It works on filetypes 'http' and 'rest'. diff --git a/doc/sources/interpreters/JS_TS_bun.md b/doc/sources/interpreters/JS_TS_bun.md index 1d754b4..56ac4dd 100644 --- a/doc/sources/interpreters/JS_TS_bun.md +++ b/doc/sources/interpreters/JS_TS_bun.md @@ -4,11 +4,11 @@ A REPL-capable (not enabled by default) Typescript / Javascript interpreter. `bun` needs to be installed and on your path. - ### JS_TS_bun is REPL-capable But the REPL is VERY quirky (and even has a greeting saying it's unstable) -It doesn't play well at all with sniprun's stdin-stdout mechanism, so while basic examples are working, +It doesn't play well at all with sniprun's stdin-stdout +mechanism, so while basic examples are working, I can't consider this a 'daily driver'... so REPL is disabled by default ```lua @@ -18,7 +18,6 @@ require('sniprun').setup({ }) ``` - ### more option for the (non-repl) command line sniprun runs your code snippets with diff --git a/doc/sources/interpreters/JS_TS_deno.md b/doc/sources/interpreters/JS_TS_deno.md index 76ff671..441f23c 100644 --- a/doc/sources/interpreters/JS_TS_deno.md +++ b/doc/sources/interpreters/JS_TS_deno.md @@ -2,7 +2,8 @@ A REPL-capable (not enabled by default) Typescript / Javascript interpreter. -`deno` needs to be installed and on your path (and working). The precise command used by sniprun is `deno repl -q` +`deno` needs to be installed and on your path (and working). +The precise command used by sniprun is `deno repl -q` ```lua require('sniprun').setup({ diff --git a/doc/sources/interpreters/Java_original.md b/doc/sources/interpreters/Java_original.md index 6e25608..fa4f6d2 100644 --- a/doc/sources/interpreters/Java_original.md +++ b/doc/sources/interpreters/Java_original.md @@ -1,3 +1,4 @@ ## Java original -no special conf is needed, besides having a functionnal `javac` compiler present on the $PATH +no special conf is needed, besides having a functionnal +`javac` compiler present on the $PATH diff --git a/doc/sources/interpreters/Julia_jupyter.md b/doc/sources/interpreters/Julia_jupyter.md index 61faf87..e3c70e1 100644 --- a/doc/sources/interpreters/Julia_jupyter.md +++ b/doc/sources/interpreters/Julia_jupyter.md @@ -2,13 +2,16 @@ The setup for the julia_jupyter interpreter is quite convoluted: -Indeed, the Julia jupyter kernel MUST be started before Sniprun can run (and there is even a consequent delay since the kernel is so slow to start). +Indeed, the Julia jupyter kernel MUST be started before Sniprun can run +(and there is even a consequent delay since the kernel is so slow to start). You should start a julia jupyter kernel with the following command: ` jupyter-kernel --kernel=julia-1.5 --KernelManager.connection_file=$HOME/.cache/sniprun/julia_jupyter/kernel_sniprun.json` (adapt to your XDG_CACHE location if you're on Mac) -You manage kernel startup AND shutdown manually. Why? There is a terrible data race if sniprun does it. Python_jupyter works, julia doesn't. That's life. +You manage kernel startup AND shutdown manually. Why? There is a terrible +data race if sniprun does it. Python_jupyter works, julia doesn't. That's life. -If you want to use another kernel location, post a feature request at github.com/michaelb/sniprun and I'll see what I can do. +If you want to use another kernel location, post a feature request at +github.com/michaelb/sniprun and I'll see what I can do. diff --git a/doc/sources/interpreters/Julia_original.md b/doc/sources/interpreters/Julia_original.md index 8f8d081..8019413 100644 --- a/doc/sources/interpreters/Julia_original.md +++ b/doc/sources/interpreters/Julia_original.md @@ -9,7 +9,10 @@ require'sniprun'.setup({ repl_enable = {'Julia_original'}, }) ``` -Julia_original supports several interpreter options, such as the interpreter executable (absolute path or command in PATH, by default "julia"), and the 'project' (will be passed as --project=... to the executed command) + +Julia_original supports several interpreter options, such as the interpreter +executable (absolute path or command in PATH, by default "julia"), and the +'project' (will be passed as --project=... to the executed command) ```lua require('sniprun').setup({ diff --git a/doc/sources/interpreters/Lua_nvim.md b/doc/sources/interpreters/Lua_nvim.md index dba5c3f..d37dfbe 100644 --- a/doc/sources/interpreters/Lua_nvim.md +++ b/doc/sources/interpreters/Lua_nvim.md @@ -1,10 +1,13 @@ ## Lua_nvim -This interpreter works inherently in a pseudo-REPL mode and this can't be disabled. However, it is run within neovim so you can expect the usual vim API functions to be available. +This interpreter works inherently in a pseudo-REPL mode and this can't +be disabled. However, it is run within neovim so you can expect the +usual vim API functions to be available. -Essentially, you can expect REPL behavior when running line-by-line of bloc-by-bloc lua script: +Essentially, you can expect REPL behavior when running line-by-line +of bloc-by-bloc lua script: -``` +```lua a = 4 b = 6 print(a+5) -- <- 9 @@ -13,12 +16,3 @@ a = 0 print(a + b) -- <- 6 ``` - -HOWEVER, if you define a 'local' variable, it won't be available in subsequent calls - -``` -local a = 5 - -print(a) -- <- nil -``` - diff --git a/doc/sources/interpreters/Lua_original.md b/doc/sources/interpreters/Lua_original.md index 6fa620c..903662f 100644 --- a/doc/sources/interpreters/Lua_original.md +++ b/doc/sources/interpreters/Lua_original.md @@ -3,6 +3,7 @@ Limitation/feature IF + - your code selection contains "nvim' or "vim", even in comments, - you haven't explicitely selected Lua_original - your code snippet fails diff --git a/doc/sources/interpreters/Mathematica_original.md b/doc/sources/interpreters/Mathematica_original.md index fab9067..3257878 100644 --- a/doc/sources/interpreters/Mathematica_original.md +++ b/doc/sources/interpreters/Mathematica_original.md @@ -17,13 +17,11 @@ lua require'sniprun'.setup({ }) ``` - - - - ### Enabling graphics -You can specify whether the ``< CreateDialog]` -If your selection contains a Plot (or matching pattern), in non-REPL mode Mathematica_original will never return (in order to keep the graph window open), this means other statements will not return output. - -As a general rule of thumb, in non-REPL mode, either sniprun a Plot _or_ normal statements - - +If your selection contains a Plot (or matching pattern), in non-REPL mode +Mathematica_original will never return (in order to keep the graph window open), +this means other statements will not return output. +As a general rule of thumb, in non-REPL mode, +either sniprun a Plot _or_ normal statements ### Print on each sniprun (non-REPL only!) -To make the experience more notebook/REPL -like, those options (incompatible with the true REPL mode) can be configured. +To make the experience more notebook/REPL -like, those options +(incompatible with the true REPL mode) can be configured. -They will wrap any/the last line, if they dont contain alread a Print, Plot or end with ";" or and open bracket +They will wrap any/the last line, if they dont contain alread a +Print, Plot or end with ";" or and open bracket -!! WARNING !! This can lead to dangerous side-effects, mathematica contains very little documentation about this. -To feel safe, you wouldn't use these unless you only execute code line-by-line. It may or may not work with blocs. +!! WARNING !! This can lead to dangerous side-effects, mathematica contains +very little documentation about this. To feel safe, you wouldn't use these +unless you only execute code line-by-line. It may or may not work with blocs. ```lua lua require'sniprun'.setup({ @@ -69,26 +70,30 @@ lua require'sniprun'.setup({ }) ``` - - - ### Quirks of REPL-mode -Enabling REPL for mathematica will launch a WolframKernel instance in the background. This session will close when the last neovim instance quits, but is only usable by one neovim instance. -I hope you only need to sniprun mathematica snippets in one neovim instance, because anything else will probably crash. - -In REPL-mode, your first SnipRun command of the neovim instance is used to start the REPL kernel, and the selection is discarded. You'll have to re-run it, sorry, but that's the only way for now. - -In REPL-mode, just like in the normal interpreter, suffix your expressions with ';' if you don't want them to output something. I strongly recommend to suffix Plots with ';' +Enabling REPL for mathematica will launch a WolframKernel instance in the +background. This session will close when the last neovim instance quits, +but is only usable by one neovim instance. +I hope you only need to sniprun mathematica snippets in one neovim instance, +because anything else will probably crash. +In REPL-mode, your first SnipRun command of the neovim instance is used to start +the REPL kernel, and the selection is discarded. You'll have to re-run it, +sorry, but that's the only way for now. +In REPL-mode, just like in the normal interpreter, suffix your expressions with ';' +if you don't want them to output something. +I strongly recommend to suffix Plots with ';' ### Troubleshooting - No valid password found - - For some reason, WolframKernel doesn't like being launched in the background if there is arleady a WolframKernel instance running. You can close your own, or `killall -9 WolframKernel` to kill all the WolframKernel still running, and re-open neovim. This will _also_ close the kernels you've launched yourself! - - +- For some reason, WolframKernel doesn't like being launched in the + background if there is already a WolframKernel instance running. + You can close your own, or `killall -9 WolframKernel` to kill all the + WolframKernel still running, and re-open neovim. + This will _also_ close the kernels you've launched yourself! diff --git a/doc/sources/interpreters/Neorg_original.md b/doc/sources/interpreters/Neorg_original.md index a11ec98..7a03b72 100644 --- a/doc/sources/interpreters/Neorg_original.md +++ b/doc/sources/interpreters/Neorg_original.md @@ -1,13 +1,12 @@ ## Neorg original -the Neorg\_original interpreter helps you running code blocs defined in neorg code blocs delimiters +the Neorg\_original interpreter helps you running code +blocs defined in neorg code blocs delimiters inline, switches and headers are not supported/ignored ### example 1 - - -``` +```neorg #name demo @code bash @@ -26,11 +25,9 @@ done ``` - ### example 2 - -``` +```neorg #name demo_run_whole_bloc << running on this line or the line below will run the entire bloc @code rust @@ -40,9 +37,11 @@ println!("test2"); ``` -Even though it is possible to have empty lines in between the #name tag and the @code block for this plugin this doesn't work. The #name has to be in the line directly above the @code block +Even though it is possible to have empty lines in between the #name tag and +the @code block for this plugin this doesn't work. The #name has to be +in the line directly above the @code block -``` +```neorg #name name_tag_not_working << this #name tag doesn't run the code below @@ -54,12 +53,12 @@ println!("test2"); ``` +**the language name must be there (otherwise the default * will be used) at +the bloc start** and has to match the language name or the filetype associated -**the language name must be there (otherwise the default * will be used) at the bloc start** and has to match the language name or the filetype associated - -\* python, but you can ofc configure that: +\* python, but you can ofc configure that: -``` +```lua require'sniprun'.setup({ interpreter_options = { Neorg_original = { @@ -71,13 +70,14 @@ require'sniprun'.setup({ ### example 3: running named code blocs -``` +```neorg #name mycodebloc @code rust println!("test"); @end ``` -running `:%SnipRun mycodebloc` will run this code bloc (and any code bloc named similarly, case-insensitively) +running `:%SnipRun mycodebloc` will run this code bloc +(and any code bloc named similarly, case-insensitively) running `:%SnipRun` without any further arguments will run all the code blocs diff --git a/doc/sources/interpreters/OCaml_fifo.md b/doc/sources/interpreters/OCaml_fifo.md index 67a3aed..276edbc 100644 --- a/doc/sources/interpreters/OCaml_fifo.md +++ b/doc/sources/interpreters/OCaml_fifo.md @@ -1,10 +1,10 @@ ## OCaml fifo -This interpreter relies on `ocaml` by default, but has been confirmed to work with `utop` in normal (non-REPL) mode. +This interpreter relies on `ocaml` by default, but has been +confirmed to work with `utop` in normal (non-REPL) mode. +The default interpreter can be changed relatively safely for non-REPL mode: - -The default interpreter can be changed relatively safely for normal (non-REPL) mode: ```lua require'sniprun'.setup({ interpreter_options = { diff --git a/doc/sources/interpreters/OrgMode_original.md b/doc/sources/interpreters/OrgMode_original.md index acf81c5..2dd146d 100644 --- a/doc/sources/interpreters/OrgMode_original.md +++ b/doc/sources/interpreters/OrgMode_original.md @@ -1,13 +1,13 @@ ## Orgmode original -the Orgmode\_original interpreter helps you running code blocs defined in org code blocs delimiters +the Orgmode\_original interpreter helps you running code blocs +defined in org code blocs delimiters inline, switches and headers are not supported/ignored ### example 1 - -``` +```orgmode #+NAME: demo #+BEGIN_SRC bash @@ -30,14 +30,13 @@ done ### example 2 -``` +```orgmode #+NAME: demo_run_whole_bloc #+BEGIN_SRC rust << running on this line will run the entire bloc println!("test"); println!("test2"); #+END_SRC - ``` @@ -45,7 +44,7 @@ println!("test2"); \* python, but you can ofc configure that: -``` +```orgmode require'sniprun'.setup({ interpreter_options = { OrgMode_original = { @@ -64,6 +63,7 @@ println!("test"); #+END_SRC ``` -running `:%SnipRun mycodebloc` will run this code bloc (and any code bloc named similarly, case-insensitively) +running `:%SnipRun mycodebloc` will run this code bloc +(and any code bloc named similarly, case-insensitively) running `:%SnipRun` without any further arguments will run all the code blocs diff --git a/doc/sources/interpreters/Plantuml_original.md b/doc/sources/interpreters/Plantuml_original.md index 6bcd212..e9323ac 100644 --- a/doc/sources/interpreters/Plantuml_original.md +++ b/doc/sources/interpreters/Plantuml_original.md @@ -15,6 +15,7 @@ require'sniprun'.setup({ } }) ``` + You can add options to the 'compiler' key, but do not set "-pipe" (or it'll break output), and "-failfast2", "-nbthread auto" are already set. diff --git a/doc/sources/interpreters/Prolog_original.md b/doc/sources/interpreters/Prolog_original.md index 0339747..1842ab0 100644 --- a/doc/sources/interpreters/Prolog_original.md +++ b/doc/sources/interpreters/Prolog_original.md @@ -2,12 +2,12 @@ This interpreter is currently a work in progress and is probably not usable -The Prolog interpreter supports setting a different compiler/interpreter for prolog such as swi ('swipl') +The Prolog interpreter supports setting a different +compiler/interpreter for prolog such as swi ('swipl') you can set it with the following key: - -``` +```lua require'sniprun'.setup({ interpreter_options = { Prolog_original = { interpreter = "swipl" } @@ -15,4 +15,3 @@ require'sniprun'.setup({ } }) ``` - diff --git a/doc/sources/interpreters/Python3_fifo.md b/doc/sources/interpreters/Python3_fifo.md index 58c90f5..3ec4c5e 100644 --- a/doc/sources/interpreters/Python3_fifo.md +++ b/doc/sources/interpreters/Python3_fifo.md @@ -2,14 +2,13 @@ This is a pipe-based implementation that has some quirks: - -You have to run sniprun once before being able to send code snippets to it (configure an autocmd?) +You have to run sniprun once before being able to send code snippets +to it (configure an autocmd?) A python REPL is launched in the background and won't quit till you exit neovim. - -This interpreter only works in REPL-mode, and is not the default for Python files, so to use it you should configure it as following: - +This interpreter only works in REPL-mode, and is not the default for Python +files, so to use it you should configure it as following: ```lua require'sniprun'.setup({ @@ -18,12 +17,11 @@ require'sniprun'.setup({ }) ``` -if a snippet produce an error important enough to crash the interpreter, you may be required to re-launch the kernel (with a `SnipRun`) - +if a snippet produce an error important enough to crash the interpreter, +you may be required to re-launch the kernel (with a `SnipRun`) setting a custom python interpreter and venv is also supported - ```lua require'sniprun'.setup({ interpreter_options = { @@ -35,4 +33,3 @@ require'sniprun'.setup({ } }) ``` - diff --git a/doc/sources/interpreters/Python3_jupyter.md b/doc/sources/interpreters/Python3_jupyter.md index 596c90e..c529e0f 100644 --- a/doc/sources/interpreters/Python3_jupyter.md +++ b/doc/sources/interpreters/Python3_jupyter.md @@ -1,67 +1,45 @@ ## Python3 jupyter -Unless you really really need this (for Ipython), I would strongly advise for the Python3_fifo interpreter which has -way less potential issues +Unless you really really need this (for Ipython), I would strongly +advise for the Python3_fifo interpreter which has way less potential issues ### Dependencies + - jupyter -(more specifically, you must be able to run `jupyter-kernel` and `jupyter-console` from the command line) +(more specifically, you must be able to run `jupyter-kernel` and +`jupyter-console` from the command line) ### Notes +(As there is a different interpreter for Python, you may want to +force the selection of Python3_jupyter with:) -(As there is a different interpreter for Python, you may want to force the selection of Python3_jupyter with:) ```lua require'sniprun'.setup({ selected_interpreters={'Python3_jupyter'} }) ``` - ### Limitations -The code runs on a separate jupyter python3 kernel which will NOT interefere with your own running kernels. - -However, mind that the usual limitations of such kernels still apply: max duration of execution, etc... but you probably don't have to pay too much attention to this. +The code runs on a separate jupyter python3 kernel which will NOT interefere +with your own running kernels. +However, mind that the usual limitations of such kernels still apply: +max duration of execution, etc... but you probably don't have to pay +too much attention to this. -The jupyter kernel also has a substantial overhead when it comes to running code, in addition to imports*, that means the Python3_jupyter interpreter may feel a bit slow compared to others, when the REPL functionnaluty relying on it. +The jupyter kernel also has a substantial overhead when it comes to running +code, in addition to imports*, that means the Python3_jupyter interpreter may +feel a bit slow compared to others, when the REPL functionnaluty relying on it. -\* The Jupyter-based interpreter also doesn't support Python's "list-import" syntax such as: +\* The Jupyter-based interpreter also doesn't support +Python's "list-import" syntax such as: -``` +```python from math import ( sin, cos ) ``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/sources/interpreters/Python3_original.md b/doc/sources/interpreters/Python3_original.md index f29648e..7dc4bf0 100644 --- a/doc/sources/interpreters/Python3_original.md +++ b/doc/sources/interpreters/Python3_original.md @@ -1,6 +1,7 @@ ## Python3 original -To get the REPL behaviour (inactive by default) working, you need to install the klepto python package: `pip install --user klepto` +To get the REPL behaviour (inactive by default) working, you need to install +the klepto python package: `pip install --user klepto` Then, to enable the REPL behavior for python in your config file @@ -10,19 +11,29 @@ require'sniprun'.setup({ }) ``` -HOWEVER, if you're interested in a very stable and solid REPL python interpreter, to process bigger amount of data or import some exotic modules (not supported by klepto), get a look at the Python3_fifo interpreter. +HOWEVER, if you're interested in a very stable and solid REPL python +interpreter, to process bigger amount of data or import some exotic +modules (not supported by klepto), get a look at the Python3_fifo interpreter. +With the REPL enabled, sniprunning a \* (star) import `from module import *` may +not work, indeed the imports needs to be correctly saved/loaded by klepto. +klepto manages variables, functions and modules but very special things may fail. -With the REPL enabled, sniprunning a \* (star) import `from module import *` may not work, indeed the imports needs to be correctly saved/loaded by klepto. klepto manages variables, functions and modules but very special things may fail. +Without REPL enabled, your python snip's will be executed faster +(and not increasingly slower) and the correctness/cleanliness of the inner +working is garanteed. By setting this, you can be sure your snip's will run +free of side-effects and anything you would not want. -Without REPL enabled, your python snip's will be executed faster (and not increasingly slower) and the correctness/cleanliness of the inner working is garanteed. By setting this, you can be sure your snip's will run free of side-effects and anything you would not want. - -With or without REPL, the star imports may also not be automatically fetched, even though normal imports will be. Python3_original has the 'Import' support level but that won"t work with star import, and I don't think we'll be able to make a workaround due to the philosophy 'run only what's necessary' of sniprun. - - - -To use a custom python interpreter ( maybe python2, or a particular version?) you can provide the following interpreter options:, using a venv is also supported (provide one or several relative paths "../venv" etc.. may be necessary if Neovim didn't set the current working directory at the root of the project (presumably next to the venv). +With or without REPL, the star imports may also not be automatically fetched, +even though normal imports will be. Python3_original has the 'Import' support +level but that won"t work with star import, and I don't think we'll be able +to make a workaround due to the philosophy 'run only what's necessary' of sniprun. +To use a custom python interpreter ( maybe python2, or a particular version?) +you can provide the following interpreter options:, using a venv is also +supported (provide one or several relative paths "../venv" etc.. may be +necessary if Neovim didn't set the current working directory at the root +of the project (presumably next to the venv). ```lua require'sniprun'.setup({ @@ -35,4 +46,3 @@ require'sniprun'.setup({ } }) ``` - diff --git a/doc/sources/interpreters/R_original.md b/doc/sources/interpreters/R_original.md index 2cbd71e..0b0f006 100644 --- a/doc/sources/interpreters/R_original.md +++ b/doc/sources/interpreters/R_original.md @@ -1,5 +1,3 @@ ## R original Needs `Rscript` - - diff --git a/doc/sources/interpreters/Ruby_original.md b/doc/sources/interpreters/Ruby_original.md index b3ea250..b13ad6f 100644 --- a/doc/sources/interpreters/Ruby_original.md +++ b/doc/sources/interpreters/Ruby_original.md @@ -1,5 +1,3 @@ ## Ruby original This interpreter assumes ruby is installed and on your $PATH, but no extra configuration options are available - - diff --git a/doc/sources/interpreters/Rust_original.md b/doc/sources/interpreters/Rust_original.md index 92cf381..55aa4b6 100644 --- a/doc/sources/interpreters/Rust_original.md +++ b/doc/sources/interpreters/Rust_original.md @@ -12,5 +12,3 @@ require'sniprun'.setup({ } }) ``` - - diff --git a/doc/sources/interpreters/Sage_fifo.md b/doc/sources/interpreters/Sage_fifo.md index 6dd296c..733e57a 100644 --- a/doc/sources/interpreters/Sage_fifo.md +++ b/doc/sources/interpreters/Sage_fifo.md @@ -1,8 +1,10 @@ ## Sage fifo -This is a pipe-based implementation: you have to run sniprun once before being able to send code snippets (configure an autcmd?) +This is a pipe-based implementation: you have to run sniprun once before +being able to send code snippets (configure an autcmd?) -A sage REPL is launcher in the background and won't quit until you exit neovim (or after 10h). +A sage REPL is launcher in the background and won't quit +until you exit neovim (or after 10h). This interpreter only works in REPL-mode (and behaves REPL-like by default) @@ -11,11 +13,11 @@ two configurations keys are available: ```lua require'sniprun'.setup({ interpreter_options = { - Sage_fifo = { - interpreter = "sage", - sage_user_config = 1, -- the actual value has no effect, only the presence of the key is important - } - } + Sage_fifo = { + interpreter = "sage", + sage_user_config = 1, -- the actual value has no effect, only the presence of the key is important + } + } } }); ``` diff --git a/doc/sources/interpreters/TypeScript_original.md b/doc/sources/interpreters/TypeScript_original.md index b8b0bf1..8b6937f 100644 --- a/doc/sources/interpreters/TypeScript_original.md +++ b/doc/sources/interpreters/TypeScript_original.md @@ -3,4 +3,3 @@ Requires `ts-node`, usually installed from npm `sudo npm install -g ts-node typescript` - From 5fa83962048c78266a009090e20d5cccac06e8ab Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 27 Jul 2024 17:19:36 +0200 Subject: [PATCH 11/12] remove beta from version and update changelog --- CHANGELOG.md | 2 + Cargo.lock | 226 +++++++++++++++++++++++++-------------------------- Cargo.toml | 4 +- 3 files changed, 114 insertions(+), 118 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33fc4bc..09c016b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## v1.3.15 - Add PlantUML support (ascii output) +- Basic user input support +- SQL support ## v1.3.14 - Improve Lua\_nvim's handling of 'local' requires in REPL mode diff --git a/Cargo.lock b/Cargo.lock index 0064595..df695c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -28,15 +28,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -61,15 +61,9 @@ checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "byteorder" @@ -79,15 +73,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" [[package]] name = "cc" -version = "1.0.95" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" [[package]] name = "cfg-if" @@ -129,9 +123,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "crc32fast" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if 1.0.0", ] @@ -172,9 +166,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -274,9 +268,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", "libc", @@ -285,15 +279,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "http" @@ -338,15 +332,15 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libredox" @@ -354,15 +348,15 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.1", + "bitflags", "libc", ] [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -370,9 +364,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "log-panics" @@ -386,15 +380,15 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -413,18 +407,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "object" -version = "0.32.2" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" dependencies = [ "memchr", ] @@ -449,9 +443,9 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -459,15 +453,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.4.1", + "redox_syscall 0.5.3", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -490,9 +484,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -514,11 +508,11 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -534,9 +528,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -546,9 +540,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -557,9 +551,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "ring" @@ -600,9 +594,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustls" @@ -660,9 +654,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" @@ -681,11 +675,11 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -694,9 +688,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" dependencies = [ "core-foundation-sys", "libc", @@ -704,9 +698,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.198" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] @@ -722,9 +716,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", @@ -733,9 +727,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -795,7 +789,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "sniprun" -version = "1.3.15-beta" +version = "1.3.15" dependencies = [ "close_fds", "dirs", @@ -837,9 +831,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "2.0.60" +version = "2.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" dependencies = [ "proc-macro2", "quote", @@ -848,18 +842,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -879,9 +873,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -957,9 +951,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -968,9 +962,9 @@ dependencies = [ [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "vte" @@ -1044,7 +1038,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1064,18 +1058,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -1086,9 +1080,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -1098,9 +1092,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -1110,15 +1104,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -1128,9 +1122,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -1140,9 +1134,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -1152,9 +1146,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -1164,9 +1158,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "zeroize" diff --git a/Cargo.toml b/Cargo.toml index 6831ada..797d08a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.3.15-beta" +version = "1.3.15" authors = ["michaelb "] rust-version = "1.65" edition = "2018" @@ -22,7 +22,7 @@ simple-logging = "2.0" close_fds = "0.3" thiserror = "1.0" dirs = "5.0" -regex = "1.0" # up-to-date-regex needs a more recent Rust version +regex = "1.0" # up-to-date-regex needs a more recent Rust version strip-ansi-escapes = "0.2" libc = "0.2.79" serial_test = "2.0" From 2fd6808597590162a583691565bc0ac0b4a3a44f Mon Sep 17 00:00:00 2001 From: Michael B Date: Sat, 27 Jul 2024 17:33:54 +0200 Subject: [PATCH 12/12] remove wrong sql test --- src/interpreters/SQL_original.rs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/interpreters/SQL_original.rs b/src/interpreters/SQL_original.rs index 62ff6ae..89499c3 100644 --- a/src/interpreters/SQL_original.rs +++ b/src/interpreters/SQL_original.rs @@ -132,23 +132,3 @@ impl Interpreter for SQL_original { } } } - -#[cfg(test)] -mod test_d_original { - use super::*; - use serial_test::serial; - - #[test] - #[serial(d_original)] - fn simple_print() { - let mut data = DataHolder::new(); - data.current_bloc = - String::from("string yourName = \"a\";\nwritefln(\"Hi %s!\", yourName);"); - let mut interpreter = SQL_original::new(data); - let res = interpreter.run(); - - // should panic if not an Ok() - let string_result = res.unwrap(); - assert_eq!(string_result, "Hi a!\n"); - } -}