diff --git a/CHANGELOG.md b/CHANGELOG.md index ea64c91b..a95d70b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v1.2.7 +- Fix bug where the display configuration was overwritten by live mode activation +- Fix bug where REPL interpreter would get instantly stopped on MacOS +- Mark SnipTerminate for deprecation, will be removed in a future release +- Narrower and aligned SnipInfo + ## v1.2.6 - Clojure support (REPL-capable) - Improved & simplified CI diff --git a/Cargo.lock b/Cargo.lock index 19d12e74..7f740d33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -47,6 +47,29 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "close_fds" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bc416f33de9d59e79e57560f450d21ff8393adcf1cdfc3e6d8fb93d5f88a2ed" +dependencies = [ + "cfg-if 1.0.0", + "libc", +] + +[[package]] +name = "dashmap" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "dirs" version = "4.0.0" @@ -69,9 +92,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" +checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" dependencies = [ "futures-channel", "futures-core", @@ -84,9 +107,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", "futures-sink", @@ -94,15 +117,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-executor" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" +checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" dependencies = [ "futures-core", "futures-task", @@ -111,27 +134,27 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-channel", "futures-core", @@ -155,11 +178,17 @@ dependencies = [ "wasi", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "lazy_static" @@ -169,15 +198,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" dependencies = [ "autocfg", "scopeguard", @@ -219,6 +248,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" + [[package]] name = "parking_lot" version = "0.12.1" @@ -237,16 +272,16 @@ checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.2.15", + "redox_syscall 0.2.16", "smallvec", "windows-sys", ] [[package]] name = "paste" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" [[package]] name = "pin-project-lite" @@ -286,18 +321,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -310,9 +345,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -324,7 +359,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom", - "redox_syscall 0.2.15", + "redox_syscall 0.2.16", "thiserror", ] @@ -368,17 +403,11 @@ dependencies = [ "serde_bytes", ] -[[package]] -name = "rustversion" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c8ad4f0c00e1eb5bc7614d236a7f1300e3dbd76b68cac8e06fb00b015ad8d8" - [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "scopeguard" @@ -388,24 +417,24 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" [[package]] name = "serde_bytes" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" +checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" dependencies = [ "serde", ] [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -414,10 +443,11 @@ dependencies = [ [[package]] name = "serial_test" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eec42e7232e5ca56aa59d63af3c7f991fe71ee6a3ddd2d3480834cf3902b007" +checksum = "92761393ee4dc3ff8f4af487bd58f4307c9329bbedea02cac0089ad9c411e153" dependencies = [ + "dashmap", "futures", "lazy_static", "log", @@ -427,14 +457,13 @@ dependencies = [ [[package]] name = "serial_test_derive" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1b95bb2f4f624565e8fe8140c789af7e2082c0e0561b5a82a1b678baa9703dc" +checksum = "4b6f5d1c3087fb119617cff2966fe3808a80e5eb59a8c1601d5994d66f4346a5" dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "rustversion", "syn", ] @@ -468,6 +497,7 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" name = "sniprun" version = "1.2.6" dependencies = [ + "close_fds", "dirs", "libc", "log", @@ -492,9 +522,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = [ "proc-macro2", "quote", @@ -503,18 +533,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "8c1b05ca9d106ba7d2e31a9dab4a64e7be2cce415321966ea3132c49a656e252" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487" dependencies = [ "proc-macro2", "quote", @@ -534,15 +564,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unindent" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52fee519a3e570f7df377a06a1a7775cdbfb7aa460be7e08de2b1f0e69973a44" +checksum = "58ee9362deb4a96cef4d437d1ad49cffc9b9e92d202b6995674e928ce684f112" [[package]] name = "unix_socket" diff --git a/Cargo.toml b/Cargo.toml index 016bde18..30f85daf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.2.6" +version = "1.2.7" authors = ["michaelb "] rust-version="1.31" edition = "2018" @@ -15,6 +15,7 @@ ignore_in_ci = [] neovim-lib="*" log="*" simple-logging="*" +close_fds="*" thiserror="*" dirs="*" regex="*" diff --git a/doc/JS_TS_deno.md b/doc/JS_TS_deno.md new file mode 100644 index 00000000..7668bdc6 --- /dev/null +++ b/doc/JS_TS_deno.md @@ -0,0 +1,12 @@ +# JS_TS_Deno + +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` + +``` +require('sniprun').setup({ + selected_interpreters={"JS_TS_deno"}, + repl_enable={"JS_TS_deno"} +}) +``` diff --git a/doc/sniprun.txt b/doc/sniprun.txt index 472fcd66..07270537 100644 --- a/doc/sniprun.txt +++ b/doc/sniprun.txt @@ -40,8 +40,6 @@ ALL COMMANDS *sniprun-commands* :SnipReplMemoryClean If you sent incorrect code to a interpreter with enabled REPL mode, you can clear the REPL 'memory' with that. It will forget all variables you have defined previously etc.. -:SnipTerminate Kill Sniprun and child processes (equivalent to SnipReset but does not clean the cache) - :SnipInfo Get Sniprun version info and info about the available interpreters :SnipClose Clear virtual text and close splits and floating windows created by sniprun diff --git a/lua/sniprun.lua b/lua/sniprun.lua index 6872cd3a..93e1147b 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -171,13 +171,13 @@ function M.configure_keymaps() vim.api.nvim_set_keymap("v", "SnipRun", ":lua require'sniprun'.run('v')", {silent=true}) vim.api.nvim_set_keymap("n", "SnipRun", ":lua require'sniprun'.run()",{silent=true}) vim.api.nvim_set_keymap("n", "SnipRunOperator", ":set opfunc=SnipRunOperatorg@",{silent=true}) - vim.api.nvim_set_keymap("n", "SnipRTerminate", ":lua require'sniprun'.terminate()",{silent=true}) + vim.api.nvim_set_keymap("n", "SnipRTerminate", ":lua require'sniprun'.terminate() ; print('warning: SnipTerminate will be deprecated in the next release. Use SnipReset instead') ",{silent=true}) vim.api.nvim_set_keymap("n", "SnipReset", ":lua require'sniprun'.reset()",{silent=true}) vim.api.nvim_set_keymap("n", "SnipInfo", ":lua require'sniprun'.info()",{}) vim.api.nvim_set_keymap("n", "SnipReplMemoryClean", ":lua require'sniprun'.clear_repl()",{silent=true}) vim.api.nvim_set_keymap("n", "SnipClose", ":lua require'sniprun.display'.close_all()",{silent=true}) - vim.cmd("command! SnipTerminate :lua require'sniprun'.terminate()") + vim.cmd("command! SnipTerminate :lua require'sniprun'.terminate() ; print('warning: SnipTerminate will be deprecated in the next release. Use SnipReset instead') ") vim.cmd("command! SnipReset :lua require'sniprun'.reset()") vim.cmd("command! SnipReplMemoryClean :lua require'sniprun'.clear_repl()") vim.cmd("function! SnipRunOperator(...) \n lua require'sniprun'.run('n') \n endfunction") diff --git a/lua/sniprun/live_mode.lua b/lua/sniprun/live_mode.lua index c918f7a7..bff902e0 100644 --- a/lua/sniprun/live_mode.lua +++ b/lua/sniprun/live_mode.lua @@ -1,11 +1,26 @@ local M = {} +function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + +end function M.run() local sa = require('sniprun.api') local line = vim.api.nvim_win_get_cursor(0)[1] local ft = vim.bo.filetype - local opts = require('sniprun').config_values + local opts = deepcopy(require('sniprun').config_values) opts.display = { "VirtualTextOk"} opts.show_no_output = {} sa.run_range(line,line, ft, opts) diff --git a/ressources/init_repl.sh b/ressources/init_repl.sh index 2e6264de..9d4750b4 100644 --- a/ressources/init_repl.sh +++ b/ressources/init_repl.sh @@ -1,23 +1,35 @@ #!/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" >> $working_dir/log + echo "process already present" >> $log exit 1 fi + pipe=pipe_in out=out_file err=err_file +nvim_pid=$2 -repl="$2" +shift 2 +repl="$@" # the rest rm -rf $working_dir/ mkdir -p $working_dir -echo "setting up things" > $working_dir/log +echo "pid of parent neovim session is $nvim_pid" >> $log +echo "setting up things" >> $log mkfifo $working_dir/$pipe touch $working_dir/$out @@ -26,22 +38,22 @@ 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")." >> $working_dir/log +echo $repl " process started at $(date +"%F %T")." >> $log bash $working_dir/real_launcher.sh > $working_dir/$out 2> $working_dir/$err & -echo "done_logged" >> $working_dir/log +echo "done" >> $log +# wait for the parent nvim process to exit, then kill the sniprun process that launched this script - -while pkill -0 nvim ;do +while ps -p $nvim_pid ;do sleep 1 done -rm -rf $working_dir pkill -P $$ -echo $repl " and other backoung process terminated at $(date +"%F %T")." >> $working_dir/log +echo $repl " and other backoung process terminated at $(date +"%F %T")." >> $log +rm -rf $working_dir diff --git a/src/daemonizer.rs b/src/daemonizer.rs index 192b14ef..86661aa5 100644 --- a/src/daemonizer.rs +++ b/src/daemonizer.rs @@ -46,6 +46,13 @@ pub fn daemon() -> Result { Ok(Fork::Parent(child_pid)) => Ok(Fork::Parent(child_pid)), Ok(Fork::Child) => setsid().and_then(|_| { close_fd()?; + // close additionnal fds (logs, socket ?) + let keep_fds = []; + + unsafe { + close_fds::close_open_fds(3, &keep_fds); + }; + fork() }), Err(n) => Err(n), diff --git a/src/interpreter.rs b/src/interpreter.rs index abab8f32..b0fda31f 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -25,7 +25,7 @@ pub enum 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("Unsupported"), + SupportLevel::Unsupported => f.write_str("None"), SupportLevel::Line => f.write_str("Line"), SupportLevel::Bloc => f.write_str("Bloc"), SupportLevel::Import => f.write_str("Import"), @@ -65,6 +65,11 @@ pub trait Interpreter: ReplLikeInterpreter { fn set_current_level(&mut self, level: SupportLevel); fn get_data(&self) -> DataHolder; + fn get_nvim_pid(data: &DataHolder) -> String { + // associated utility function + data.nvim_pid.to_string() + } + /// You should override this method as soon as you wish to test your interpreter. fn get_max_support_level() -> SupportLevel { //to overwrite in trait impls diff --git a/src/interpreters/Clojure_fifo.rs b/src/interpreters/Clojure_fifo.rs index e72faadc..8b68b2d9 100644 --- a/src/interpreters/Clojure_fifo.rs +++ b/src/interpreters/Clojure_fifo.rs @@ -96,10 +96,6 @@ impl Clojure_fifo { } } - fn get_nvim_pid(data: &DataHolder) -> String { - data.nvim_pid.to_string() - } - fn fetch_config(&mut self) { let default_interpreter_repl = String::from("clojure -e \"(clojure.main/repl :prompt (defn f[] (\"\")) )\""); @@ -287,11 +283,9 @@ impl ReplLikeInterpreter for Clojure_fifo { ]) .output() .unwrap(); - let pause = std::time::Duration::from_millis(36_000_000); - std::thread::sleep(pause); return Err(SniprunError::CustomError( - "Timeout expired for clojure REPL".to_owned(), + "clojure REPL exited".to_owned(), )); } Ok(Fork::Parent(_)) => {} diff --git a/src/interpreters/FSharp_fifo.rs b/src/interpreters/FSharp_fifo.rs index 106623cf..2329b0d7 100644 --- a/src/interpreters/FSharp_fifo.rs +++ b/src/interpreters/FSharp_fifo.rs @@ -94,10 +94,6 @@ impl FSharp_fifo { } } - fn get_nvim_pid(data: &DataHolder) -> String { - data.nvim_pid.to_string() - } - fn fetch_config(&mut self) { let default_interpreter = String::from("dotnet fsi --nologo"); self.interpreter = default_interpreter; @@ -265,15 +261,14 @@ impl ReplLikeInterpreter for FSharp_fifo { .args(&[ init_repl_cmd, self.cache_dir.clone(), + FSharp_fifo::get_nvim_pid(&self.data), self.interpreter.clone(), ]) .output() .unwrap(); - let pause = std::time::Duration::from_millis(36_000_000); - std::thread::sleep(pause); return Err(SniprunError::CustomError( - "Timeout expired for dotnet fsi REPL".to_owned(), + "background dotnet fsi REPL exited".to_owned(), )); } Ok(Fork::Parent(_)) => {} diff --git a/src/interpreters/JS_TS_deno.rs b/src/interpreters/JS_TS_deno.rs index d14345ca..5c636f70 100644 --- a/src/interpreters/JS_TS_deno.rs +++ b/src/interpreters/JS_TS_deno.rs @@ -113,7 +113,7 @@ impl Interpreter for JS_TS_deno { //pre-create string pointing to main file's and binary's path let mfp = lwd.clone() + "/main.ts"; Box::new(JS_TS_deno { - cache_dir: lwd.clone() + "/" + &Python3_fifo::get_nvim_pid(&data), + cache_dir: lwd.clone() + "/" + &JS_TS_deno::get_nvim_pid(&data), data, support_level, code: String::new(), @@ -124,7 +124,7 @@ impl Interpreter for JS_TS_deno { fn get_supported_languages() -> Vec { vec![ - String::from("TS/JS via Deno"), // in 1st position of vector, used for info only + String::from("TS/JS (Deno)"), // in 1st position of vector, used for info only //':set ft?' in nvim to get the filetype of opened file String::from("typescript"), String::from("typescriptreact"), @@ -282,17 +282,14 @@ impl ReplLikeInterpreter for JS_TS_deno { .args(&[ init_repl_cmd, self.cache_dir.clone(), + JS_TS_deno::get_nvim_pid(&self.data), String::from("deno"), - String::from("repl"), - String::from("-q"), ]) .output() .unwrap(); - let pause = std::time::Duration::from_millis(36_000_000); - std::thread::sleep(pause); return Err(SniprunError::CustomError( - "Timeout expired for python3 REPL".to_owned(), + "deno REPL exited".to_owned(), )); } Ok(Fork::Parent(_)) => {} diff --git a/src/interpreters/Julia_original.rs b/src/interpreters/Julia_original.rs index 248be82e..f1d42aa9 100644 --- a/src/interpreters/Julia_original.rs +++ b/src/interpreters/Julia_original.rs @@ -21,7 +21,7 @@ impl Julia_original { ); let mut contents = String::new(); - + let mut pause = std::time::Duration::from_millis(50); loop { std::thread::sleep(pause); @@ -41,13 +41,10 @@ impl Julia_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()) } } @@ -170,7 +167,6 @@ impl Interpreter for Julia_original { String::from_utf8(output.stderr.clone()).unwrap().to_owned(), )); } - } } } @@ -206,14 +202,17 @@ impl ReplLikeInterpreter for Julia_original { match daemon() { Ok(Fork::Child) => { let _res = Command::new("bash") - .args(&[init_repl_cmd, self.cache_dir.clone(), "julia --banner=no --color=no".to_owned()]) + .args(&[ + init_repl_cmd, + self.cache_dir.clone(), + Julia_original::get_nvim_pid(&self.data), + "julia --banner=no --color=no".to_owned(), + ]) .output() .unwrap(); - let pause = std::time::Duration::from_millis(36_000_000); - std::thread::sleep(pause); return Err(SniprunError::CustomError( - "Timeout expired for julia REPL".to_owned(), + "julia REPL exited".to_owned(), )); } Ok(Fork::Parent(_)) => {} diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 378fd9aa..5dd10ded 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -105,10 +105,6 @@ impl Python3_fifo { } } - fn get_nvim_pid(data: &DataHolder) -> String { - data.nvim_pid.to_string() - } - fn fetch_imports(&mut self) -> Result<(), SniprunError> { if self.support_level < SupportLevel::Import { return Ok(()); @@ -403,16 +399,15 @@ impl ReplLikeInterpreter for Python3_fifo { .args(&[ init_repl_cmd, self.cache_dir.clone(), + Python3_fifo::get_nvim_pid(&self.data), self.interpreter.clone() + " -ic 'import sys; sys.ps1=\"\";sys.ps2=\"\"'", ]) .output() .unwrap(); - let pause = std::time::Duration::from_millis(36_000_000); - std::thread::sleep(pause); return Err(SniprunError::CustomError( - "Timeout expired for python3 REPL".to_owned(), + "python3 REPL exited".to_owned(), )); } Ok(Fork::Parent(_)) => {} diff --git a/src/interpreters/Python3_jupyter.rs b/src/interpreters/Python3_jupyter.rs index a6c68b04..5357020a 100644 --- a/src/interpreters/Python3_jupyter.rs +++ b/src/interpreters/Python3_jupyter.rs @@ -59,11 +59,6 @@ impl Python3_jupyter { Ok(()) } - #[allow(dead_code)] - fn get_nvim_pid(data: &DataHolder) -> String { - data.nvim_pid.to_string() - } - fn module_used(&self, line: &str, code: &str) -> bool { info!( "checking for python module usage: line {} in code {}", diff --git a/src/interpreters/Sage_fifo.rs b/src/interpreters/Sage_fifo.rs index ad973316..84c3d462 100644 --- a/src/interpreters/Sage_fifo.rs +++ b/src/interpreters/Sage_fifo.rs @@ -211,9 +211,6 @@ impl Sage_fifo { } false } - fn get_nvim_pid(data: &DataHolder) -> String { - data.nvim_pid.to_string() - } fn fetch_config(&mut self) { let default_interpreter = String::from("sage"); @@ -380,16 +377,15 @@ impl ReplLikeInterpreter for Sage_fifo { .args(&[ init_repl_cmd, self.cache_dir.clone(), + Sage_fifo::get_nvim_pid(&self.data), self.interpreter.clone(), nodotstage_arg.to_string(), ]) .output() .unwrap(); - let pause = std::time::Duration::from_millis(36_000_000); - std::thread::sleep(pause); return Err(SniprunError::CustomError( - "Timeout expired for sage REPL".to_owned(), + "sage REPL exited".to_owned(), )); } Ok(Fork::Parent(_)) => {} diff --git a/src/launcher.rs b/src/launcher.rs index 31643941..a5c7912b 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -135,14 +135,14 @@ impl Launcher { v.push("\nAvailable interpreters and languages".to_owned()); - let separator = "|--------------------------|---------------|---------------|-------------|------------|--------------|".to_string(); + let separator = "|----------------------|--------------|---------|-------------|------------|--------------|".to_string(); v.push(separator.clone()); - v.push("| Interpreter | Language | Support Level | Default for | REPL | REPL enabled |".to_string()); - v.push("| | | | filetype | capability | by default |".to_string()); + v.push("| Interpreter | Language | Support | Default for | REPL | REPL enabled |".to_string()); + v.push("| | | Level | filetype | capability | by default |".to_string()); let mut temp_vec = vec![]; iter_types! { - let line = format!("| {:<25}| {:<14}| {:<14}|{:^13}|{:^12}|{:^14}|", + let line = format!("| {:<21}| {:<13}| {:<8}|{:^13}|{:^12}|{:^14}|", Current::get_name(), Current::get_supported_languages().get(0).unwrap_or(&"".to_string()), Current::get_max_support_level().to_string(),