Skip to content

Commit

Permalink
Merge branch 'master' of github.com:michaelb/sniprun
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelb committed Apr 9, 2021
2 parents f6396f5 + 2b61e24 commit b35fcb4
Show file tree
Hide file tree
Showing 38 changed files with 919 additions and 1,474 deletions.
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ coverage:
patch:
default:
target: 1%
threshold: 1%
path: "src"
6 changes: 5 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 &&
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' &&
sudo apt install r-base &&
sudo apt install gnat &&
sudo apt install scala &&
pip3 install jupyter &&
sudo apt install lua5.3 &&
./ressources/go_install.sh &&
Expand Down Expand Up @@ -78,6 +80,8 @@ jobs:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 &&
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' &&
sudo apt install r-base &&
sudo apt install gnat &&
sudo apt install scala &&
pip3 install jupyter &&
sudo apt install lua5.3 &&
./ressources/go_install.sh &&
Expand All @@ -91,7 +95,7 @@ jobs:
- name: Code coverage
uses: actions-rs/[email protected]
with:
args: --features ignore_in_ci -- --test-threads=1
args: --features ignore_in_ci --exclude-files src/interpreters/example.rs -- --test-threads=1

- name: Upload to codecov.io
uses: codecov/[email protected]
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ test/
download_dir/
target/
ressources/infofile.txt
ressources/cccccc.c
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## v0.5.2
- Ada and Scala interpreters
- Operator mode, courtesy of @DarwinSenior
- Julia REPL via jupyter kernel
- Compatibility fix for nvim 0.4.x (will miss out on features >= sniprun v0.4.9)


## v0.5.1
- Markdown interpreter
- Better :SnipInfo
- SnipInfo \<name> now display the help file in doc/

## v0.5.0
- Sniprun becomes a Lua (+Rust) plugin!!
- Lua backend, config, and checkhealth
Expand Down
31 changes: 16 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Just in case: to compile `cargo build --release`, to create and show the documen

### How hard it is?

Lemon squeezy easy. A developper midly familiar with Rust and the language to add support for can write a working bloc-support interpreter in 30min ( 13min my best time, for C_original) to 1h30. You can then submit your proposed changes as a PR to the master branch.
Lemon squeezy easy. A developper midly familiar with Rust and the language to add support for can write a working bloc-support interpreter in 30min ( 13min is my best time, for C_original to 1h30. You can then submit your proposed changes as a PR to the master branch.

Higher support levels gets exponentially harder (depends on the languages though), so you should start out with Bloc.

Expand All @@ -22,40 +22,41 @@ Yeah cool but what _code_ goes inside?

-> Inside, you must define a struct that implement the **Interpreter** trait. Have a look at existing implementations to get the idea, though some current interpreters use pretty advanced features of Sniprun that you may not want to deal with. Prefer looking at 'Bloc' level support interpreters for a smooth start. Make sure to respect the [conventions](#conventions). The "example.rs" interpreter is a good starting point, with more comments to help you understand what's happening.

I just compiled, how do I test my code quickly?
---
I just finished some changes, how do I test my code quickly?

-> compile `cargo build --release` and run `nvim -u plugin/sniprun.vim some_test_file.ext` from the sniprun project root.
-> compile `cargo build --release` and run `nvim --cmd "set rtp+=. -u NORC <testfile>` from the sniprun project root.

---

Is _my_ code running?

-> Assert that the file type detected by Neovim is contained in your list of supported file types. If there is already a implementation for your filetype/language, set (temporarly) your max support level to "Selected".
-> Assert that the file type detected by Neovim is contained in your list of supported file types. If there is already a implementation for your filetype/language, set (temporarly) your max support level to "Selected", or run something like `:lua require'sniprun'.setup({selected_interpreters = {'<name>'}})` before `:SnipRun` .

---

I need to debug, how ?

-> Use the `info!("here")` macro instead of `println!("here")`. This writes to the log file you can find in ~/.cache/sniprun/sniprun.log.
-> Use the `info!("here")` macro instead of `println!("here")`. This writes to the log file you can find in ~/.cache/sniprun/sniprun.log. Beware, if you panic, the logger will stop writing.

---

Can I panic!() ?

-> Yes but preferably only when you encounter a fatal error (eg: you have to write a file, but there is no space left on the device).
Failing compilation or incorrect code panicking should be handled via the SniprunError enum
Failing user code compilation or incorrect user code panicking should be handled via the SniprunError enum.

---

My interpreter does not produce any output..?!

-> It's because your code is panicking. (unwrapping a `None` or these kind of things). Check the logs at ~/.cache/sniprun/sniprun.log
-> It's because your code is panicking. (unwrapping a `None` or these kind of things). Check the logs at ~/.cache/sniprun/sniprun.log .

---

I need to import some external dependencies.

-> Add what you need to the src/interpreters/import.rs file, and the Cargo.toml if necessary
-> Add what you need to the src/interpreters/import.rs file, and the Cargo.toml if necessary.

---

Expand All @@ -67,13 +68,13 @@ I need more than one file to write complicated code...

Do I need to manage async running and compiling?

-> No, Sniprun takes care of that for you. You can implement a single-threaded synchronous code just like the Python3_original interpreter
-> No, Sniprun takes care of that for you. You can implement a single-threaded synchronous code just like the D_original interpreter.

---

My interpreter has some quirks that the end user should know

-> Document limitations and features in doc/interpreter_name.md
-> Document limitations and features in doc/interpreter_name.md .

---

Expand All @@ -86,20 +87,20 @@ I lack the ReplLikeInterpreter trait implementation and don't want to do REPL-li
My tests are inconsistent ..?!?

-> Rust tests are run in parallel, and therefore a race condition may occur when writing to files and compiling.
Run with `cargo test -- --test-threads=1`
Run with `cargo test -- --test-threads=1` .

---
I think I've done a good job, but am I ready to submit a PR?

-> You should check beforehand that the output of `cargo test -- --test-threads=1`, `cargo tarpaulin -- --test-threads=1`, and `./ressources/vroomtests.sh` are satisfying. You've added the proper an necessary tests, and have documented any edge case.
-> You should check beforehand that the output of `cargo test -- --test-threads=1` and your own tests are satisfying. You've added the proper an necessary tests, and have documented any edge case.

### What's the deal with...

- Support Levels? Those exists to document what the interpreter supports to the end user. They are also used for higher (file, project and system) levels as if an interpreter detects it does not need a support level that high, it can set down its own level and hopefully be faster [ since it won't need to open all files etc...]. **You don't have to worry about this too much if you are just getting started**.

- Errors? When possible and sensible, functions like fetch(), build() and execute() should return either an Ok(\_) variant or a Err(SniprunError). Choose the error that most closely describe whatever migth cause your function to fail, and populate it with a String message if relevant.

* The imposed names? To simplify contribution (you only have to write a interpreter), the main program fetch new files and run functions of your interpreter. This is only easily possible if you types names match your file name, as I can get those easily but i would have to read them, guess what struct is the correct one should you have many....no, I rather do the `use file_name::file_name;` trick that just works.
* The imposed names? To simplify contribution (you only have to write a interpreter), the main program fetch new files and run functions of your interpreter. This is only easily possible if you types names match your file name, as I can get those easily but i would have to read them, guess what struct is the correct one should you have many....no, I rather do the `use file_name::file_name;` trick that just works. Also helps future contributors/users.

### Conventions

Expand All @@ -126,5 +127,5 @@ To pay attention to, when writing an interpreter or changes:
- **Minimum code retrieval** : Sniprun should only fetch from the buffer/file the bare minimum necessary to get working.
- **Allow snips from incomplete files** : if you need to read a bigger part of the file than the data provided by sniprun (in DataHolder), you should NOT fail because the file miss a '}' 35 lines after the code snip.
- **IO optimization** : it's OK if you write 3 files each time sniprun fires. It's not OK if you re-index a whole project and write a 50Mo file. Overall this is a pretty relaxed rule, as most code sent to sniprun (to then write etc...) is very short, a few lines at most.
- **Code clarity** : at least comments for non-trivial parts, 'good code' is valued even if I get, and did that myself, than sometimes dirty hacks are necessary.
- **Documentation** : not extensively required, but limitations and subtilities, if any, of your interpreter should be written a the doc/interpreter_name.md file.
- **Code clarity** : at least comments for non-trivial parts, 'good code' is given value even if I get, and did that myself, than sometimes dirty hacks are necessary.
- **Documentation** : not extensively required, but limitations and subtilities, if any, of your interpreter should be written a the doc/interpreter_name.md file: that will be accessible through :SnipInfo [name] this way!
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Send to Sniprun snippets of any language. A few lines of code are now within a p
An example in C:
![](ressources/visual_assets/demo_c.gif)

⮤ result is displayed at the bottom of the window.

send-to-REPL-like behavior is available for Python, R (both real REPLs) and Bash (simulated), coming soon for many other interpreted and compiled languages. Very versatile, you can even run things like GUI plots on the fly!

![](ressources/visual_assets/demo_repl.gif)
Expand Down Expand Up @@ -95,10 +97,11 @@ Sniprun will then:

### Prerequisites && dependencies

- Sniprun is Linux-only for now (as of v0.5.1), so you need Linux.
- Neovim version (>= 0.43 preferably), but should work with older versions
- [recommended, but optionnal] cargo and the rust toolchain version >= 1.43.0 (you can find those [here](https://www.rust-lang.org/tools/install)).
- 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 **[doc](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 also be accessed through `:SnipInfo <interpreter_name>` (tab autocompletion supported).
- Sniprun is **Linux**-only for now (as of v0.5.2).
- **Neovim** version (>= 0.5 for the latest goodies), but 0.4.x is supported up to sniprun v0.4.9 and the installer will take care of installing the latest version 'that works', though you may miss the latest goodies, and you will need to use the [old vimscript way to configure](ressources/old_configuration.md).
- [recommended, but optionnal] **cargo and the rust toolchain** version >= 1.43.0 (you can find those [here](https://www.rust-lang.org/tools/install)).

- **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 [doc](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 also be accessed through `:SnipInfo <interpreter_name>` (tab autocompletion supported).


### Install Sniprun
Expand Down Expand Up @@ -144,7 +147,11 @@ You can do basically two things: **run** your code selection and **stop** it (in

`:'<,'>SnipRun`

(the shorthand for ``` :lua require'sniprun'.run('v')```)
(the shorthand for `:lua require'sniprun'.run('v')`)

**Operator mode**:

Configure a mapping to `<Plug>SnipRunOperator` and combine it with movements to sniprun 'text objects'. Every text-object will be rounded line-wise.


#### Stopping
Expand Down Expand Up @@ -216,13 +223,16 @@ You can find [here](ressources/old_configuration.md) the 'old'/vimscript way to

![](ressources/visual_assets/760091.png)

### My usage recommandation & tricks
### Usage recommandation & tricks

- Map the run command to a simple command such as `<leader>ff` (or just `f` in visual mode)
- The operator mapping allows you to combine movements with sniprun: with the suggested mapping, "<leader>f + j" will run sniprun on the current line + the line below.

- Map the run command to a simple command such as `<leader>f` (or just `f` in visual mode).
(if you don't know what is the leader key you can find a short explanation [here](https://vim.works/2019/03/03/vims-leader-key-wtf-is-it/)).

```
nmap <leader>f <Plug>SnipRun
nmap <leader>ff <Plug>SnipRun
nmap <leader>f <Plug>SnipRunOperator
vmap f <Plug>SnipRun
```

Expand Down Expand Up @@ -262,7 +272,7 @@ println!("-> {}", alphabet);

| Language | Support level | | Language | Support level |
| ------------ | ------------- | --- | ---------- | ---------------- |
| Ada | Untested | | Java | Bloc |
| Ada | Line | | Java | Bloc |
| Bash/Shell | Bloc + REPL\* | | JavaScript | Bloc |
| C | Import | | Julia | Bloc |
| C++ | Import | | Lisp | Untested |
Expand All @@ -276,7 +286,7 @@ println!("-> {}", alphabet);
| Erlang | Untested | | R | Bloc + REPL \*\* |
| F# | Untested | | Ruby | Bloc |
| Go | Bloc | | Rust | Bloc |
| Groovy | Untested | | Scala | Untested |
| Groovy | Untested | | Scala | Bloc |
| Haskell | Line | | Scilab | Untested |
| Idris | Untested | | Swift | Untested |

Expand Down
8 changes: 8 additions & 0 deletions doc/Ada_original.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Need gcc-ada and gnatmake


Note: because Ada needs variables to be declared before the begin (in a non contiguous section of the file), SnipRun is not very useful here and will, in practice, only be able to run blocs like

```
Put_Line("raw text");
```
3 changes: 3 additions & 0 deletions doc/GFM_original.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ require'sniprun'.setup({
EOF


if GFM doesn't include a flavor that matches the language you want, well it's not really GFM anymore but you can but the filetype of the language you want, such as julia or lua




48 changes: 30 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env bash

set -o errexit

# version="v0.2.0"

echo "Runnning Sniprun Installer"
local_version=vv$(cat Cargo.toml | grep version | cut -d "\"" -f 2)
local_version=v$(cat Cargo.toml | grep version | cut -d "\"" -f 2)
name="sniprun"
force_build=$1

Expand All @@ -14,6 +11,7 @@ cargo_build() {
echo "Building..."
cargo build --release &>/dev/null
echo "Done"
return 0
else
echo "Could not find cargo in \$PATH: the Rust toolchain is required to build Sniprun"
return 1
Expand All @@ -26,42 +24,56 @@ get_latest_release() {
download() {
# command -v curl >/dev/null &&
# curl --fail --location "$1" --output target/release/sniprun
rm -rf download_dir
mkdir -p download_dir
cd download_dir
curl -s https://api.github.com/repos/michaelb/sniprun/releases/latest | grep "sniprun" | cut -d ":" -f 2,3 | tr -d \" | wget -qi -
mv -f sniprun ../target/release/
cd ..
echo "Downloading" $1
# curl -s https://api.github.com/repos/michaelb/sniprun/releases/$1 | grep "sniprun" | cut -d ":" -f 2,3 | tr -d \" | wget -qi -
wget -q https://github.com/michaelb/sniprun/releases/download/v0.4.9/sniprun
mkdir -p target/release/
mv -f sniprun target/release/
}

fetch_prebuilt_binary() {
echo "Downloading binary.."
mkdir -p target/release

if (download "$url"); then
if (download $1); then
chmod a+x target/release/sniprun
echo "Done"
return
return 0
else
return 1
fi
}

arch=$(uname)
if [ $arch != "Linux" ]; then
echo "Warning, sniprun needs Linux to work properly! Any behaviour from this point is not tested"
echo "Warning: Doesn't look like you are on Linux. Sniprun is not tested on Mac and will not work on windows"
fi

remote_version=v$(get_latest_release)
remote_version=$(get_latest_release)

if [ $force_build ]; then
echo "Always compiling the latest commit (most bleeding-edge option)"
neovim_version=$(nvim --version | head -n 1 | cut -d . -f 2) # 4 -> neovim 0.4.x
if [ $neovim_version == "4" ]; then
echo "Sniprun 0.4.9 is the highest version supported on neovim 0.4.x"
git reset --hard v0.4.9
fi
cargo_build
else

tag_to_fetch=$remote_version
neovim_version=$(nvim --version | head -n 1 | cut -d . -f 2) # 4 -> neovim 0.4.x
if [ $neovim_version == "4" ]; then
echo "Sniprun 0.4.9 is the highest version supported on neovim 0.4.x"
git reset --hard v0.4.9
tag_to_fetch="v0.4.9"
fi


#check if release is up to date
success=1
if [ $local_version == $remote_version ]; then
echo "Trying to get a up-to-date precompiled binary"
fetch_prebuilt_binary
fetch_prebuilt_binary $tag_to_fetch
success=$?
else
echo "Release version is not up to date, building from source"
Expand All @@ -70,9 +82,9 @@ else
fi

# if nothing succeeded
if [ success == 1 ]; then
if [ $success == 1 ]; then
echo "Could not build (missing rust/cargo toolchain?). Getting an out-of-date release if available"
fetch_prebuilt_binary # get an older release
fetch_prebuilt_binary $tag_to_fetch # get an older release
fi
fi

Expand Down
Loading

0 comments on commit b35fcb4

Please sign in to comment.