Skip to content

Commit

Permalink
Merge pull request #167 from michaelb/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
michaelb authored Jun 18, 2022
2 parents 5b7d9f9 + 9243bd6 commit 44acc11
Show file tree
Hide file tree
Showing 33 changed files with 550 additions and 200 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.2.5
- SnipInfo in floating windows and decently fast
- auto + configurable error truncation
- Lua_nvim REPL/non-REPL modes

## v1.2.4
- set Rust 1.55 as MSRV
- fix typo in documentation
Expand Down
91 changes: 62 additions & 29 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sniprun"
version = "1.2.4"
version = "1.2.5"
authors = ["michaelb <[email protected]>"]
rust-version="1.31"
edition = "2018"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,16 @@ require'sniprun'.setup({
repl_disable = {}, --# disable REPL-like behavior for the given interpreters
interpreter_options = { --# interpreter-specific options, see docs / :SnipInfo <name>
--# use the interpreter name as key
GFM_original = {
use_on_filetypes = {"markdown.pandoc"} --# the 'use_on_filetypes' configuration key is
--# available for every interpreter
},
Python3_original = {
error_truncate = "auto" --# Truncate runtime errors 'long', 'short' or 'auto'
--# the hint is available for every interpreter
--# but may not be always respected
}
},
Expand Down
25 changes: 24 additions & 1 deletion doc/Lua_nvim.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
Limitation: If your code do not contain "nvim" or "vim" (even in comments) the Sniprun will fallback to the (pure) lua interpreter, which may be fine, or may not if you are using subtelties of the lua-nvim language the normal lua interpreter cannot grasp
Limitations:

This interpreter works inherently in a pseudo-REPL mode and this can't be disabled.

Essentially, you can expect REPL behavior when running line-by-line of bloc-by-bloc lua script:

```
a = 4
b = 6
print(a+5) -- <- 9
a = 0
print(a + b) -- <- 6
```

HOWEVER, if you define a 'local' variable, it won't be available in subsequent calls

```
local a = 5
print(a) -- <- nil
```

12 changes: 10 additions & 2 deletions doc/Lua_original.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
Limitation: if your code selection contains "nvim' or "vim", even in comments, Sniprun will use the lua-nvim interpreter instead of the normal 'lua' one.
Which may be fine, but may not be :-)
Limitation/feature

IF
- your code selection contains "nvim' or "vim", even in comments,
- you haven't explicitely selected Lua_original
- your code snippet fails

THEN

Sniprun will use the lua-nvim interpreter instead of the normal 'lua' one.
41 changes: 17 additions & 24 deletions lua/sniprun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ end

-- get all lines from a file, returns an empty
-- list/table if the file does not exist
local function lines_from(file)
local lines = {""}
for line in io.lines(file) do
lines[#lines + 1] = line or " "
end
return lines
local function lines_from(filename)
local file = io.open(filename, "r")
local arr = {}
for line in file:lines() do
table.insert (arr, line)
end
return arr
end

function M.display_lines_in_floating_win(lines)
Expand All @@ -284,15 +285,9 @@ function M.display_lines_in_floating_win(lines)
})
-- vim.api.nvim_win_set_option(M.info_floatwin.win, 'winhighlight', 'Normal:CursorLine')

local namespace_id = vim.api.nvim_create_namespace("sniprun_info")
local h = -1
local hl=""
for line in lines:gmatch("([^\n]*)\n?") do
h = h+1
vim.api.nvim_buf_set_lines(M.info_floatwin.buf,h, h+1,false, {line})
-- local namespace_id = vim.api.nvim_create_namespace("sniprun_info")
vim.api.nvim_buf_set_lines(M.info_floatwin.buf,0,500,false, lines)
-- vim.api.nvim_buf_add_highlight(M.info_floatwin.buf, namespace_id, hl, h,0,-1) -- highlight lines in floating window
vim.cmd('set ft=markdown')
end
end


Expand All @@ -301,16 +296,14 @@ function M.info(arg)
M.config_values["sniprun_root_dir"] = sniprun_path
M.notify("info",1,1,M.config_values, "")

if M.config_values.inline_messages ~= 0 then
vim.wait(300) -- let enough time for the sniprun binary to generate the file
print(" ")
local lines = lines_from(sniprun_path.."/ressources/infofile.txt")
-- print all lines content
M.display_lines_in_floating_win(table.concat(lines,"\n"))
end
else --help about a particular interpreter
vim.wait(500) -- let enough time for the sniprun binary to generate the file
print(" ")
local lines = lines_from(sniprun_path.."/ressources/infofile.txt")
-- print all lines content
M.display_lines_in_floating_win(lines)
else --help about a particular interpreter
local lines = lines_from(sniprun_path.."/doc/"..string.gsub(arg,"%s+","")..".md")
M.display_lines_in_floating_win(table.concat(lines,"\n"))
M.display_lines_in_floating_win(lines)
end
end

Expand All @@ -325,7 +318,7 @@ function M.health()
else health_ok("Rust toolchain found") end

if vim.fn.executable(binary_path) == 0 then health_error("sniprun binary not found!")
else health_ok("sniprun binary found") end
else health_ok("sniprun binary found at "..binary_path) end

local terminate_after = M.job_id == nil
local path_log_file = os.getenv('HOME').."/.cache/sniprun/sniprun.log"
Expand Down
17 changes: 14 additions & 3 deletions ressources/gitscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ get_latest_release() {
curl --silent "https://api.github.com/repos/michaelb/sniprun/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}

local_version=v$(cat Cargo.toml | grep version | cut -d "\"" -f 2)
local_version=v$(cat Cargo.toml | grep -m 1 version | cut -d "\"" -f 2)
remote_version=$(get_latest_release)

branch_name="$(git symbolic-ref HEAD 2>/dev/null)"

echo -n "Version : " $local_version
if [ $local_version == $remote_version ]; then
echo " (up-to-date)"
echo -n " (up-to-date)"
else
echo -n " (update to " $remote_version "is available)"
fi


if [[ "$branch_name" == *"dev" ]]; then
commit=$(git rev-parse --short HEAD)
echo -n " dev branch, git HEAD: $commit"
else
echo " (update to " $remote_version "is available)"
# on main branch, only show version
echo ""
fi
Loading

0 comments on commit 44acc11

Please sign in to comment.