Skip to content

Commit

Permalink
Merge pull request #38 from Klafyvel/v0.4-damage-control
Browse files Browse the repository at this point in the history
V0.4 damage control
  • Loading branch information
Klafyvel authored Sep 11, 2024
2 parents 5aa3f76 + 59bd4ca commit fad6915
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

Neo-Vim companion plugin for [REPLSmuggler.jl](https://github.com/klafyvel/REPLSmuggler.jl). Send code to your Julia REPL, and get Neo-Vim diagnostics in return.

> [!WARNING]
> NeoVim 0.10 or later is required.

## Demo

Expand Down
14 changes: 14 additions & 0 deletions lua/smuggler/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local M = {}

M.check = function()
vim.health.start("nvim-smuggler report")
-- make sure setup function parameters are ok
if vim.fn.has("nvim-0.10") == 1 then
vim.health.ok("Neovim version is OK.")
else
vim.health.error("Neovim ≥ 0.10 is required for nvim-smuggler.")
end
end

return M

8 changes: 7 additions & 1 deletion lua/smuggler/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
local smuggler = {}
local log = require("smuggler.log")

if vim.fn.has("nvim-0.10") ~= 1 then
log.warn("Neovim ≥ 0.10 is required.")
smuggler.setup = function(opts) end
return smuggler
end

local protocol = require("smuggler.protocol")
local slime = require("smuggler.reslime")
local smuggler_ui = require("smuggler.ui")
local log = require("smuggler.log")

smuggler.send_range = slime.send_range
smuggler.send_lines = slime.send_lines
Expand Down
12 changes: 10 additions & 2 deletions lua/smuggler/partial_mpack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ BYTE_FORMATS = {
-- number of elements to consume, or to a function that yields that answer.
local LENGTH_DISPATCH = {}

local DEBUG_LABELS = {}

for k, v in pairs(BYTE_FORMATS) do
if v.tag ~= nil then
LENGTH_DISPATCH[v.tag] = {v.length, v.final, v.headerlength}
DEBUG_LABELS[v.tag] = k
else
for i=v.tagmin,v.tagmax do
LENGTH_DISPATCH[i] = {v.length, v.final, v.headerlength}
DEBUG_LABELS[i] = k
end
end
end
Expand All @@ -103,29 +107,32 @@ function M.first_element_length(buffer, offset)
end
local first_byte = string.byte(buffer, offset)
local length, isfinal, headerlength = unpack(LENGTH_DISPATCH[first_byte])
log.trace("First element length determination. First byte = ", first_byte, " length=", length)
local result = 0
local success = true
if type(length) ~= "number" then
length = length(buffer, offset)
success = length ~= nil
end
log.trace("First element length determination. This is a ", DEBUG_LABELS[first_byte], " First byte = ", first_byte, " length=", length, " headerlength=", headerlength, " isfinal=", isfinal)
if success then
if isfinal then -- The length is a length in bytes
result = length + headerlength
success = result <= #buffer-offset+1
else -- This is a container, the length is in elements
log.trace("Iterating through a container.")
result = headerlength
buffer_position = offset + headerlength
local buffer_position = offset + headerlength
for i=1,length do
log.trace("Doing element ", i, " of ", DEBUG_LABELS[first_byte])
local element_success, element_length = M.first_element_length(buffer, buffer_position)
if not element_success then
success = false
break
end
log.trace("Adding length ", element_length, " to ", DEBUG_LABELS[first_byte])
result = result + element_length
buffer_position = buffer_position + element_length
log.trace("full container is :", string.sub(buffer, offset, buffer_position-1))
end
if success then
success = result <= #buffer-offset+1
Expand All @@ -141,6 +148,7 @@ function M.decode_one(buffer)
if success and (length <= #buffer) then
log.trace("Decoding for length ", length)
local chunk = string.sub(buffer, 1, length)
log.trace("Chunk is:", chunk)
success, result = pcall(vim.mpack.decode, chunk)
else
success = false
Expand Down
2 changes: 1 addition & 1 deletion lua/smuggler/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function ui.create_user_commands()
desc = "Hide smuggler's diagnostics loclist.",
})
vim.api.nvim_create_user_command("SmuggleHideEvaluated", function(_)
ui.hidechunk_highlights(vim.api.nvim_get_current_buf())
ui.hide_chunk_highlights(vim.api.nvim_get_current_buf())
end, {
desc = "Hide highlight around evaluated chunks.",
})
Expand Down

0 comments on commit fad6915

Please sign in to comment.