Giter Site home page Giter Site logo

michaelb / sniprun Goto Github PK

View Code? Open in Web Editor NEW
1.3K 8.0 45.0 14.29 MB

A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages

License: MIT License

Rust 93.17% Shell 2.07% Python 0.24% Lua 4.44% Vim Script 0.08%
code neovim runner languages interpreter compiled-language interpreted-language partial-evaluators neovim-plugin plugin

sniprun's Introduction

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. Sniprun blurs the line between standard save/run workflow, jupyter-like notebook, and REPL/interpreters.


TLDR: Plug 'michaelb/sniprun', {'do': 'sh install.sh'}, :SnipRun, :'<,'>SnipRun, :SnipInfo

Installation, configuration, ...

See installation instructions, configuration tips, usage explanations and much more useful information on the WIKI.

Demos

Send to Sniprun snippets of any language.

A very simple example (in C), play the .gif and look in the command area:

The result can be returned in multiple (even at the same time) ways:
Classic Virtual Text
Temporary Floating Window Terminal
Notification API
REPL-like behavior is available for some languages

Python, Julia, Lua, JavaScript & Typescript (via deno), Clojure, R, Mathematica, Sage, coming soon for many other interpreted (and compiled) languages. With REPL-like behavior, you can run code dependent on previously executed code, just like in a REPL, from within your favorite editor.

Features

Sniprun is a way to quickly run small snippets of code, on the fly, and iterate very quickly and conveniently. To learn a language, to quickly experiment with new features (not yet embedded in classes or a whole project etc...), or to develop simple code pipelines (like a machine learning exercise) that fit in a unique file, sniprun is probably the best plugin out there.

As a matter of proof, Sniprun :

  • Officially supports all these languages (compiled & interpreted), and virtually any language
  • can create and connect to REPLs in order to present an interactive and playful interface
  • can run things like GUI plots, networks requests or even Ansible playbooks
  • doesn't require even one line of configuration by default (but can be customized up to the tiniest things)
  • can run code from a part of a file which isn't complete / contains errors
  • can automatically fetch (in some languages) the imports necessary for your code snippet
  • can run live (at every keystroke)
  • lends itself to easy mappings and Vim motions
  • has an API (for running code, and displaying results)
  • has many result display modes that can be enabled at the same time, and for different output status if wanted
  • supports literate programming in Markdown, Orgmode and Neorg

Known limitations

Due to its nature, Sniprun may have trouble with programs that :

  • Mess with standard output / stderr
  • Need to read from stdin
  • Access files; sniprun does not run in a virtual environment, it accesses files just like your own code do, but since it does not run the whole program, something might go wrong. Relative paths may cause issues, as the current working directory for sniprun will be somewhere in ~/.cache/sniprun, and relative imports may miss.
  • No support for Windows
  • NixOS, MacOS users have to compile sniprun locally. Sniprun has not been tested on other Unixes

Changelog

It's been quite a journey already! For history fans, see the full changelog.

Contributing

Sniprun has been made contributor-friendly (see CONTRIBUTING.md), so it's relatively easy to create / fix interpreters for any language. But any (constructive) issue, discussion, or doc Pull Request is a welcome form of contribution !

sniprun's People

Contributors

adishourya avatar bogdan-nikitin avatar danngreen avatar darwinsenior avatar escwxyz avatar gaetanlepage avatar gh-atuzhikov avatar jdsee avatar jonathanffon avatar joshpetit avatar junkblocker avatar lars-vc avatar lintaoamons avatar michaelb avatar nagolove avatar pwnalone avatar quoteme avatar qvieth avatar reavessm avatar saccarosium avatar tani avatar vigoux avatar zhengpd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sniprun's Issues

TerminalWithCode display

It could be nice to have the Terminal display also display the sniprun'd code along with the result.

Future discussion about the feature included in #123 can happen here, if the PR is merged into dev

typescript error

Describe the bug
First of all, thank you for making this awesome plugin! It makes me feel like I am using electron text editor 😁. Unfortunately, sniprun didn't giving same result as I type ts-node filename.ts on terminal

What do the bug concerns? Sniprun itself, a particular interpreter?
I don't know who gave bug, but it seems sniprun.

To Reproduce
Steps to reproduce the behavior:

  1. Installed snip run using vim-plug
  2. Did :PlugInstall
  3. ./install.sh didn't install correctly (exit code 1)
  4. Went to /.vim/plugged/sniprun
  5. Did bash ./install.sh
  6. Succesfully installed sniprun
  7. Did :checkhealth sniprun
  8. Everything went OK
  9. Did sudo npm install -g ts-node typescript

Expected behavior
The expected output should be:
image

Actual behavior
image

Environment:

  • NVIM v0.6.0-dev+560-g1fdbd29d
  • MacOS 12.0.1
  • rustc 1.56.1 (59eed8a2a 2021-11-01)

Unfortunately, I couldn't resolve this , do you have any clue?

newline in output breaks Terminal display

Describe the bug
if output contains a newline "\n" nothing will be printed in the Terminal display

What do the bug concerns? Sniprun itself, a particular interpreter?
Sniprun itself not escaping the newline properly

Use a terminal to display the output, or even take input

While the default can stay the echomsg-like output, I think having an optionnal split with a :term inside would allow for nicer interaction.

Just an idea, should be doable some day. This issue is just to remind me of that late-night idea

Virtual lines display

Is your feature request related to a problem? Please describe.

With Neovim 0.6 release around the corner, it would be great to leverage the new extmark virtual line api to show snippet results in a separate line, underneath the code.

For me, this would have better visual clarity between code and output, and also result in less cases of truncated output.

Describe the solution you'd like

An extra display option, using the virt_lines key of vim.api.nvim_buf_set_extmark.

Describe alternatives you've considered

Additional context

Persistent process

Describe the bug
The SnipRun process does not close by itself after buffer is closed / vim session is over.

What do the bug concerns? Sniprun itself, a particular interpreter?
Using Python3_fifo.

Expected behavior
Process should end when the buffer is closed.

Screenshots
Screen Shot 2021-11-16 at 18 42 25

Environment:

  • Neovim version: NVIM v0.6.0-dev+575-g2ef9d2a66
  • OS/distribution: Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-71-generic x86_64)
  • if possible, GLIBC version (output of ldd --version): (Ubuntu GLIBC 2.31-0ubuntu9.2) 2.31

Additional context
What is the proper way to end the SnipRun processes? I can add a autocmd if necessary.

Support text-objects

Using visual mode to select text for SnipRun is not an efficient vim workflow.

Implementing support for text-objects can be complex. An easier way would be to ensure the SnipRun function works properly with the toop#mapFunction() method of vim-toop.

Python 3: Execution of function definition

Describe the bug
When executing (reading) a function definition that has blank lines in it, an error occurs displaying:

RuntimeError:     <statement>
IndentationError: unexpected indent

What do the bugs concerns? Sniprun itself, a particular interpreter?
Using Python3_fifo.

To Reproduce
Steps to reproduce the behaviour:

  1. Open a python file.
  2. Replicate the "Not working" example.
  3. Select all.
  4. Run (:'<,'>SnipRun).

Expected behaviour
Should interpret the whole function correctly.

Example
Working:

def a():
    print("a")
    print("b")

Not Working:

def a():
    print("a")

    print("b")

Environment:

  • Neovim version [e.g. v0.4.3]
    NVIM v0.6.0-dev+550-g29cec32f4
  • OS/distribution
    20.04.2 LTS (GNU/Linux 5.4.0-71-generic x86_64)
  • if possible, GLIBC version (output of ldd --version)
    ldd (Ubuntu GLIBC 2.31-0ubuntu9.2) 2.31

Additional context
Add any other context about the problem here.

don't give me compile error, look for definition (rust)

No sure what better name to give it 😆

Is your feature request related to a problem? Please describe.

Yes, coming lisp languages when I run a block it automatically look for the definition and attach it then give an output

Describe the solution you'd like
A clear and concise description of what you want to happen.

When running a code and behind the scene there is a compile error, then look for definition in current buffer and evaluate them with the block. perhaps go over the line a bit and search the project.

Terminal and Floating Window not working

Describe the bug
Both floating window and terminal don't work - I can only get the virtual text to show properly

Classic
Classic works

lua << EOF
require'sniprun'.setup({
  repl_enable = {'Python3_original'},
  selected_interpreters = {'Lua_nvim'},
  display = {
    "Classic"
  },
})
EOF

image

Terminal
Terminal is blank

lua << EOF
require'sniprun'.setup({
  repl_enable = {'Python3_original'},
  selected_interpreters = {'Lua_nvim'},
  display = {
    "Terminal"
  },
})
EOF

image

Temporary Floatterm

lua << EOF
require'sniprun'.setup({
  repl_enable = {'Python3_original'},
  selected_interpreters = {'Lua_nvim'},
  display = {
    "VirtualTextOk",
    "VirtualTextErr",
    "TempFloatingWindow"
  },
})
EOF

image

and

lua << EOF
require'sniprun'.setup({
  repl_enable = {'Python3_original'},
  selected_interpreters = {'Lua_nvim'},
  display = {
    "VirtualTextOk",
    "VirtualTextErr",
    "LongTempFloatingWindow"
  },
})
EOF

image

Environment:

  • Neovim version 0.5.0

API not working [nixOS]

Adding this config to init.lua

local sa = require('sniprun.api')
local api_listener = function (d)
  if d.status == 'ok' then
    print("Nice uwu: ", d.message)
  elseif d.status == 'error' then
    print("Oh nyow! Somethuwuing went wyong: ", d.message)
  else 
    print("Whut is this myeow? I don't knyow this status type nyah")
  end
end
sa.register_listener(api_listener)

Shows binary incompatible or crash at start under checkhealth sniprun after :SnipRun or '<,'>SnipRun is used.

No output from SnipRun on any displays.

healthcheck report once the above is added to config:

sniprun: health#sniprun#check
========================================================================
## Installation
  - WARNING: `tree-sitter` executable not found (): File support and higher may not work properly
  - OK: Rust toolchain found
  - OK: sniprun binary found
  - ERROR: sniprun binary incompatible or crash at start
    - ADVICE:
      - Compile sniprun locally, with a clean reinstall and 'bash ./install.sh 1' as post-install command.

I am able to build the sniprun binary and use it without the API using BuildRustPackage

i.e before and after :SnipRun or '<,'>SnipRun, checkhealth sniprun reports everything OK:
As soon as I add a callback with register_callback(), use run_range() or run_string(), checkhealth reports the binary as incompatible.

Tested using this minimal config:

vim.cmd("packadd packer.nvim")
require("packer").startup(function(use
    use("michaelb/sniprun")
end)

require("sniprun").setup({
  display = {
    "Classic",
    "VirtualTextOk",
    "Api",
  },
  repl_enable = { "Python3_original" },
})

Environment:

  • Nvim 5.1, also tested 6.1
  • OS/distribution - nixOS

Additional context
If this isn't a config problem, its most likely a nixOS problem imo.

Support for Mathematica

Describe the language you want support for (compiler, specificities)
I'd like an interpreter for Mathematica/Wolfram Language that uses interpreter and works with filetype mma.

Support Level to achieve
Bloc level should be enough for me!

Additional context
I can call wolframscript from terminal to run a small chunk of code, but the process is slow when this is done from vim, especially because I use python based UltiSnips to do it for me. I guess using sniprun's method it can be way faster?

Border colours are inverted with TempFloatingWindow display mode

Describe the bug
When display is set to TempFloatingWindow, the colour of the borders and the area around them are inverted.

To Reproduce
Steps to reproduce the behavior:

  1. Run lua require'sniprun'.setup({ display = { "TempFloatingWindow" }})
  2. Highlight a passage
  3. Run :'<,'>SnipRun

Expected behavior
Border colours are not inverted.

Screenshots
nvim-sniprun-border

Environment:

  • Neovim v0.5.0-dev+1318-g61aefaf29
  • SnipRun installed through Packer
  • nvim-solarized-lua
  • Manjaro Linux (x86-64)
  • Alacritty

Additional context
I've first come across the same issue in FTerm, but I haven't been able to figure out what caused it. Borders in vim-floaterm and Telescope look fine, however.

I've tried having a clean init file (nvim -u NORC), changing colourschemes (to one of the built-in ones), and even a different terminal emulator (namely Kitty), but the problem same persists.

For now, being able to disable borders altogether with this display mode would be OK with me, but I don't know how to do that.

Sniprun says no such file or directory

Describe the bug
I don't know what's happening but i am getting an error saying that there is no file or directory /home/shantnu/.local/share/nvim/sit e/pack/packer/start/sniprun/target/release/sniprun even after i did ./install.sh manually (i forgot to add that line in my plugin manager)

Expected behavior
It should have run properly without any errors

Screenshots
wth

Environment:

  • Neovim v0.6.0-dev

Feature Request: Inline display of previously executed lines

Is your feature request related to a problem? Please describe.
My working memory is limited. Instead of remembering runtime variables and previous results I love to seem them. There's many approaches to solve this, like variable viewers used in debuggers or available as jupyter plugins, but one of my favorite ones are Atom's Hydrogen and inline result display a la codi as both are highly space efficient. This idea came out of #54 .

Describe the solution you'd like
A clear and concise description of what you want to happen.

Now what would be beyond amazing is if we could display the result of previously executed lines like nvim-hlslense displays the grey search counts here

CleanShot 2021-04-19 at 22 28 09@2x

Describe alternatives you've considered

  • use a debugger with variable explorer
  • use jupyter notebook/vscode's variable explorer

Julia repl doesn't work

Describe the bug
Julia REPL does not work ...?

What do the bug concerns? Sniprun itself, a particular interpreter?
The julia interpreter

To Reproduce
select Julia_jupyter in config
run on a julia file
nothing happens

Expected behavior
code output is displayed

Environment:

  • Neovim 0.5, sniprun 0.5.2

C++ namespace definitions cause Compile Error

The following C++ code will cause a Compile Error when run with SnipRun, whether the entire file is passed to SnipRun, or if just the line std::cout << "test"; is selected and run with :'<,'>SnipRun

namespace MyApplication
{
void foo()
{
std::cout << "test";
}
}

If namespace MyApplication is commented out, SnipRun works fine.

I'm very excited to use SnipRun, this project looks great! But most of my c++ code uses namespaces (which seems to be a common/recommended practice for modern c++, especially for libraries). I could probably run SnipRun cpp at the Bloc level, but then I'd miss out on the benefits of Import level.

It looks like fetch_imports in Cpp_original.rs will grab any line starting with namespace and prepend that to the temp file that's compiled, so the generated file (when used just on the single line) is:

#include <iostream>
namespace MyApplication
int main() {
std::cout << "test";
return 0;
}

which isn't valid C++ code.

I'm wondering why namespaces are included in fetch_import() to begin with. Is it to support things like
namespace someAliasNs = someOtherNs;
?

If so, changing this line in Cpp_original.rs

if line.starts_with("namespace")

to

if (line.starts_with("namespace") && line.contains("="))

fixes at least the example above (though I might be breaking something else, I'm not sure of the original intention).
Thanks!

More lua based example of usage?

Hi,
I am trying to switch into lua and your plugin looks very nice. Althought I have yet to get this work correctly.
Could you update your readme.md to include more lua based examples?

Installed using packer, but for now I haven't even gotten python to run.

use {'michaelb/sniprun', run = 'bash install.sh'}

Could you add more examples on lua instead of the old syntax?

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

Output breaks when backslashes and quotation marks are contained in the result

Describe the bug
When the result of the execution of a line or a code block contains a bad constellation of \ and ", the there is no output und an error in the sniprun.log appears.
I found the example print("\\\"") in python 3.9. The expected output would be \". In the python terminal it works. Same for R (e.g. cat("\\\"")).
Sniprun don't print anything (I tested classic, virtualtext and terminal). The logoutput for the example shows this:

[00:00:00.156] (7f8e703b3640) INFO message '\"' cleaned out
[00:00:00.157] (7f8e703b3640) INFO done displaying virtual text, Err(NeovimError(0, "Vim(lua):E5107: Error loading lua [string ":lua"]:1: ')' expected near '","'"))

What do the bug concerns? Sniprun itself, a particular interpreter?
I tracked the problem down to the cleanup_and_escape function in display.rs

sniprun/src/display.rs

Lines 330 to 333 in 545aa90

fn cleanup_and_escape(message: &str) -> String {
let answer_str = message.replace("\\", "\\\\");
let answer_str = answer_str.replace("\\\"", "\"");
let answer_str = answer_str.replace("\"", "\\\"");

The first replace statement adds a second backslash ("\\""), the second removes it ("\"") and the last one escapes all quotes (\"\\"\"). This is than pasted to the lua command for printing, but the resulting command is not sane.

To Reproduce
Steps to reproduce the behavior:

  1. Open an file in a language with sniprun support
  2. add a line with a print statement, that contains "\\\"" for example in python print("\\\"")
  3. run SnipRun
  4. See error at the end of the log (~/.cache/sniprun/sniprun.log)

Expected behavior
Output of \".

Environment:

  • NVIM v0.6.0
  • OS: Linux thinkpad 5.15.6-arch2-1
  • rustc 1.57.0
  • LuaJIT 2.0.5
  • ldd (GNU libc) 2.33
  • Sniprun 1.0.5, (also tested the current master)

Additional context
My first intuition was to switch the first and the second replace statement. Sniprun is then able to print something, but the result is wrong. For the example print("\\\"") results in ".

Passing command-line arguments, when running whole file like :%SnipRun {args}

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

sniprun.vim tries to index field 'fn' ('nil value')

Describe the bug
Sniprun fails to install properly, preventing it from loading at all.

What do the bug concerns? Sniprun itself, a particular interpreter?
The bug manifests in the Vim script parts of the plugin.

To Reproduce
Steps to reproduce the behavior:
Assuming Neovim 0.4.4 and vim-plug are already installed and set:

  1. Install sniprun using the recommended method (Plug 'michaelb/sniprun', {'do': 'bash install.sh'})
  2. After the script runs, both vim-plug and Neovim will report this error:
Error detected while processing /home/luis/.local/share/nvim/plugged/sniprun/plugin/sniprun.vim:
line    1:
E5105: Error while calling lua chunk: .../luis/.local/share/nvim/plugged/sniprun//lua/sniprun.lua:4: attempt to index field 'fn' (a nil value)

Expected behavior
Neovim should install and load the program without raising any error, at the very least.

Environment:

  • Neovim version 0.4.4

Additional context
I am trying to package this for the AUR, however it isn't clear where the sniprun binary should be relative to the tree structure of the plugin. Some additional help here would be great, too!

Using sniprun as an API

Is your feature request related to a problem? Please describe.

I am currently developing an extension that grabs code snippet from markup languages (like markdown, rst, neorg, orgmode), and I was looking into good methods to execute the code (in addition other features like save to disk through tangle).

I could make something myself, by see that sniprun is clearly superior to anything I could make.
Unfortunatly, using sniprun as a library for this purpose seem to be a bit difficult, as it is clearly meant to be a user tool.

Describe the solution you'd like

I'd like a more flexible entrypoint in the code. For example expand the notify function to have the signature:

require"sniprun".notify("run", start, end_, filetype, {display = "rpc"})

With:

  • filetype -- the filetype to assume, nil/"" means get type from buffer
  • display = "rpc" -- allow for the result to be fetched through an interface that uses rpcrequest (using e.g. buffer number as identifier).

Describe alternatives you've considered

An even more flexible design would be to allow passing arbitrary strings, like:

local stdout = require"sniprun".api_run(string_of_code, filetype)

But that would require a blocking design.

support for older versions of glibc than 2.33

Is your feature request related to a problem? Please describe.
:Sniprun silently fails so i tried to run the binary just like that and get:
./sniprun: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.33' not found (required by ./sniprun) ./sniprun: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.32' not found (required by ./sniprun)

Describe the solution you'd like
im on ubuntu 20.04 and the libc version is 2.31, can you add support for older versions of libc?

Describe alternatives you've considered
if not, at least add it to the dependency list

sniprun binary incompatible or crash at start in c or cpp files

Describe the bug
sniprun won't work in c files, when I run checkhealth sniprun every thing was fine except the error mentioned. I tried compiling the plugin locally, reinstalling language server and compiler but the issue persist.

To Reproduce
Steps to reproduce the behavior:
Execute sniprun in a .c or .cpp files

Expected behavior
Output of my code or <- (no output) in empty line

Environment:
Lunarvim (NVIM v0.5.0-dev) in Artix Linux

Additional context
The bug only happen in .c (.cpp) files, python works normally

Nothing works

Describe the bug
So I download the plugin using: Plug 'michaelb/sniprun', {'do': 'bash install.sh'}. Then restart nvim then execute :Sniprun --> nothing... no errors just nothing. OKAY. So now I execute :Snipinfo --> nothing... no errors just nothing.

Expected behavior
I just want my code to run

Environment:

  • Latest Neovim Nightly with linux Ubuntu machine and cargo installed.

:%SnipRun does not execute the whole file

Describe the bug
:%SnipRun should execute the whole file, but itactually only runs the current line

What do the bug concerns? Sniprun itself, a particular interpreter?
SnipRun launcher

Environment:

  • Neovim version 0.5

Run functions without print

Hi, thanks for the great project! I just have a quick suggestion, or maybe it's already here and I'm missing something in the docs.

From the demos and docs, I see that the result only gets captured from stdout or stderr. I was wondering if it's possible to run the code simply by capturing the return value.

For example, we can run a function like this:

def add(a, b):
    return a + b

using a command like SnipRunFunc 3 4, which will yield display

def add(a, b):
    return a + b   <- returns: 7

If the function has additional outputs, something like this could work

def add(a, b):
    print("HI")
    return a + b  <- "HI" returns: 7

This way, we don't have to add print commands anywhere.

REPL Support for Typescript

Describe the language you want support for (compiler, specificities)
I'd like an interpreter for Typescript that uses ts-node and works with filetype .ts

Support Level to achieve
It would be awesome if REPL could be implemented

Additional context
I created 2 file

test2.ts:

export const substract = (a: number, b: number): void => {
    console.log(a - b);
}

test.ts

import { substract } from "./test2";
substract(4, 2);

I run ts-node test.ts on terminal
and it gave output 2

But When I highlight all buffer in test.ts then do :'<,'>SnipRun I got following error:

RuntimeError: /opt/homebrew/lib/node_modules/ts-node/src/index.ts:750
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
../../Library/Caches/sniprun/typescript_original/main.ts(1,27): error TS2307: Cannot find module './test2' or its corresponding type declarations.
    at createTSError (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:750:12)
    at reportTSError (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:754:19)
    at getOutput (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:941:36)
    at Object.compile (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:1243:30)
    at Module.m._compile (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:1370:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:1374:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
  diagnosticText: "../../Library/Caches/sniprun/typescript_original/main.ts(1,27): error TS2307: Cannot find module './test2' or its corresponding type declarations.\n",
  diagnosticCodes: [ 2307 ]
}

It seems, ts-node support multiple file, is it possible to make it happen? Thanks in advance 🙂

Goals of the project

As the original project developer, this is how i envision sniprun's future:

The following is already a reality, and I'd like it to stay that way

  • Simple in utilisation and understanding
  • Allow simple contribution (addition of new languages)
  • Documentation effort throughout the code
  • Sniprun only runs the code it needs to run (when possible)

This would be nice to have:

  • Plugin system, where plugins (can) sometimes provide services for multiple interpreters
  • Optional dependencies (features?) (for in-development interpreters)
  • Public recognition
  • Test automation
    -̶ ̶l̶e̶t̶ ̶c̶o̶n̶f̶i̶g̶u̶r̶a̶t̶i̶o̶n̶=̶o̶p̶t̶i̶o̶n̶s̶ ̶i̶n̶ ̶v̶i̶m̶ done
  • integrated parsing framework (to help implementation of higher support levels)

Seeing how there are few satisfactory alternative (comment if i am wrong), especially for compiled languages, and how quickly i could develop this by myself * , I'd like to see sniprun become a popular plugin. Maybe the all-language partial tester? ? I can dream alright.

Handling typescript

It would be awesome to handle Typescript.

Usually Typescript will convert the file to Javascript first (tsc helloworld.ts will generate helloworld.js).
Alternatively, it seems there is another tool: ts-node src/foo.ts.

Alternatively (probably the best solution), it could be output to the stdout then pass it to nodejs: tsc hw.ts --out /dev/stdout | node

Support for SageMath

Describe the language you want support for (compiler, specificities)
I'd like an interpreter for SageMath that uses SageMath REPL (which is essentially iPython with Sage additions) and that work with detected filetype ".sage" (which is supported by vim-sage).

SageMath is a quite popular opensource computer-algebra system. Sage code is basically Python code with some minor additions (explaining preparsing) and it is preparsing to Python.

Support Level to achieve
Having same level of support (Import +REPL**) as Python has would be great!

Additional context
Similar project vimcmdline has SageMath support.

One either run Sage code in Sage REPL (alternative: Sage Notebook) or run .sage file in command line: sage my_file.sage. During run of .sage file Sage runs preparsing. Something like sage -preparse myclass_test.sage

In Sage code you are able to:

  1. import standard python modules
  2. import sage modules in special manner
  3. use load (load command specificaton), special instruction for load sage file.

Last one is the most popular.

Lua_nvim support

Hey ! Thanks for this awesome plugin !

I think it can be really useful to execute lua snippets within neovim, how hard do you think it would be ?
And how could I help in the process ?

Thanks again !

defaut behavior for repl-capable interpreters

Would you rather have to:

  • opt-in (upvote)
  • opt-out (current) (downvote)

?

Opt-in would make the default behavior more consistent between interpreters (most can't do REPL) , but users may miss out on the feature.

Python - RuntimeError: ModuleNotFoundError: No module named 'klepto'

Describe the bug

RunTimeError when using the Python_original interpreter
image

lua << EOF
require'sniprun'.setup({
  selected_interpreters = {},     --" use those instead of the default for the current filetype
  repl_enable = {},               --" enable REPL-like behavior for the given interpreters
  repl_enable = {'Python3_original'},
  repl_disable = {},              --" disable REPL-like behavior for the given interpreters

  inline_messages = 0,             --" inline_message (0/1) is a one-line way to display messages
                                  --" to workaround sniprun not being able to display anything

  -- " you can combo different display modes as desired
  display = {
    -- "Classic",                    -- "display results in the command-line  area
    "VirtualTextOk",              -- "display ok results as virtual text (multiline is shortened)
    "VirtualTextErr",          -- "display error results as virtual text
    "TempFloatingWindow",      -- "display results in a floating window
    --LongTempFloatingWindow",  -- "same as above, but only long results. To use with VirtualText__
    -- "Terminal"                 -- "display results in a vertical split
    },

})
EOF

And my SnipInfo

-n Version :  v0.5.3
 (up-to-date)


Currently selected interpreter: Python3_original, at support level: Import

mode of install

Plug 'michaelb/sniprun', {'do': 'bash install.sh 1'}
:checkhealth
## Installation
  - OK: `tree-sitter` found  0.19.4 (89e1157a299596f3ce2155ba9fd69d5e2c03d3e6) (parser generator, only needed for :TSInstallFromGrammar)
  - OK: Rust toolchain found
  - OK: sniprun binary found
  - ERROR: sniprun binary incompatible or crash at start
    - ADVICE:
      - Compile sniprun locally, with a clean reinstall and 'bash ./install.sh 1' as post-install command.

(Note I recompiled multiple times)

❯ file ./target/release/sniprun
./target/release/sniprun: Mach-O 64-bit executable arm64

lua appears to work well

image

What do the bug concerns? Sniprun itself, a particular interpreter?
The bug seems to stem from the Python interpreter

Environment:

❯ nvim --version
NVIM v0.5.0-dev+1025-g0fad952a2
Build type: Debug
LuaJIT 2.1.0-beta3

Additional context
Add any other context about the problem here.

none of the commands found

Describe the bug

none of the commands are appearing ie :SnipRun/Info etc... :h sniprun works and :checkhealth sniprun shows everything is good.

Installed on Mac OS big sur.

I have the following in my

require'sniprun'.setup()

I compiled with bash ./install.sh 1

I installed with vim-plug

I have the rust toolchain cargo 1.51.0 (43b129a20 2021-03-16)

Sorry if I am overlooking something obvious.

Thanks you!

Support specifying what commands to use for compiling stuff

Is your feature request related to a problem? Please describe.
Right now, (as far as I can tell) compilers are hard-coded to gcc, g++, go, etc. In some cases, this means that someone would need to install a different compiler than the one they're already using for this plugin to work.

This could also allow for using a compiler cache like ccache or sccache so things run a little faster (but that's not as important)

Describe the solution you'd like
An option to specify what compilers to use.

Describe alternatives you've considered
All I've got right now is changing the hard-coded values in the source code, and then building from scratch.

For C & C++ specifically, the default compilers could be changed to respect the $CC & $CXX environment variables respectively, and default to cc and c++ respectively. Those are arguably safer if it stays hard-coded.

No such file or directory

Describe the bug
I don't know what's happening but i am getting an error saying that there is no file or directory /home/shantnu/.local/share/nvim/sit e/pack/packer/start/sniprun/target/release/sniprun even after i did ./install.sh manually (i forgot to add that line in my plugin manager)

Expected behavior
It should have run properly without any errors

Screenshots
wth

Environment:

  • Neovim v0.6.0-dev

Does not seem to work properly

Describe the bug

  1. Open small python hello world
  2. Visual select all the code
  3. Run SnipRun
  4. See error about non existent channel.
Error detected while processing function <SNR>42_run:                 
line    3:
E475: Invalid argument: Channel doesn't exist
Press ENTER or type command to continue

What do the bug concerns? Sniprun itself, a particular interpreter?

Tried also Ruby and Bash sample Hello World programs. Same result.

Expected behavior

I expected to see a terminal magically being open with the required REPL and get the selected code executed in it.

Screenshots

image

Environment:

  • Linux (Kde Neon Latest)
  • Neovim v0.5.0-dev+1019 (Latest compiled from master)

How to configure the markdown interpreter?

I was looking for a way to run code blocks in markdown and came upon this plugin. It didn't run at first. It turns out that was because I was using markdown syntax file that requires the markdown filetype to change to markdown.pandoc. Changing the file type back to markdown works.

My first question is, how do I make sniprun work when the filetype is changed to markdown.pandoc.

My section question is why can't I put the cursor anywhere inside the code block and have the code block evaluated?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.