Skip to content

Commit

Permalink
Merge pull request #162 from michaelb/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
michaelb authored May 23, 2022
2 parents 09b5ac4 + a42ebde commit 9f9971e
Show file tree
Hide file tree
Showing 35 changed files with 51 additions and 99 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,26 @@ env:

jobs:
build:
name : build

name : build-latest-stable
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose --release

buildmsrv:
name: build-nightly
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install Rust 1.55 toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.55
override: true
- name: build
run: cargo build --release

buildnightly:
name: build-nightly
runs-on: ubuntu-20.04
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.2.4
- set Rust 1.55 as MSRV
- fix typo in documentation

## v1.2.3
- no signcolumn in Terminal display + fix line wrapping

Expand Down Expand Up @@ -161,7 +165,7 @@

## v0.4.3
- Rust interpreter and example now have tests
- Julia intepreter
- Julia interpreter
- example.rs interpreter


Expand Down
1 change: 1 addition & 0 deletions CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

- Check CI status
- Check Releases status
- Edit release name
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sniprun"
version = "1.2.3"
authors = ["michaelb <[email protected]>"]
rust-version="1.31"
edition = "2018"

[features]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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))
- Sniprun is compatible with **Linux** and **MacOS**. (Mac users _need_ the Rust [toolchain](https://www.rust-lang.org/tools/install)) >= 1.55

- **Neovim** version >= 0.5

Expand Down Expand Up @@ -257,7 +257,7 @@ Some languages, see support [table](README.md#support-levels-and-languages), als
This is easier/cleaner to implement on interpreted languages, but **compiled languages can have a REPL-like behavior too** using dirty tricks, or through an intrepreter such as [evcxr](https://github.com/google/evcxr), but no compiled language has REPL behavior for now.

Many interpreted languages will have this behavior enabled or disabled by default, you can change this with the
`repl_enable = { 'Intepreter_name', 'Another_one' }` and `repl_disable = {'Disabled_interpreter'}` keys in the configuration. Relevant info is available in `:SnipInfo` / `:SnipInfo <name> `
`repl_enable = { 'Interpreter_name', 'Another_one' }` and `repl_disable = {'Disabled_interpreter'}` keys in the configuration. Relevant info is available in `:SnipInfo` / `:SnipInfo <name> `


Hopefully, if something does not work, or if the 'memory' is corrupted by bad code you can clear the REPL memory with `:SnipReplMemoryClean` that is a faster and less error-prone alternative to `:SnipReset` for this use case.
Expand All @@ -277,7 +277,7 @@ require'sniprun'.setup({
repl_enable = {}, --# enable REPL-like behavior for the given interpreters
repl_disable = {}, --# disable REPL-like behavior for the given interpreters
interpreter_options = { --# intepreter-specific options, see docs / :SnipInfo <name>
interpreter_options = { --# interpreter-specific options, see docs / :SnipInfo <name>
GFM_original = {
use_on_filetypes = {"markdown.pandoc"} --# the 'use_on_filetypes' configuration key is
--# available for every interpreter
Expand Down
2 changes: 1 addition & 1 deletion doc/Python3_fifo.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ setting a custom python interpreter and venv is also supported
require'sniprun'.setup({
interpreter_options = {
Python3_fifo = {
intepreter = "python3.9",
interpreter = "python3.9",
venv = {"venv_project1", "venv_project2", "../venv_project2"},
}
}
Expand Down
4 changes: 2 additions & 2 deletions doc/Python3_original.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ With or without REPL, the star imports may also not be automatically fetched, ev



To use a custom python intepreterv( maybe python2, or a particular version?) you can provide the following interpreter options:, using a venv is also supported (provide one or several relative paths "../venv" etc.. may be necessary if you didn't open neovim at the root of the project)
To use a custom python interpreter ( maybe python2, or a particular version?) you can provide the following interpreter options:, using a venv is also supported (provide one or several relative paths "../venv" etc.. may be necessary if you didn't open neovim at the root of the project)


```
require'sniprun'.setup({
interpreter_options = {
Python3_original = {
intepreter = "python3.9",
interpreter = "python3.9",
venv = {"venv_project1", "venv_project2", "../venv_project2"},
}
}
Expand Down
2 changes: 1 addition & 1 deletion doc/sniprun.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ALL COMMANDS *sniprun-commands*

: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 intepreters
:SnipInfo Get Sniprun version info and info about the available interpreters

:SnipClose Clear virtual text and close splits and floating windows created by sniprun

Expand Down
8 changes: 4 additions & 4 deletions ressources/CONTRIBUTING_REPL.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Making a REPL-capable intepreter for sniprun
# Making a REPL-capable interpreter for sniprun

## Is it possible ?

Yes, most of the time, if the language already has an available intepreter. It _could_ be possible otherwise but has yet to be really done.
Yes, most of the time, if the language already has an available interpreter. It _could_ be possible otherwise but has yet to be really done.

To avoid confusion, we'll call the language interpreter 'interpreter', and sniprun's part (implementing the Interpreter trait) the runner.

Expand All @@ -22,7 +22,7 @@ To avoid confusion, we'll call the language interpreter 'interpreter', and snipr

The best example I'm going to discuss is Python3\_fifo, even if it's a bit bloated from python-specific things.

Just like you implemented the Intepreter trait for a conventional runner, you'll have to implement the ReplLikeInterpreter trait. Another trait (InterpreterUtils) is automatically implemented and provides features & data persistency to help you survive across different/independent runs.
Just like you implemented the Interpreter trait for a conventional runner, you'll have to implement the ReplLikeInterpreter trait. Another trait (InterpreterUtils) is automatically implemented and provides features & data persistency to help you survive across different/independent runs.

1. Running something in the background:

Expand Down Expand Up @@ -106,7 +106,7 @@ fn wait_out_file (....){
is executed & returned at the end of `execute_repl` that firsts send the user's snippet (wrapped with landmarks) to the FIFO pipe.

4. Helper scripts
Though not very documented, the `ressources/init_repl.sh` and `ressources/launcher.sh` script are resuable for other runners than Python3\_fifo (see Mathematica that has its own similar scripts in `src/interpreters/Mathematica_original/`. They take care of plugging together the fifo, stdout, stderr files and the interpreter's process. They also take care of closing the intepreter (and free the ressources) when nvim exits
Though not very documented, the `ressources/init_repl.sh` and `ressources/launcher.sh` script are resuable for other runners than Python3\_fifo (see Mathematica that has its own similar scripts in `src/interpreters/Mathematica_original/`. They take care of plugging together the fifo, stdout, stderr files and the interpreter's process. They also take care of closing the interpreter (and free the ressources) when nvim exits


### End notes:
Expand Down
6 changes: 3 additions & 3 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub trait Interpreter: ReplLikeInterpreter {
SupportLevel::Unsupported
}

/// This function should be overwritten if your intepreter cannot run
/// This function should be overwritten if your interpreter cannot run
/// all the files for the advertised filetypes.
/// It's up to you to detect it, and initialize (new()) and .run() it and return the result
fn fallback(&mut self) -> Option<Result<String, SniprunError>> {
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<T: Interpreter> InterpreterUtils for T {
}
}

/// get an intepreter option
/// get an interpreter option
fn get_interpreter_option(data: &DataHolder, option: &str) -> Option<neovim_lib::Value> {
fn index_from_name(
name: &str,
Expand Down Expand Up @@ -317,7 +317,7 @@ pub trait ReplLikeInterpreter {
}
fn execute_repl(&mut self) -> Result<String, SniprunError> {
Err(SniprunError::InterpreterLimitationError(String::from(
"REPL-like behavior is not implemented for this intepreter",
"REPL-like behavior is not implemented for this interpreter",
)))
}
}
4 changes: 1 addition & 3 deletions src/interpreters/Bash_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub struct Bash_original {
support_level: SupportLevel,
data: DataHolder,
code: String,
bash_work_dir: String,
main_file_path: String,
}

Expand All @@ -16,12 +15,11 @@ impl Interpreter for Bash_original {
builder
.create(&bwd)
.expect("Could not create directory for bash-original");
let mfp = bwd.clone() + "/main.sh";
let mfp = bwd + "/main.sh";
Box::new(Bash_original {
data,
support_level: level,
code: String::from(""),
bash_work_dir: bwd,
main_file_path: mfp,
})
}
Expand Down
4 changes: 1 addition & 3 deletions src/interpreters/CS_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub struct CS_original {
support_level: SupportLevel,
data: DataHolder,
code: String,
cs_work_dir: String,
main_file_path: String,
}
impl ReplLikeInterpreter for CS_original {}
Expand All @@ -16,12 +15,11 @@ impl Interpreter for CS_original {
builder
.create(&bwd)
.expect("Could not create directory for cs-original");
let mfp = bwd.clone() + "/main.coffee";
let mfp = bwd + "/main.coffee";
Box::new(CS_original {
data,
support_level: level,
code: String::from(""),
cs_work_dir: bwd,
main_file_path: mfp,
})
}
Expand Down
2 changes: 0 additions & 2 deletions src/interpreters/C_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub struct C_original {
support_level: SupportLevel,
data: DataHolder,
code: String,
c_work_dir: String,
bin_path: String,
main_file_path: String,
compiler: String,
Expand Down Expand Up @@ -81,7 +80,6 @@ impl Interpreter for C_original {
data,
support_level,
code: String::from(""),
c_work_dir: rwd,
bin_path: bp,
main_file_path: mfp,
compiler: String::new(),
Expand Down
2 changes: 0 additions & 2 deletions src/interpreters/Cpp_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub struct Cpp_original {
support_level: SupportLevel,
data: DataHolder,
code: String,
c_work_dir: String,
bin_path: String,
main_file_path: String,
compiler: String,
Expand Down Expand Up @@ -74,7 +73,6 @@ impl Interpreter for Cpp_original {
data,
support_level,
code: String::from(""),
c_work_dir: rwd,
bin_path: bp,
main_file_path: mfp,
compiler: String::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/interpreters/D_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub struct D_original {
data: DataHolder,
code: String,

///specific to d
d_work_dir: String,
main_file_path: String,
}
impl ReplLikeInterpreter for D_original {}
Expand All @@ -26,7 +24,6 @@ impl Interpreter for D_original {
data,
support_level,
code: String::from(""),
d_work_dir: rwd,
main_file_path: mfp,
})
}
Expand Down
3 changes: 0 additions & 3 deletions src/interpreters/FSharp_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub struct FSharp_fifo {
data: DataHolder,
code: String,
main_file_path: String,
plugin_root: String,
cache_dir: String,

interpreter: String,
Expand Down Expand Up @@ -126,14 +125,12 @@ impl Interpreter for FSharp_fifo {
//pre-create string pointing to main file's and binary's path
let mfp = rwd.clone() + "/main.fsx";

let pgr = data.sniprun_root_dir.clone();
Box::new(FSharp_fifo {
cache_dir: rwd + "/" + &FSharp_fifo::get_nvim_pid(&data),
data,
support_level: level,
code: String::from(""),
main_file_path: mfp,
plugin_root: pgr,
current_output_id: 0,
interpreter: String::new(),
})
Expand Down
8 changes: 3 additions & 5 deletions src/interpreters/GFM_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub struct GFM_original {
data: DataHolder,
code: String,

language_work_dir: String,
default_filetype: String,
}

Expand All @@ -29,7 +28,7 @@ impl GFM_original {
let selection_line = self.data.range[0] as usize;
let mut v = vec![];
for (i,l) in lines.iter().enumerate() {
if (l.trim_start().starts_with("```") && !l.trim_start()[3..].trim().is_empty())
if (l.trim_start().starts_with("```") && !l.trim_start()[3..].trim().is_empty())
&& counter % 2 == 1
{
return Err(SniprunError::CustomError(String::from(
Expand All @@ -47,13 +46,13 @@ impl GFM_original {
}
}
if counter >= 2 {
info!("counting {counter} code blocs delimiters");
info!("counting {} code blocs delimiters", counter);
if counter % 2 == 1 {
return Err(SniprunError::CustomError(String::from(
"Selection contains an odd number of code bloc delimiters",
)));
}
info!("running separately ranges : {v:?}");
info!("running separately ranges : {:?}",v);
return Err(SniprunError::ReRunRanges(v));
}
info!("no muliple bloc was found");
Expand Down Expand Up @@ -158,7 +157,6 @@ impl Interpreter for GFM_original {
data: data_clone,
support_level,
code: String::new(),
language_work_dir: lwd,
default_filetype: ddf,
});

Expand Down
4 changes: 1 addition & 3 deletions src/interpreters/Generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub struct Generic {
support_level: SupportLevel,
data: DataHolder,
code: String,
generic_work_dir: String,
glot_bin_path: String,
main_file_path: String,
}
Expand All @@ -17,13 +16,12 @@ impl Interpreter for Generic {
builder
.create(&rwd)
.expect("Could not create directory for generic");
let mfp = rwd.clone() + "/main.json";
let mfp = rwd + "/main.json";
let bp = String::from(&data.sniprun_root_dir) + "/ressources/runner";
Box::new(Generic {
data,
support_level,
code: String::from(""),
generic_work_dir: rwd,
glot_bin_path: bp,
main_file_path: mfp,
})
Expand Down
5 changes: 1 addition & 4 deletions src/interpreters/Haskell_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub struct Haskell_original {
data: DataHolder,
code: String,

///specific to haskell
haskell_work_dir: String,
bin_path: String,
main_file_path: String,
}
Expand All @@ -22,13 +20,12 @@ impl Interpreter for Haskell_original {
.expect("Could not create directory for haskell-original");

//pre-create string pointing to main file's and binary's path
let mfp = rwd.clone() + "/main.hs";
let mfp = rwd + "/main.hs";
let bp = String::from(&mfp[..mfp.len() - 3]); // remove extension so binary is named 'main'
Box::new(Haskell_original {
data,
support_level,
code: String::from(""),
haskell_work_dir: rwd,
bin_path: bp,
main_file_path: mfp,
})
Expand Down
2 changes: 0 additions & 2 deletions src/interpreters/JS_TS_deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub struct JS_TS_deno {
cache_dir: String,

current_output_id: u32,
language_work_dir: String,
main_file_path: String,
}

Expand Down Expand Up @@ -118,7 +117,6 @@ impl Interpreter for JS_TS_deno {
data,
support_level,
code: String::new(),
language_work_dir: lwd,
main_file_path: mfp,
current_output_id: 0,
})
Expand Down
Loading

0 comments on commit 9f9971e

Please sign in to comment.