From 65dfe02f4d62700b9b934e65002042a3ab3da30a Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Mon, 19 Dec 2022 22:45:00 +0100 Subject: [PATCH 01/19] elixir support --- docs/sources/README.md | 3 +- docs/sources/interpreters/Elixir_original.md | 3 + src/interpreters/Elixir_original.rs | 302 +++++++++++++++++++ 3 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 docs/sources/interpreters/Elixir_original.md create mode 100644 src/interpreters/Elixir_original.rs diff --git a/docs/sources/README.md b/docs/sources/README.md index cf63237b..41dc88a4 100755 --- a/docs/sources/README.md +++ b/docs/sources/README.md @@ -369,6 +369,7 @@ println!("-> {}", alphabet); | Clojure | Bloc | Yes \*\* | | Coffeescript | Bloc | No | | D | Bloc | No | +| Elixir | Bloc | Yes \*\* | | F# | Bloc | No, but _could_ \*\* | | Go | Import | No | | Haskell | Line | No | @@ -391,7 +392,7 @@ println!("-> {}", alphabet); Want 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 functionnality, with potential unwanted side-effects +\* (fake) REPL-like functionality, with potential unwanted side effects \*\* True REPL under the hood diff --git a/docs/sources/interpreters/Elixir_original.md b/docs/sources/interpreters/Elixir_original.md new file mode 100644 index 00000000..90ddf8ab --- /dev/null +++ b/docs/sources/interpreters/Elixir_original.md @@ -0,0 +1,3 @@ +## Elixir original + +Needs "elixir" (or "iex" for REPL mode) available and in $PATH) diff --git a/src/interpreters/Elixir_original.rs b/src/interpreters/Elixir_original.rs new file mode 100644 index 00000000..4952599f --- /dev/null +++ b/src/interpreters/Elixir_original.rs @@ -0,0 +1,302 @@ +#[derive(Clone)] +#[allow(non_camel_case_types)] +pub struct Elixir_original { + support_level: SupportLevel, + data: DataHolder, + code: String, + main_file_path: String, + cache_dir: String, + + current_output_id: u32, +} + +impl Elixir_original { + fn wait_out_file(&self, path: String, id: u32) -> Result { + let end_mark = String::from("sniprun_finished_id=") + &id.to_string(); + let start_mark = String::from("sniprun_started_id=") + &id.to_string(); + + info!( + "searching for things between {:?} and {:?}", + start_mark, end_mark + ); + + let mut contents = String::new(); + + let mut pause = std::time::Duration::from_millis(50); + loop { + std::thread::sleep(pause); + pause = pause.saturating_add(std::time::Duration::from_millis(50)); + + if let Ok(mut file) = std::fs::File::open(&path) { + info!("file exists"); + let res = file.read_to_string(&mut contents); + if res.is_ok() { + info!("file could be read : {:?}", contents); + // info!("file : {:?}", contents); + if contents.contains(&end_mark) { + info!("found"); + break; + } + contents.clear(); + } + } + info!("not found yet"); + } + + // elixir-specific filtering + let mut cleaned_contents = String::new(); + let mut current_line = contents.lines().next().unwrap_or(""); + for l in contents.lines() { + if current_line.starts_with("iex(") { + let index = current_line.rfind(")>").unwrap(); + cleaned_contents += ¤t_line[index + 2..]; + } else if !(current_line == ":ok" && l.starts_with("iex(")) { + // keep the line + cleaned_contents += current_line; + cleaned_contents += "\n"; + } else { + // do nothing, (discarding the line) + } + current_line = l; + } + // info!("cleaned contents: {:?}", cleaned_contents); + + let contents = cleaned_contents; + let index = contents.rfind(&start_mark).unwrap(); + Ok(contents[index + start_mark.len()..contents.len() - end_mark.len() - 1].to_owned()) + } +} + +impl Interpreter for Elixir_original { + fn new_with_level(data: DataHolder, level: SupportLevel) -> Box { + //create a subfolder in the cache folder + let rwd = data.work_dir.clone() + "/elixir_original"; + let mut builder = DirBuilder::new(); + builder.recursive(true); + builder + .create(&rwd) + .expect("Could not create directory for elixir-original"); + + //pre-create string pointing to main file's and binary's path + let mfp = rwd.clone() + "/main.exs"; + + Box::new(Elixir_original { + data, + support_level: level, + code: String::from(""), + main_file_path: mfp, + cache_dir: rwd, + current_output_id: 0, + }) + } + + fn get_name() -> String { + String::from("Elixir_original") + } + + fn default_for_filetype() -> bool { + true + } + + fn behave_repl_like_default() -> bool { + false + } + + fn has_repl_capability() -> bool { + false + } + + fn get_supported_languages() -> Vec { + vec![ + String::from("Elixir"), + String::from("elixir"), + String::from("exs"), + ] + } + + 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 get_max_support_level() -> SupportLevel { + SupportLevel::Bloc + } + + fn check_cli_args(&self) -> Result<(), SniprunError> { + // All cli arguments are sendable to python + // Though they will be ignored in REPL mode + Ok(()) + } + + fn fetch_code(&mut self) -> Result<(), SniprunError> { + if !self + .data + .current_bloc + .replace(&[' ', '\t', '\n', '\r'][..], "") + .is_empty() + && self.get_current_level() >= SupportLevel::Bloc + { + self.code = self.data.current_bloc.clone(); + } 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(""); + } + + Ok(()) + } + fn add_boilerplate(&mut self) -> Result<(), SniprunError> { + Ok(()) + } + fn build(&mut self) -> Result<(), SniprunError> { + // info!("python code:\n {}", self.code); + write(&self.main_file_path, &self.code) + .expect("Unable to write to file for elixir_original"); + Ok(()) + } + fn execute(&mut self) -> Result { + let output = Command::new("elixir") + .arg(&self.main_file_path) + .args(&self.get_data().cli_args) + .output() + .expect("Unable to start process"); + if output.status.success() { + Ok(String::from_utf8(output.stdout).unwrap()) + } else { + if Elixir_original::error_truncate(&self.get_data()) == ErrTruncate::Short { + return Err(SniprunError::RuntimeError( + String::from_utf8(output.stderr.clone()) + .unwrap() + .lines() + .last() + .unwrap_or(&String::from_utf8(output.stderr).unwrap()) + .to_owned(), + )); + } else { + return Err(SniprunError::RuntimeError( + String::from_utf8(output.stderr.clone()).unwrap().to_owned(), + )); + } + } + } +} + +impl ReplLikeInterpreter for Elixir_original { + fn fetch_code_repl(&mut self) -> Result<(), SniprunError> { + self.fetch_code()?; + + if !self.read_previous_code().is_empty() { + // nothing to do, kernel already running + info!("elixir kernel already running"); + + if let Some(id) = self.get_pid() { + // there is a race condition here but honestly you'd have to + // trigger it on purpose + self.current_output_id = id + 1; + self.set_pid(self.current_output_id); + } else { + info!("Could not retrieve a previous id even if the kernel is running"); + } + + Ok(()) + } else { + // launch everything + self.set_pid(0); + + let init_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/init_repl.sh"; + info!( + "launching kernel : {:?} on {:?}", + init_repl_cmd, &self.cache_dir + ); + + match daemon() { + Ok(Fork::Child) => { + let _res = Command::new("bash") + .args(&[ + init_repl_cmd, + self.cache_dir.clone(), + Elixir_original::get_nvim_pid(&self.data), + "iex".to_owned(), + ]) + .output() + .unwrap(); + + return Err(SniprunError::CustomError("elixir REPL exited".to_owned())); + } + Ok(Fork::Parent(_)) => {} + Err(_) => info!( + "Elixir_original could not fork itself to the background to launch the kernel" + ), + }; + + let pause = std::time::Duration::from_millis(100); + std::thread::sleep(pause); + self.save_code("kernel_launched".to_owned()); + + Err(SniprunError::CustomError( + "elixir kernel launched, re-run your snippet".to_owned(), + )) + } + } + + fn add_boilerplate_repl(&mut self) -> Result<(), SniprunError> { + self.add_boilerplate()?; + let start_mark = String::from("IO.puts(\"sniprun_started_id=") + + &self.current_output_id.to_string() + + "\")\n"; + let end_mark = String::from("IO.puts(\"sniprun_finished_id=") + + &self.current_output_id.to_string() + + "\")\n"; + + self.code = start_mark + &self.code + &String::from("\n") + &end_mark; + Ok(()) + } + + fn build_repl(&mut self) -> Result<(), SniprunError> { + self.build() + } + + fn execute_repl(&mut self) -> Result { + let send_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/launcher_repl.sh"; + info!("running launcher (via {})", send_repl_cmd); + let res = Command::new(send_repl_cmd) + .arg(self.cache_dir.clone() + "/main.exs") + .arg(self.cache_dir.clone() + "/fifo_repl/pipe_in") + .spawn() + .expect("could not run launcher"); + info!("launcher launched : {:?}", res); + + let outfile = self.cache_dir.clone() + "/fifo_repl/out_file"; + info!("outfile : {:?}", outfile); + match self.wait_out_file(outfile, self.current_output_id) { + Ok(s) => Ok(s), + Err(s) => Err(SniprunError::CustomError(s)), + } + } +} + +#[cfg(test)] +mod test_elixir_original { + use super::*; + + #[test] + fn simple_print() { + let mut data = DataHolder::new(); + data.current_bloc = String::from("IO.puts(\"hello\")"); + let mut interpreter = Elixir_original::new(data); + let res = interpreter.run(); + + // should panic if not an Ok() + let string_result = res.unwrap(); + assert_eq!(string_result, "hello\n"); + } +} From 5f81ea0b12174374ea559ef781234ce0c61ee232 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Mon, 19 Dec 2022 22:45:57 +0100 Subject: [PATCH 02/19] typo in trace --- ressources/init_repl.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ressources/init_repl.sh b/ressources/init_repl.sh index 9d4750b4..eb51dbec 100644 --- a/ressources/init_repl.sh +++ b/ressources/init_repl.sh @@ -44,7 +44,6 @@ bash $working_dir/real_launcher.sh > $working_dir/$out 2> $working_dir/$err & echo "done" >> $log - # wait for the parent nvim process to exit, then kill the sniprun process that launched this script while ps -p $nvim_pid ;do @@ -54,6 +53,6 @@ done pkill -P $$ -echo $repl " and other backoung process terminated at $(date +"%F %T")." >> $log +echo $repl " and other background processes terminated at $(date +"%F %T")." >> $log rm -rf $working_dir From ce5442d96781273b0db5641af0d4e1b23ce86e50 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 20 Dec 2022 13:10:10 +0100 Subject: [PATCH 03/19] update julia repl even if still doesn't work --- src/interpreters/Julia_original.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index f1d42aa9..98c1b5f2 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -240,7 +240,7 @@ impl ReplLikeInterpreter for Julia_original { + &self.current_output_id.to_string() + "\")\n"; - self.code = start_mark + &self.code + &end_mark; + self.code = start_mark + &self.code + "\n" + &end_mark; Ok(()) } @@ -250,9 +250,9 @@ impl ReplLikeInterpreter for Julia_original { fn execute_repl(&mut self) -> Result { info!("running launcher"); - let send_repl_cmd = self.data.sniprun_root_dir.clone() + "ressources/launcher.sh"; + let send_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/launcher_repl.sh"; let res = Command::new(send_repl_cmd) - .arg(self.cache_dir.clone() + "/main.mma") + .arg(self.cache_dir.clone() + "/main.jl") .arg(self.cache_dir.clone() + "/fifo_repl/pipe_in") .spawn() .expect("could not run launcher"); From a429e44841cdedb068dad2f4f11722013ede8c2c Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 20 Dec 2022 13:14:40 +0100 Subject: [PATCH 04/19] fix typos in doc and add example --- docs/sources/README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/sources/README.md b/docs/sources/README.md index 41dc88a4..7277f5ae 100755 --- a/docs/sources/README.md +++ b/docs/sources/README.md @@ -305,9 +305,9 @@ All of sniprun functionalities:

``` -vim.api.nvim\_set\_keymap('v', 'f', 'SnipRun', {silent = true}) -vim.api.nvim\_set\_keymap('n', 'f', 'SnipRunOperator', {silent = true}) -vim.api.nvim\_set\_keymap('n', 'ff', 'SnipRun', {silent = true}) +vim.api.nvim_set_keymap('v', 'f', 'SnipRun', {silent = true}) +vim.api.nvim_set_keymap('n', 'f', 'SnipRunOperator', {silent = true}) +vim.api.nvim_set_keymap('n', 'ff', 'SnipRun', {silent = true}) ```

@@ -323,10 +323,12 @@ vmap f SnipRun

-- For interpreted languages with simple output, `:%SnipRun` (or a shortcut, wrapping it with `let b:caret=winsaveview()` and `call winrestview(b:caret)` in order to keep the cursor at the current position) may be a more convenient way to run your entire file. When running the whole file, SnipRun supports taking arguments on the command line: `:%SnipRun 5 "yay"` frictionlessly for interpreted languages, and compiled languages with entry point detection implemented (most of them). +- For interpreted languages with simple output, `:%SnipRun` (or a shortcut, wrapping it with `let b:caret=winsaveview()` and `call winrestview(b:caret)` in order to keep the cursor at the current position) may be a more convenient way to run your entire file. Example mapping `:%SnipRun` to F5: `vim.keymap.set('n', '', ":let b:caret=winsaveview() | :%SnipRun | :call winrestview(b:caret) ", {})`, with my apologies for poor vimscript. +When running the whole file, SnipRun supports taking arguments on the command line: `:%SnipRun 5 "yay"` frictionlessly for interpreted languages, and compiled languages with entry point detection implemented (most of them). -While both shorthands and \ are here to stay, **please use the `` style ones in your mappings** or if using from another plugin. + +While both shorthands and \ are here to stay, **it's better practice to use the `` style ones in your mappings** or if using from another plugin. From 8eaef4cdb287ccd0d007b989af01fc8d940e2008 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 21 Dec 2022 14:30:50 +0100 Subject: [PATCH 05/19] special init_repl.sh for julia, REPL works! --- src/interpreters/Julia_original.rs | 6 +- src/interpreters/Julia_original/init_repl.sh | 58 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100755 src/interpreters/Julia_original/init_repl.sh diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index 98c1b5f2..f301d589 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -193,7 +193,7 @@ impl ReplLikeInterpreter for Julia_original { // launch everything self.set_pid(0); - let init_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/init_repl.sh"; + let init_repl_cmd = self.data.sniprun_root_dir.clone() + "/src/interpreters/Julia_original/init_repl.sh"; info!( "launching kernel : {:?} on {:?}", init_repl_cmd, &self.cache_dir @@ -206,7 +206,7 @@ impl ReplLikeInterpreter for Julia_original { init_repl_cmd, self.cache_dir.clone(), Julia_original::get_nvim_pid(&self.data), - "julia --banner=no --color=no".to_owned(), + "julia".to_owned(), ]) .output() .unwrap(); @@ -252,7 +252,7 @@ impl ReplLikeInterpreter for Julia_original { info!("running launcher"); let send_repl_cmd = self.data.sniprun_root_dir.clone() + "/ressources/launcher_repl.sh"; let res = Command::new(send_repl_cmd) - .arg(self.cache_dir.clone() + "/main.jl") + .arg(self.main_file_path.clone()) .arg(self.cache_dir.clone() + "/fifo_repl/pipe_in") .spawn() .expect("could not run launcher"); diff --git a/src/interpreters/Julia_original/init_repl.sh b/src/interpreters/Julia_original/init_repl.sh new file mode 100755 index 00000000..af069dbd --- /dev/null +++ b/src/interpreters/Julia_original/init_repl.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# this script takes 3 (or more) args. +# $1 is a path to a working directory +# $2 is the PID of the parent neovim session. All processes created here will be killed when the parent exits +# $3, $4 ... are the repl command to launch (ex: "deno", "repl" "-q") + + +working_dir="$1/fifo_repl" +log=$working_dir/../background_repl_process.log +if test -e "$working_dir" ; then + echo "process already present" >> $log + exit 1 +fi + + + + +pipe=pipe_in +out=out_file +err=err_file + +nvim_pid=$2 + +shift 2 +repl="$@" # the rest + + +rm -rf $working_dir/ +mkdir -p $working_dir +echo "pid of parent neovim session is $nvim_pid" >> $log +echo "setting up things" >> $log + +mkfifo $working_dir/$pipe +touch $working_dir/$out +sleep 36000 > $working_dir/$pipe & + +echo "/bin/cat " $working_dir/$pipe " | " $repl > $working_dir/real_launcher.sh +chmod +x $working_dir/real_launcher.sh + +echo $repl " process started at $(date +"%F %T")." >> $log +bash $working_dir/real_launcher.sh | tee $working_dir/$out & + +echo "done" >> $log + + +# wait for the parent nvim process to exit, then kill the sniprun process that launched this script + +while ps -p $nvim_pid ;do + sleep 1 +done + + +pkill -P $$ + +echo $repl " and other background processes terminated at $(date +"%F %T")." >> $log + +rm -rf $working_dir From ea4fdc21851df457a2b1470bf64aab9a128766a2 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 21 Dec 2022 14:32:00 +0100 Subject: [PATCH 06/19] advertise Julia repl capabilities --- ressources/init_repl.sh | 0 src/interpreters/Julia_original.rs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 ressources/init_repl.sh diff --git a/ressources/init_repl.sh b/ressources/init_repl.sh old mode 100644 new mode 100755 diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index f301d589..41cd64cd 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -84,7 +84,7 @@ impl Interpreter for Julia_original { } fn has_repl_capability() -> bool { - false + true } fn get_supported_languages() -> Vec { From 904c8e28b59d1d10689e0ae6632fd9a42a12d9d3 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 21 Dec 2022 22:02:06 +0100 Subject: [PATCH 07/19] doc fixes --- docs/sources/README.md | 11 ++++++----- docs/sources/interpreters/Julia_original.md | 8 ++++++++ src/interpreters/Julia_original.rs | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/sources/README.md b/docs/sources/README.md index 7277f5ae..d5542f21 100755 --- a/docs/sources/README.md +++ b/docs/sources/README.md @@ -259,13 +259,14 @@ require'sniprun'.setup({ SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"}, }, + live_mode_toggle='off' --# live mode toggle, see Usage - Running for more info + --# miscellaneous compatibility/adjustement settings - inline_messages = 0, --# inline_message (0/1) is a one-line way to display messages - --# to workaround sniprun not being able to display anything + inline_messages = 0, --# inline_message (0/1) is a one-line way to display messages + --# to workaround sniprun not being able to display anything - borders = 'single', --# display borders around floating windows - --# possible values are 'none', 'single', 'double', or 'shadow' - live_mode_toggle='off' --# live mode toggle, see Usage - Running for more info + borders = 'single', --# display borders around floating windows + --# possible values are 'none', 'single', 'double', or 'shadow' }) EOF ``` diff --git a/docs/sources/interpreters/Julia_original.md b/docs/sources/interpreters/Julia_original.md index 33d3b713..d8eaa899 100644 --- a/docs/sources/interpreters/Julia_original.md +++ b/docs/sources/interpreters/Julia_original.md @@ -1,3 +1,11 @@ ## Julia original Simply needs the 'julia' executable + +REPL mode can be activated with this configuration + +``` +lua require'sniprun'.setup({ + repl_enable = {'Julia_original'}, +}) +``` diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index 41cd64cd..f7b47f86 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -111,7 +111,7 @@ impl Interpreter for Julia_original { } fn check_cli_args(&self) -> Result<(), SniprunError> { - // All cli arguments are sendable to python + // All cli arguments are sendable to julia // Though they will be ignored in REPL mode Ok(()) } From be7f8c847e234793a539e8fe565b9c57e00b34fb Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Fri, 23 Dec 2022 14:20:57 +0100 Subject: [PATCH 08/19] julia --project support --- docs/sources/interpreters/Julia_original.md | 17 +++++- src/interpreters/Julia_original.rs | 54 +++++++++++++++++--- src/interpreters/Julia_original/init_repl.sh | 2 +- src/lib.rs | 11 +++- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/docs/sources/interpreters/Julia_original.md b/docs/sources/interpreters/Julia_original.md index d8eaa899..994c0989 100644 --- a/docs/sources/interpreters/Julia_original.md +++ b/docs/sources/interpreters/Julia_original.md @@ -4,8 +4,21 @@ Simply needs the 'julia' executable REPL mode can be activated with this configuration -``` -lua require'sniprun'.setup({ +```lua +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) + +```lua +require('sniprun').setup({ + interpreter_options = { + Julia_original = { + project="." --# either a fixed absolute path, or "." for nvim's current directory (from echo getcwd() ) + --# This directory has to contain a {Project,Manifest}.toml ! + interpreter="/path/to/custom/julia" + } + } +}) +``` diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index f7b47f86..97df62b0 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -7,6 +7,9 @@ pub struct Julia_original { main_file_path: String, cache_dir: String, + interpreter: String, + interpreter_args: Vec, // for now, used for --project=.... + current_output_id: u32, } @@ -46,6 +49,35 @@ impl Julia_original { let index = contents.rfind(&start_mark).unwrap(); Ok(contents[index + start_mark.len()..contents.len() - end_mark.len() - 1].to_owned()) } + + fn fetch_config(&mut self) { + let default_interpreter = String::from("julia"); + self.interpreter = default_interpreter; + if let Some(used_interpreter) = + Julia_original::get_interpreter_option(&self.get_data(), "interpreter") + { + if let Some(interpreter_string) = used_interpreter.as_str() { + info!("Using custom interpreter: {}", interpreter_string); + self.interpreter = interpreter_string.to_string(); + } + } + + if let Some(project_opt) = + Julia_original::get_interpreter_option(&self.get_data(), "project") + { + if let Some(mut project_str) = project_opt.as_str() { + if project_str == "." { + info!( + "Using neovim's current working directory as julia --project: {}", + self.data.projectroot + ); + project_str = &self.data.projectroot; + } + + self.interpreter_args = vec![String::from("--project=") + project_str]; + } + } + } } impl Interpreter for Julia_original { @@ -66,6 +98,8 @@ impl Interpreter for Julia_original { support_level: level, code: String::from(""), main_file_path: mfp, + interpreter: String::new(), + interpreter_args: Vec::new(), cache_dir: rwd, current_output_id: 0, }) @@ -117,6 +151,7 @@ impl Interpreter for Julia_original { } fn fetch_code(&mut self) -> Result<(), SniprunError> { + self.fetch_config(); if !self .data .current_bloc @@ -145,7 +180,8 @@ impl Interpreter for Julia_original { Ok(()) } fn execute(&mut self) -> Result { - let output = Command::new("julia") + let output = Command::new(&self.interpreter) + .args(&self.interpreter_args) .arg(&self.main_file_path) .args(&self.get_data().cli_args) .output() @@ -193,7 +229,8 @@ impl ReplLikeInterpreter for Julia_original { // launch everything self.set_pid(0); - let init_repl_cmd = self.data.sniprun_root_dir.clone() + "/src/interpreters/Julia_original/init_repl.sh"; + let init_repl_cmd = self.data.sniprun_root_dir.clone() + + "/src/interpreters/Julia_original/init_repl.sh"; info!( "launching kernel : {:?} on {:?}", init_repl_cmd, &self.cache_dir @@ -206,14 +243,13 @@ impl ReplLikeInterpreter for Julia_original { init_repl_cmd, self.cache_dir.clone(), Julia_original::get_nvim_pid(&self.data), - "julia".to_owned(), + self.interpreter.clone(), ]) + .args(&self.interpreter_args) .output() .unwrap(); - return Err(SniprunError::CustomError( - "julia REPL exited".to_owned(), - )); + return Err(SniprunError::CustomError("julia REPL exited".to_owned())); } Ok(Fork::Parent(_)) => {} Err(_) => info!( @@ -240,6 +276,12 @@ impl ReplLikeInterpreter for Julia_original { + &self.current_output_id.to_string() + "\")\n"; + let start_mark_err = String::from("println(stderr, \"sniprun_started_id=") + + &self.current_output_id.to_string() + + "\")\n"; + let end_mark_err = String::from("println(stderr, \"sniprun_finished_id=") + + &self.current_output_id.to_string() + + "\")\n"; self.code = start_mark + &self.code + "\n" + &end_mark; Ok(()) } diff --git a/src/interpreters/Julia_original/init_repl.sh b/src/interpreters/Julia_original/init_repl.sh index af069dbd..64eb2939 100755 --- a/src/interpreters/Julia_original/init_repl.sh +++ b/src/interpreters/Julia_original/init_repl.sh @@ -39,7 +39,7 @@ echo "/bin/cat " $working_dir/$pipe " | " $repl > $working_dir/real_launcher.sh chmod +x $working_dir/real_launcher.sh echo $repl " process started at $(date +"%F %T")." >> $log -bash $working_dir/real_launcher.sh | tee $working_dir/$out & +bash $working_dir/real_launcher.sh | tee $working_dir/$out 2| tee $working_dir/$err & echo "done" >> $log diff --git a/src/lib.rs b/src/lib.rs index 9aee281e..36ff14f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,8 @@ pub struct DataHolder { pub range: [i64; 2], /// path of the current file that's being edited pub filepath: String, - /// Field is left blank as of v0.3 + /// Current directory for Neovim. Neovim is responsible for setting correctly the current working directory + /// Sniprun retrieves the result from `getcwd()` as of v1.2.9 pub projectroot: String, /// field is left blank as of v0.3 pub dependencies_path: Vec, @@ -249,6 +250,14 @@ impl EventHandler { } } + { + //get neovim's current directory + let nvim_cwd = self.nvim.lock().unwrap().call_function("getcwd", vec![]).unwrap(); + info!("nvimcwd as value: nvim_cwd: {:?}", nvim_cwd); + self.data.projectroot = String::from(nvim_cwd.as_str().unwrap()); + info!("[FILLDATA] got neovim's current directory: {}", self.data.projectroot); + } + { //get filetype let ft = self.nvim.lock().unwrap().command_output("set ft?"); From de7bb5fbf155d0f5610541c7c1f850c89628baee Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 27 Dec 2022 20:33:38 +0100 Subject: [PATCH 09/19] new CSharp interpreter --- src/interpreters/CSharp_original.rs | 196 ++++++++++++++++++++++++++++ src/interpreters/Rust_original.rs | 4 +- 2 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 src/interpreters/CSharp_original.rs diff --git a/src/interpreters/CSharp_original.rs b/src/interpreters/CSharp_original.rs new file mode 100644 index 00000000..8944f0e4 --- /dev/null +++ b/src/interpreters/CSharp_original.rs @@ -0,0 +1,196 @@ +#[derive(Clone)] +#[allow(non_camel_case_types)] +pub struct CSharp_original { + support_level: SupportLevel, + data: DataHolder, + code: String, + + ///specific to csharp + compiler: String, + bin_path: String, + main_file_path: String, +} + +impl CSharp_original { + fn fetch_config(&mut self) { + let default_compiler = String::from("csc"); + self.compiler = default_compiler; + if let Some(used_compiler) = + CSharp_original::get_interpreter_option(&self.get_data(), "compiler") + { + if let Some(compiler_string) = used_compiler.as_str() { + info!("Using custom compiler: {}", compiler_string); + self.compiler = compiler_string.to_string(); + } + } + } +} + +impl ReplLikeInterpreter for CSharp_original {} +impl Interpreter for CSharp_original { + fn new_with_level(data: DataHolder, support_level: SupportLevel) -> Box { + //create a subfolder in the cache folder + let rwd = data.work_dir.clone() + "/csharp_original"; + let mut builder = DirBuilder::new(); + builder.recursive(true); + builder + .create(&rwd) + .expect("Could not create directory for csharp-original"); + + //pre-create string pointing to main file's and binary's path + let mfp = rwd.clone() + "/main.cs"; + let bp = String::from(&mfp[..mfp.len() - 3]); // remove extension so binary is named 'main' + Box::new(CSharp_original { + data, + support_level, + code: String::new(), + bin_path: bp, + main_file_path: mfp, + compiler: String::new(), + }) + } + + fn get_supported_languages() -> Vec { + vec![ + String::from("C#"), + String::from("csharp"), + String::from("cs"), + ] + } + + fn get_name() -> String { + String::from("CSharp_original") + } + + fn default_for_filetype() -> bool { + true + } + 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 get_max_support_level() -> SupportLevel { + SupportLevel::Bloc + } + + fn check_cli_args(&self) -> Result<(), SniprunError> { + // All cli arguments are sendable to Csharp + Ok(()) + } + + fn fetch_code(&mut self) -> Result<(), SniprunError> { + self.fetch_config(); + //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(""); + } + Ok(()) + } + + fn add_boilerplate(&mut self) -> Result<(), SniprunError> { + if !CSharp_original::contains_main("static void Main(string[] args)", &self.code, "//") { + self.code = + String::from("using System; class Hello { static void Main(string[] args) {\n ") + + &self.code + + "\n} }"; + } + + if !CSharp_original::contains_main("using System", &self.code, "//") { + self.code = String::from("using System;\n") + &self.code; + } + 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 csharp-original"); + write(&self.main_file_path, &self.code) + .expect("Unable to write to file for csharp-original"); + + //compile it (to the bin_path that arleady points to the rigth path) + let output = Command::new(&self.compiler) + .arg(String::from("-out:") + &self.bin_path) + .arg(&self.main_file_path) + .output() + .expect("Unable to start process"); + + //TODO if relevant, return the error number (parse it from stderr) + if !output.status.success() { + let error_message = String::from_utf8(output.stderr).unwrap(); + //take first line and remove first 'error' word (redondant) + let first_line = error_message + .lines() + .next() + .unwrap_or_default() + .trim_start_matches("error: ") + .trim_start_matches("error"); + Err(SniprunError::CompilationError(first_line.to_owned())) + } else { + Ok(()) + } + } + + fn execute(&mut self) -> Result { + //run th binary and get the std output (or stderr) + let output = Command::new("mono") + .arg(&self.bin_path) + .args(&self.get_data().cli_args) + .output() + .expect("Unable to start process"); + if output.status.success() { + Ok(String::from_utf8(output.stdout).unwrap()) + } else { + if CSharp_original::error_truncate(&self.get_data()) == ErrTruncate::Short { + return Err(SniprunError::RuntimeError( + String::from_utf8(output.stderr.clone()) + .unwrap() + .lines() + .next() + .unwrap_or(&String::from_utf8(output.stderr).unwrap()) + .to_owned(), + )); + } else { + return Err(SniprunError::RuntimeError( + String::from_utf8(output.stderr.clone()).unwrap().to_owned(), + )); + } + } + } +} + +#[cfg(test)] +mod test_csharp_original { + use super::*; + + #[test] + fn simple_print() { + let mut data = DataHolder::new(); + data.current_bloc = String::from("println!(\"HW, 1+1 = {}\", 1+1);"); + let mut interpreter = CSharp_original::new(data); + let res = interpreter.run(); + + // should panic if not an Ok() + let string_result = res.unwrap(); + assert_eq!(string_result, "HW, 1+1 = 2\n"); + } +} diff --git a/src/interpreters/Rust_original.rs b/src/interpreters/Rust_original.rs index 615afbee..fbfeb081 100644 --- a/src/interpreters/Rust_original.rs +++ b/src/interpreters/Rust_original.rs @@ -82,8 +82,6 @@ impl Interpreter for Rust_original { } fn check_cli_args(&self) -> Result<(), SniprunError> { - // All cli arguments are sendable to python - // Though they will be ignored in REPL mode Ok(()) } @@ -110,7 +108,7 @@ impl Interpreter for Rust_original { fn add_boilerplate(&mut self) -> Result<(), SniprunError> { - if !Rust_original::contains_main("fn main(", &self.code, "//") { + if !Rust_original::contains_main("fn main", &self.code, "//") { self.code = String::from("fn main() {") + &self.code + "}"; } Ok(()) From ff15d64c46369bc108508aff550e2719963267fe Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 27 Dec 2022 20:36:41 +0100 Subject: [PATCH 10/19] doc for C# interpreter --- docs/sources/README.md | 1 + docs/sources/interpreters/CSharp_original | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 docs/sources/interpreters/CSharp_original diff --git a/docs/sources/README.md b/docs/sources/README.md index d5542f21..02a971c7 100755 --- a/docs/sources/README.md +++ b/docs/sources/README.md @@ -369,6 +369,7 @@ println!("-> {}", alphabet); | Bash/Shell | Bloc | Yes\* | | C | Import | No | | C++ | Import | No | +| C# | Bloc | No | | Clojure | Bloc | Yes \*\* | | Coffeescript | Bloc | No | | D | Bloc | No | diff --git a/docs/sources/interpreters/CSharp_original b/docs/sources/interpreters/CSharp_original new file mode 100644 index 00000000..4d12cc46 --- /dev/null +++ b/docs/sources/interpreters/CSharp_original @@ -0,0 +1,18 @@ +## C# original + +This interpreter require the `mono` toolbox to be installed: `csc` and `mono` must be in your $PATH + +a custom compiler can be specified : + +``` +require'sniprun'.setup({ + interpreter_options = { + CSharp_original = { + compiler = "csc" + } + } + } +}) +``` + + From 3f31f045a324f4bf8e16adf9d64d9105f50763e5 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 27 Dec 2022 20:37:01 +0100 Subject: [PATCH 11/19] fix for julia just in case julia's REPL stderr is fixed one day --- src/interpreters/Julia_original.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index 97df62b0..67b9f9f0 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -282,7 +282,7 @@ impl ReplLikeInterpreter for Julia_original { let end_mark_err = String::from("println(stderr, \"sniprun_finished_id=") + &self.current_output_id.to_string() + "\")\n"; - self.code = start_mark + &self.code + "\n" + &end_mark; + self.code = start_mark + &start_mark_err + "\n" + &self.code + "\n" + &end_mark_err + &end_mark; Ok(()) } From b4139f85155e774ee7e606f79d9b8cb55691446b Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 27 Dec 2022 20:48:31 +0100 Subject: [PATCH 12/19] changelog, update and stuff --- CHANGELOG.md | 8 ++- CHECKLIST.md | 2 +- Cargo.lock | 135 ++++++++++++++++------------------------- docs/sources/README.md | 2 +- src/lib.rs | 12 +++- 5 files changed, 71 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b7c49bf..377b4564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ +## v1.2.9 +- Elixir support (with REPL capabilities) +- C# support +- "--project"-aware Julia interpreter +- Fixed Julia REPL capabilities (fifo in Julia_original, in addition to Julia_jupyter) + ## v1.2.8 -- remove SnipTerminate +- Remove SnipTerminate - Python_fifo3 fixes for indentation issues - HTML doc deployed from github pages - Composable/filterable display options diff --git a/CHECKLIST.md b/CHECKLIST.md index 1ec6aa6c..84119a4c 100644 --- a/CHECKLIST.md +++ b/CHECKLIST.md @@ -2,9 +2,9 @@ - check compilation success - update Cargo.lock: `cargo update` - - Bump Cargo.toml to next version - cargo fmt --all / cargo check / cargo clippy - update the changelog + - bump Cargo.toml to next version - create a version bump commit - merge - create a new tag vX.Y.Z on master diff --git a/Cargo.lock b/Cargo.lock index 72cf0a9d..99e3c525 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ "gimli", ] @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "0.7.19" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] @@ -40,9 +40,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" dependencies = [ "addr2line", "cc", @@ -67,9 +67,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.74" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cfg-if" @@ -216,9 +216,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.26.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" +checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" [[package]] name = "hashbrown" @@ -228,9 +228,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "lazy_static" @@ -240,9 +240,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.137" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "lock_api" @@ -281,9 +281,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "miniz_oxide" -version = "0.5.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" dependencies = [ "adler", ] @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "object" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb" dependencies = [ "memchr", ] @@ -336,9 +336,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" +checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" dependencies = [ "cfg-if 1.0.0", "libc", @@ -349,9 +349,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" [[package]] name = "pin-project-lite" @@ -365,44 +365,20 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -435,9 +411,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "aho-corasick", "memchr", @@ -446,9 +422,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "rmp" @@ -481,9 +457,9 @@ checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "scopeguard" @@ -493,24 +469,24 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" [[package]] name = "serde_bytes" -version = "0.11.7" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" +checksum = "718dc5fff5b36f99093fc49b280cfc96ce6fc824317783bff5a1fed0c7a64819" dependencies = [ "serde", ] [[package]] name = "serde_json" -version = "1.0.87" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ "itoa", "ryu", @@ -519,9 +495,9 @@ dependencies = [ [[package]] name = "serial_test" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92761393ee4dc3ff8f4af487bd58f4307c9329bbedea02cac0089ad9c411e153" +checksum = "1c789ec87f4687d022a2405cf46e0cd6284889f1839de292cadeb6c6019506f2" dependencies = [ "dashmap", "futures", @@ -533,11 +509,10 @@ dependencies = [ [[package]] name = "serial_test_derive" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6f5d1c3087fb119617cff2966fe3808a80e5eb59a8c1601d5994d66f4346a5" +checksum = "b64f9e531ce97c88b4778aad0ceee079216071cffec6ac9b904277f8f92e7fe3" dependencies = [ - "proc-macro-error", "proc-macro2", "quote", "syn", @@ -599,9 +574,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.103" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -610,18 +585,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", @@ -641,15 +616,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unindent" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ee9362deb4a96cef4d437d1ad49cffc9b9e92d202b6995674e928ce684f112" +checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" [[package]] name = "unix_socket" @@ -667,12 +642,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "vte" version = "0.10.1" diff --git a/docs/sources/README.md b/docs/sources/README.md index 02a971c7..9cc31f92 100755 --- a/docs/sources/README.md +++ b/docs/sources/README.md @@ -79,7 +79,7 @@ Sniprun will then: - [optional] the plugin [nvim-notify](https://github.com/rcarriga/nvim-notify) for the notification display style -- **Compiler / interpreter** for the languages you work with must be installed & on your \$PATH. In case specific build tools or softwares are required, those are documented in the [docs/sources/interpreters](https://github.com/michaelb/sniprun/tree/master/doc) folder, for each interpreter, which I urge you to get a look at before getting started as it also contains the potential limitations of each interpreter; this information can be accessed through `:SnipInfo ` (tab autocompletion supported). +- **Compiler / interpreter** for the languages you work with must be installed & on your \$PATH. In case specific build tools or softwares are required, those are documented in the navigation pane of this wiki, as well as in the [docs/sources/interpreters](https://github.com/michaelb/sniprun/tree/master/doc) folder, for each interpreter, which I urge you to get a look at before getting started as it also contains the potential limitations of each interpreter; this information can be accessed through `:SnipInfo ` (tab autocompletion supported). diff --git a/src/lib.rs b/src/lib.rs index 36ff14f8..6a710d07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -252,10 +252,18 @@ impl EventHandler { { //get neovim's current directory - let nvim_cwd = self.nvim.lock().unwrap().call_function("getcwd", vec![]).unwrap(); + let nvim_cwd = self + .nvim + .lock() + .unwrap() + .call_function("getcwd", vec![]) + .unwrap(); info!("nvimcwd as value: nvim_cwd: {:?}", nvim_cwd); self.data.projectroot = String::from(nvim_cwd.as_str().unwrap()); - info!("[FILLDATA] got neovim's current directory: {}", self.data.projectroot); + info!( + "[FILLDATA] got neovim's current directory: {}", + self.data.projectroot + ); } { From f781227cfbcb27b8af6baedb6d258c03a48fa260 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 27 Dec 2022 21:12:45 +0100 Subject: [PATCH 13/19] update c# test and add c# and elixir to ci install --- ressources/install_all_compilers_ci.sh | 14 ++++++++++++++ src/interpreters/CSharp_original.rs | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ressources/install_all_compilers_ci.sh b/ressources/install_all_compilers_ci.sh index 6f84d9b6..035cc56e 100755 --- a/ressources/install_all_compilers_ci.sh +++ b/ressources/install_all_compilers_ci.sh @@ -76,6 +76,20 @@ then export PATH=$PATH:$HOME/golang/go/bin/ fi +if ! command -v elixir &> /dev/null +then + sudo apt-get install esl-erlang elixir -y +fi + +if ! command -v mono &> /dev/null +then + sudo apt-get install dirmngr gnupg apt-transport-https ca-certificates -y + sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF + sudo apt-add-repository 'deb https://download.mono-project.com/repo/ubuntu stable-bionic main' + sudo apt-get update + sudo apt-get install mono-complete -y +fi + # deno for typescript and javascript # cargo install deno --locked # too long, takes 20 min! curl -fsSL https://deno.land/x/install/install.sh | sh diff --git a/src/interpreters/CSharp_original.rs b/src/interpreters/CSharp_original.rs index 8944f0e4..849405a1 100644 --- a/src/interpreters/CSharp_original.rs +++ b/src/interpreters/CSharp_original.rs @@ -185,12 +185,12 @@ mod test_csharp_original { #[test] fn simple_print() { let mut data = DataHolder::new(); - data.current_bloc = String::from("println!(\"HW, 1+1 = {}\", 1+1);"); + data.current_bloc = String::from("Console.WriteLine(\"Hello World!\");"); let mut interpreter = CSharp_original::new(data); let res = interpreter.run(); // should panic if not an Ok() let string_result = res.unwrap(); - assert_eq!(string_result, "HW, 1+1 = 2\n"); + assert_eq!(string_result, "Hello World!\n"); } } From b4250b6725e4df18e25cf0dad0825d8b197ad344 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Tue, 27 Dec 2022 22:45:26 +0100 Subject: [PATCH 14/19] install elixir in CI --- ressources/install_all_compilers_ci.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ressources/install_all_compilers_ci.sh b/ressources/install_all_compilers_ci.sh index 035cc56e..f1fb041e 100755 --- a/ressources/install_all_compilers_ci.sh +++ b/ressources/install_all_compilers_ci.sh @@ -78,6 +78,11 @@ fi if ! command -v elixir &> /dev/null then + sudo apt-get purge elixir + sudo apt-get purge esl-erlang + wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc + sudo apt-key add erlang_solutions.asc + sudo apt-get update sudo apt-get install esl-erlang elixir -y fi From 987d4134dbcee8a1917742131b76e02fd46a45b9 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 28 Dec 2022 19:15:14 +0100 Subject: [PATCH 15/19] install elixir in CI --- .github/workflows/rust.yml | 2 +- ressources/install_all_compilers_ci.sh | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 363eaf5a..dc29f7bc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -52,7 +52,7 @@ jobs: - run: './ressources/install_all_compilers_ci.sh' - uses: dlang-community/setup-dlang@v1 - + - uses: actions/setup-elixir@v1 - name: Unit tests diff --git a/ressources/install_all_compilers_ci.sh b/ressources/install_all_compilers_ci.sh index f1fb041e..18000416 100755 --- a/ressources/install_all_compilers_ci.sh +++ b/ressources/install_all_compilers_ci.sh @@ -76,16 +76,6 @@ then export PATH=$PATH:$HOME/golang/go/bin/ fi -if ! command -v elixir &> /dev/null -then - sudo apt-get purge elixir - sudo apt-get purge esl-erlang - wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc - sudo apt-key add erlang_solutions.asc - sudo apt-get update - sudo apt-get install esl-erlang elixir -y -fi - if ! command -v mono &> /dev/null then sudo apt-get install dirmngr gnupg apt-transport-https ca-certificates -y From 4199cf4f98730ba364d16cfb2fe543baf45d55b0 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 28 Dec 2022 19:26:43 +0100 Subject: [PATCH 16/19] up to date install elixir action --- .github/workflows/rust.yml | 4 ++++ README.md | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dc29f7bc..9cf10907 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -52,7 +52,11 @@ jobs: - run: './ressources/install_all_compilers_ci.sh' - uses: dlang-community/setup-dlang@v1 + - uses: actions/setup-elixir@v1 + - uses: erlef/setup-beam@v1 + with: + elixir-version: "1.14" - name: Unit tests diff --git a/README.md b/README.md index ff79d155..631fe51b 100755 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ Sniprun is a code runner plugin for neovim written in Lua and Rust. It aims to p TLDR: `Plug 'michaelb/sniprun', {'do': 'bash install.sh'}`, `:SnipRun`, `:'<,'>SnipRun`, `:SnipInfo` -See [installation instructions](https://michaelb.github.io/sniprun/sources/README.html#installation), [configuration tips](https://michaelb.github.io/sniprun/sources/README.html#configuration), [usage explanations (recommended)](https://michaelb.github.io/sniprun/sources/README.html#usage) and much more useful information on the [wiki](https://michaelb.github.io/sniprun/) +# Installation, configuration, ... + +See [installation instructions](https://michaelb.github.io/sniprun/sources/README.html#installation), [configuration tips](https://michaelb.github.io/sniprun/sources/README.html#configuration), [usage explanations](https://michaelb.github.io/sniprun/sources/README.html#usage) and much more useful information on the [wiki](https://michaelb.github.io/sniprun/) ## Demos From 47e86fa6a4c7a5f9c538c9b6f68013ef95a93221 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 28 Dec 2022 19:31:27 +0100 Subject: [PATCH 17/19] remove old action elixir --- .github/workflows/release.yml | 2 ++ .github/workflows/rust.yml | 8 ++++---- README.md | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 47a394e7..66025fce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,5 @@ +name: Release + on: push: tags: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9cf10907..be3f076f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -43,7 +43,7 @@ jobs: run: cargo build --release --target x86_64-unknown-linux-gnu unittest: - name: Unit & integration tests + name: unit & integration tests runs-on: ubuntu-20.04 steps: @@ -53,16 +53,16 @@ jobs: - uses: dlang-community/setup-dlang@v1 - - uses: actions/setup-elixir@v1 - uses: erlef/setup-beam@v1 with: + otp-version: "23" elixir-version: "1.14" - name: Unit tests run: cargo test --release --features ignore_in_ci - - name: Integration tests + - name: integration tests run: cargo test --release --features ignore_in_ci --test integration @@ -73,7 +73,7 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: Installation tests + - name: installation tests run: ./install.sh diff --git a/README.md b/README.md index 631fe51b..5c8630b5 100755 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ TLDR: `Plug 'michaelb/sniprun', {'do': 'bash install.sh'}`, `:SnipRun`, `:'<,'>S See [installation instructions](https://michaelb.github.io/sniprun/sources/README.html#installation), [configuration tips](https://michaelb.github.io/sniprun/sources/README.html#configuration), [usage explanations](https://michaelb.github.io/sniprun/sources/README.html#usage) and much more useful information on the [wiki](https://michaelb.github.io/sniprun/) +[![wiki status](https://github.com/michaelb/sniprun/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/michaelb/sniprun/actions/workflows/pages/pages-build-deployment) + ## Demos ##### Send to Sniprun snippets of any language. From 0bcce03d04bbbc8b2e28dbcfa4a20486bb4dbb49 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 28 Dec 2022 19:42:26 +0100 Subject: [PATCH 18/19] small doc fix --- docs/sources/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sources/README.md b/docs/sources/README.md index 6f0095e0..901f6639 100755 --- a/docs/sources/README.md +++ b/docs/sources/README.md @@ -71,7 +71,7 @@ Sniprun will then: ## Prerequisites && dependencies -- Sniprun is compatible with **Linux** and **MacOS**. (Mac users _need_ the Rust [toolchain](https://www.rust-lang.org/tools/install)) >= 1.59 +- Sniprun is compatible with **Linux** and **MacOS**. (Mac users _need_ the Rust [toolchain](https://www.rust-lang.org/tools/install) version >= 1.59 ) - **Neovim** version >= 0.5 @@ -87,7 +87,7 @@ Sniprun will then: (Run `install.sh` as a post-installation script, it will download or compile the sniprun binary) -
vim-plug +
vim-plug

```vim @@ -100,7 +100,7 @@ Plug 'michaelb/sniprun', {'do': 'bash ./install.sh'}

-
packer +
packer

``` From ec998eb6a580521a5382ceec78084b8ec50be574 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 28 Dec 2022 19:49:45 +0100 Subject: [PATCH 19/19] version bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e6554614..4dd70cf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.2.8" +version = "1.2.9" authors = ["michaelb "] rust-version="1.55" edition = "2018"