diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f8af1..354ef29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.3.8 +- Fix Python3_jupyter +- Allow opening terminal in horizontal split +- Compiles locally by default (when on dev branch) + ## v1.3.7 - Fix issue in multiple languages when last line is a comment - Install instructions for lazy.nvim/Lunarvim diff --git a/CHECKLIST.md b/CHECKLIST.md index f5cc6d0..7bd47fc 100644 --- a/CHECKLIST.md +++ b/CHECKLIST.md @@ -4,11 +4,11 @@ # Prepare the release ## on dev branch - - update Cargo.lock: `cargo update` (but do not break MSRV, so do it package by package and check with MSRV toolchain) - check compilation success - cargo fmt --all / cargo check / cargo clippy - update the changelog - remove the 'beta' from the version field in Cargo.toml + - `cargo update --offline` # update sniprun's versino in committed Cargo.lock ## Merge process - create a PR dev -> master diff --git a/Cargo.lock b/Cargo.lock index b189875..c225548 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,9 +67,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" [[package]] name = "byteorder" @@ -341,9 +341,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" dependencies = [ "wasm-bindgen", ] @@ -745,7 +745,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -781,7 +781,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -812,7 +812,7 @@ checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "sniprun" -version = "1.3.7" +version = "1.3.8" dependencies = [ "close_fds", "dirs", @@ -845,6 +845,17 @@ dependencies = [ "vte", ] +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.38" @@ -873,7 +884,7 @@ checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -1010,9 +1021,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -1020,24 +1031,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" dependencies = [ "bumpalo", + "lazy_static", "log", - "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1045,28 +1056,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index b147ede..2d5df9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.3.7" +version = "1.3.8" authors = ["michaelb "] rust-version = "1.65" edition = "2018" diff --git a/README.md b/README.md index ea8db8c..4776670 100755 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ - # 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** [languages](https://michaelb.github.io/sniprun/sources/README.html#support-levels-and-languages). Sniprun blurs the line between standard save/run workflow, jupyter-like notebook, and REPL/interpreters. diff --git a/doc/sources/README.md b/doc/sources/README.md index 432a15b..475b3cf 100755 --- a/doc/sources/README.md +++ b/doc/sources/README.md @@ -95,7 +95,7 @@ Sniprun will then: use { 'michaelb/sniprun', run = 'sh ./install.sh'} ``` -(or likewise, `'sh ./install.sh 1'` to get the bleeding edge aka compile yourself the latest commit of sniprun) +(if you target the 'dev' branch, the installer will try to compile manually sniprun on your computer, which will require the rust toolchain)

@@ -275,7 +275,9 @@ require'sniprun'.setup({ terminal_line_number = false, --# whether show line number in terminal window terminal_signcolumn = false, --# whether show signcolumn in terminal window terminal_persistence = true, --# always keep the terminal open (true) or close it at every occasion (false) - terminal_width = 45, --# change the terminal display option width + terminal_position = "vertical", --# or "horizontal", to open as horizontal split instead of vertical split + terminal_width = 45, --# change the terminal display option width (if vertical) + terminal_height = 20, --# change the terminal display option height (if horizontal) notification_timeout = 5 --# timeout for nvim_notify output }, diff --git a/doc/sources/display_modes.md b/doc/sources/display_modes.md index 418ad16..e5b4f9b 100644 --- a/doc/sources/display_modes.md +++ b/doc/sources/display_modes.md @@ -128,7 +128,9 @@ require'sniprun'.setup({ terminal_scrollback = vim.o.scrollback, -- change terminal display scrollback lines terminal_line_number = false, -- whether show line number in terminal window terminal_signcolumn = false, -- whether show signcolumn in terminal window - terminal_width = 45, + terminal_position = "vertical", --# or "horizontal", to open as horizontal split instead of vertical split + terminal_width = 45, --# change the terminal display option width (if vertical) + terminal_height = 20, --# change the terminal display option height (if horizontal) }, }) EOF diff --git a/doc/sources/interpreters/Generic.md b/doc/sources/interpreters/Generic.md index 160c865..79b1039 100644 --- a/doc/sources/interpreters/Generic.md +++ b/doc/sources/interpreters/Generic.md @@ -46,7 +46,8 @@ require'sniprun'.setup({ compiler = "", exe_name = "", - boilerplate = "" + boilerplate_pre = "" + boilerplate_post = "" }, my_super_c_config = { @@ -68,6 +69,22 @@ require'sniprun'.setup({ }) ``` +### How the generic interpreter works + +#### For interpreted languages ("interpreter" is set) + +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 file with the given extension, named `_src.` +4. Sniprun runs ` .` and displays the stdout/stderr + +#### For compiled languages ("compiler" is set) + +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 +5. Sniprun runs `./` and displays the stdout/stderr ### Community examples for non-officially supported languages diff --git a/doc/sources/interpreters/Python3_jupyter.md b/doc/sources/interpreters/Python3_jupyter.md index 44c6e67..cefdc12 100644 --- a/doc/sources/interpreters/Python3_jupyter.md +++ b/doc/sources/interpreters/Python3_jupyter.md @@ -1,5 +1,8 @@ ## 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 + ### Dependencies - jupyter diff --git a/install.sh b/install.sh index d6417c3..3ca2a4a 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,18 @@ echo "Runnning Sniprun Installer" 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 + force_build=1 +fi + +arch=$(uname) +if [ "$arch" != "Linux" ] && [ "$force_build" != 1 ]; then + echo "Looks you are not running Linux: Mac users have to compile sniprun themselves and thus need the Rust toolchain" + force_build=1 +fi cargo_build() { if command -v cargo >/dev/null; then @@ -39,11 +50,6 @@ fetch_prebuilt_binary() { fi } -arch=$(uname) -if [ "$arch" != "Linux" ] && [ "$force_build" != 1 ]; then - echo "Looks you are not running Linux: Mac users have to compile sniprun themselves and thus need the Rust toolchain" - force_build=1 -fi remote_version=$(get_latest_release) diff --git a/lua/sniprun.lua b/lua/sniprun.lua index 17febfb..c9b811f 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -38,7 +38,9 @@ M.config_values = { terminal_scrollback = vim.o.scrollback, -- change terminal display scrollback lines terminal_line_number = false, -- whether show line number in terminal window terminal_signcolumn = false, -- whether show signcolumn in terminal window - terminal_width = 45, -- change the terminal display option width + terminal_position = "vertical", -- or "horizontal" + terminal_width = 45, -- change the terminal display option width (if vertical) + terminal_height = 20, -- change the terminal display option heigth (if horizontal) terminal_persistence = true, -- always keep the terminal open (true) or close it at every occasion (false) notification_timeout = 5 -- timeout for nvim_notify output }, diff --git a/lua/sniprun/display.lua b/lua/sniprun/display.lua index a58ed47..00b8c91 100644 --- a/lua/sniprun/display.lua +++ b/lua/sniprun/display.lua @@ -36,8 +36,14 @@ function M.term_set_window_handle() local winid = vim.fn.bufwinid(M.term.buffer) if winid ~= -1 then return end - local width = require("sniprun").config_values.display_options.terminal_width - vim.cmd(":rightb " .. width .. "vsplit") + local location = require("sniprun").config_values.display_options.terminal_position + if location == "horizontal" then + local height = require("sniprun").config_values.display_options.terminal_height or 20 + vim.cmd(":rightb " .. height .. "split") + else + local width = require("sniprun").config_values.display_options.terminal_width or 45 + vim.cmd(":rightb " .. width .. "vsplit") + end M.term.window_handle = vim.api.nvim_get_current_win() -- return to doc buffer diff --git a/src/interpreters/Generic.rs b/src/interpreters/Generic.rs index 34b2916..1deafdc 100644 --- a/src/interpreters/Generic.rs +++ b/src/interpreters/Generic.rs @@ -181,7 +181,7 @@ impl Interpreter for Generic { .create(&rwd) .expect("Could not create directory for generic/"); let exe_path = rwd.clone() + "/" + &exe_name; - let main_file_path = exe_path.clone() + "_src123456789src" + &extension; // this way, virtually impossible for the user for have exe & main file with same name by accident + let main_file_path = exe_path.clone() + "_src" + &extension; // this way, impossible for the user for have exe & main file with same name by accident Box::new(Generic { data, support_level, diff --git a/src/interpreters/Python3_jupyter.rs b/src/interpreters/Python3_jupyter.rs index 724ba92..92e938f 100644 --- a/src/interpreters/Python3_jupyter.rs +++ b/src/interpreters/Python3_jupyter.rs @@ -85,24 +85,24 @@ impl Python3_jupyter { } false } - // /// In theory, is a good idea, but somehow doesn't work - // fn wait_on_kernel(&self) -> Result<(), SniprunError> { - // let step = std::time::Duration::from_millis(100); - // let mut timeout = std::time::Duration::from_millis(15000); - // loop { - // if let Ok(content) = std::fs::read_to_string(&self.kernel_file) { - // if !content.is_empty() { - // return Ok(()); - // } - // } - // std::thread::sleep(step); - // if let Some(remaining) = timeout.checked_sub(step) { - // timeout = remaining; - // } else { - // return Err(SniprunError::CustomError(String::from("Timeout on jupyter kernel start expired"))); - // } - // } - // } + /// In theory, is a good idea, but somehow doesn't work + fn wait_on_kernel(&self) -> Result<(), SniprunError> { + let step = std::time::Duration::from_millis(100); + let mut timeout = std::time::Duration::from_millis(15000); + loop { + if let Ok(content) = std::fs::read_to_string(&self.kernel_file) { + if !content.is_empty() { + return Ok(()); + } + } + std::thread::sleep(step); + if let Some(remaining) = timeout.checked_sub(step) { + timeout = remaining; + } else { + return Err(SniprunError::CustomError(String::from("Timeout on jupyter kernel start expired"))); + } + } + } } impl Interpreter for Python3_jupyter { @@ -313,8 +313,7 @@ impl ReplLikeInterpreter for Python3_jupyter { + " --no-confirm" + " " + "--ZMQTerminalInteractiveShell.banner=\"\"" - + " " - + "--Application.log_level=0"; + + "\n"; write(&self.launcher_path, &actual_command) .expect("Unable to write file for python3_jupyter"); @@ -329,7 +328,7 @@ impl ReplLikeInterpreter for Python3_jupyter { "json kernel file exists yet? {}", std::path::Path::new(&self.kernel_file).exists() ); - // self.wait_on_kernel()?; + self.wait_on_kernel()?; let output = Command::new("sh") .arg(&self.launcher_path) @@ -340,10 +339,12 @@ impl ReplLikeInterpreter for Python3_jupyter { info!("result: {:?}", cleaned_result); - // first and last lines are the [In] x: prompts from jupyter-console - cleaned_result.remove(cleaned_result.len() - 1); - cleaned_result.remove(1); - cleaned_result.remove(0); + if cleaned_result.len() >= 3 { + // first and last lines are the [In] x: prompts from jupyter-console + cleaned_result.remove(cleaned_result.len() - 1); + cleaned_result.remove(1); + cleaned_result.remove(0); + } info!("cleaned result: {:?}", cleaned_result); if String::from_utf8(output.stderr.clone()).unwrap().is_empty() {