Skip to content

Commit

Permalink
Merge pull request #264 from michaelb/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
michaelb committed Dec 15, 2023
2 parents 7a8bc30 + 348be04 commit 6398773
Show file tree
Hide file tree
Showing 32 changed files with 608 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:

- run: './ressources/install_all_compilers_ci.sh'

- uses: oven-sh/setup-bun@v1

- uses: dlang-community/setup-dlang@v1

- uses: erlef/setup-beam@v1
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.3.9
- Support of "interpreter" and "compiler" key for every interpreter
- Bun-based JS/TS intepreter (with REPL)

## v1.3.8
- Fix Python3_jupyter
- Allow opening terminal in horizontal split
Expand Down
2 changes: 1 addition & 1 deletion CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- 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
- `cargo update --offline` # update sniprun's version in committed Cargo.lock

## Merge process
- create a PR dev -> master
Expand Down
17 changes: 5 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[package]
name = "sniprun"
version = "1.3.8"
version = "1.3.9"
authors = ["michaelb <[email protected]>"]
rust-version = "1.65"
edition = "2018"

[features]
ignore_in_ci = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[profile.release]
strip = true

[build-dependencies]
# cc="*"

Expand All @@ -20,7 +23,7 @@ close_fds = "0.3"
thiserror = "1.0"
dirs = "5.0"
regex = "1.0" # up-to-date-regex needs a more recent Rust version
strip-ansi-escapes = "0.1.1"
strip-ansi-escapes = "0.2"
libc = "0.2.79"
serial_test = "2.0"

Expand Down
4 changes: 2 additions & 2 deletions doc/sources/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Introductionreadme
# Introduction

Sniprun is a code runner plugin for neovim written in Lua and Rust. It aims to provide stupidly fast partial code testing for interpreted **and compiled** {ref}`languages <support-levels-and-languages>`. Sniprun blurs the line between standard save/run workflow, jupyter-like notebook, and REPL/interpreters.

Expand Down Expand Up @@ -431,7 +431,7 @@ println!("-> {}", alphabet);
| Scala | Bloc | No |
| TypeScript | Bloc | Yes\*\* (Deno) |

Your language is not officially supported ? The [Generic interpreter](https://michaelb.github.io/sniprun/sources/Generic.html#community-examples-for-non-officially-supported_languages) can probably work with it !
Your language is not officially supported ? The [Generic interpreter](https://michaelb.github.io/sniprun/sources/Generic.html#community-examples-for-non-officially-supported-languages) can probably work with it !

Want (official) support for your language? Submit an [issue](https://github.com/michaelb/sniprun/issues/new?assignees=&labels=new-langage-support&template=support-for--language-.md&title=),or even better, contribute (see CONTRIBUTING.md), it's easy!

Expand Down
26 changes: 26 additions & 0 deletions doc/sources/common_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,29 @@ interpreter_options = {
}
},
```

## The interpreter/compiler keys

Almost every interpreter support either the "interpreter" or "compiler" key even if not explicitely documented, depending on whether they're about an interpreter or compiled language.

example:

```
interpreter_options = {
Python3_original = {
interpreter = "python3.9"
}
Rust_original = {
compiler = "/home/user/bin/rustc-patched"
}
},
```

You can see what interpreters/compilers are being used at any time by watching sniprun's log for the line
"using compiler XXXX" or "using interpreter XXXX" when you run a snippet.

Exceptions:
- Scala_original has both interpreter and compiler keys that should be set consistently with each other
- *_jupyter, Generic, GFM_original, Orgmode_original, and Neorg_original do not support any of these keys


2 changes: 2 additions & 0 deletions doc/sources/interpreters/Generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ to add support for, let's say, python2
require'sniprun'.setup({
interpreter_options = {
Generic = {
error_truncate="long", -- strongly recommended to figure out what's going on
MyPython2Config = { -- any key name is ok
supported_filetypes = {"python2"}, -- mandatory
extension = ".py", -- recommended, but not mandatory. Sniprun use this to create temporary files
Expand All @@ -38,6 +39,7 @@ to also add support for, let's suppose it wasn't officially supported, C
require'sniprun'.setup({
interpreter_options = {
Generic = {
error_truncate="long",
MyPython2Config = {
supported_filetypes = {"python2"},
extension = ".py",
Expand Down
39 changes: 39 additions & 0 deletions doc/sources/interpreters/JS_TS_bun.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## JS_TS_bun

A REPL-capable (not enabled by default) Typescript / Javascript interpreter.

`bun` needs to be installed and on your path.


### JS_TS_bun is REPL-capable

But the REPL is VERY quirky (and even has a greeting saying it's unstable)
It doesn't play well at all with sniprun's stdin-stdout mechanism, so while basic examples are working,
I can't consider this a 'daily driver'... so REPL is disabled by default

```
require('sniprun').setup({
selected_interpreters={"JS_TS_bun"},
repl_enable={"JS_TS_bun"}
})
```


### more option for the (non-repl) command line

sniprun runs your code snippets with

`bun run --silent <file.ts>`

more arguments for `bun run` can be added with the interpreter option:

```
require'sniprun'.setup({
interpreter_options = {
JS_TS_bun = {
bun_run_opts = "--smol"
}
}
}
})
```
24 changes: 24 additions & 0 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ pub trait InterpreterUtils {
fn get_interpreter_option(data: &DataHolder, option: &str) -> Option<neovim_lib::Value>;
fn contains_main(entry: &str, snippet: &str, comment: &str) -> bool;
fn error_truncate(data: &DataHolder) -> ErrTruncate;

fn get_compiler_or(data: &DataHolder, or: &str) -> String;
fn get_interpreter_or(data: &DataHolder, or: &str) -> String;
}

impl<T: Interpreter> InterpreterUtils for T {
Expand Down Expand Up @@ -310,6 +313,27 @@ impl<T: Interpreter> InterpreterUtils for T {
None
}

fn get_compiler_or(data: &DataHolder, or: &str) -> String {
if let Some(compiler) = T::get_interpreter_option(data, "compiler") {
if let Some(compiler_valid_str) = compiler.as_str() {
info!("using compiler '{}'", compiler_valid_str);
return compiler_valid_str.to_string();
}
}
info!("using compiler '{}'", or);
or.to_string()
}
fn get_interpreter_or(data: &DataHolder, or: &str) -> String {
if let Some(interpreter) = T::get_interpreter_option(data, "interpreter") {
if let Some(interpreter_valid_str) = interpreter.as_str() {
info!("using interpreter '{}'", interpreter_valid_str);
return interpreter_valid_str.to_string();
}
}
info!("using interpreter '{}'", or);
or.to_string()
}

fn error_truncate(data: &DataHolder) -> ErrTruncate {
if let Some(error_truncate) = T::get_interpreter_option(data, "error_truncate") {
if let Some(error_truncate) = error_truncate.as_str() {
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/Ada_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ impl Interpreter for Ada_original {
write(&self.main_file_path, &self.code)
.expect("Unable to write to file for language_subname");

let output = Command::new("gnatmake")
let compiler = Ada_original::get_compiler_or(&self.data, "gnatmake");
let output = Command::new(compiler)
.arg("main")
.arg(&self.main_file_path)
.current_dir(&self.ada_work_dir)
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/Bash_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ impl Interpreter for Bash_original {
}

fn execute(&mut self) -> Result<String, SniprunError> {
let output = Command::new("bash")
let interpreter = Bash_original::get_interpreter_or(&self.data, "bash");
let output = Command::new(interpreter)
.arg(&self.main_file_path)
.args(&self.get_data().cli_args)
.output()
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/CS_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ impl Interpreter for CS_original {
}

fn execute(&mut self) -> Result<String, SniprunError> {
let output = Command::new("coffee")
let interpreter = CS_original::get_interpreter_or(&self.data, "coffee");
let output = Command::new(interpreter)
.arg(&self.main_file_path)
.args(&self.get_data().cli_args)
.output()
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/D_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ impl Interpreter for D_original {

fn execute(&mut self) -> Result<String, SniprunError> {
//run th binary and get the std output (or stderr)
let output = Command::new("dmd")
let interpreter = D_original::get_interpreter_or(&self.data, "dmd");
let output = Command::new(interpreter)
.arg("-run")
.arg(&self.main_file_path)
.output()
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/Elixir_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ impl Interpreter for Elixir_original {
Ok(())
}
fn execute(&mut self) -> Result<String, SniprunError> {
let output = Command::new("elixir")
let interpreter = Elixir_original::get_interpreter_or(&self.data, "elixir");
let output = Command::new(interpreter)
.arg(&self.main_file_path)
.args(&self.get_data().cli_args)
.output()
Expand Down
Loading

0 comments on commit 6398773

Please sign in to comment.