Skip to content

Commit

Permalink
feat(hurl): add command to re-run last Hurl command
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Oct 27, 2024
1 parent d556c9b commit 4b86f35
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ local function run_selection(opts)
end, timeout)
end

-- Store the last used from_entry and to_entry
local last_from_entry
local last_to_entry

-- Run at current line
---@param start_line number
---@param end_line number|nil
Expand All @@ -69,6 +73,10 @@ local function run_at_lines(start_line, end_line, opts, callback)
table.insert(opts, tostring(end_line))
end

-- Store the last used from_entry and to_entry
last_from_entry = start_line
last_to_entry = end_line

hurl_runner.execute_hurl_cmd(opts, callback)
end

Expand Down Expand Up @@ -342,6 +350,38 @@ function M.setup()
utils.notify('hurl: no HTTP method found in the current line', vim.log.levels.INFO)
end
end, { nargs = '*', range = true })

-- Re-run last Hurl command
utils.create_cmd('HurlRerun', function()
if last_from_entry then
utils.log_info(
string.format(
'hurl: re-running last command from entry %d to %s',
last_from_entry,
last_to_entry or 'end'
)
)
utils.notify('hurl: re-running last command', vim.log.levels.INFO)

local opts = {}
local file_path = vim.fn.expand('%:p')

-- Reconstruct the command with the stored from_entry and to_entry
table.insert(opts, file_path)
table.insert(opts, '--from-entry')
table.insert(opts, tostring(last_from_entry))
if last_to_entry then
table.insert(opts, '--to-entry')
table.insert(opts, tostring(last_to_entry))
end

-- Execute the command
hurl_runner.execute_hurl_cmd(opts)
else
utils.log_info('hurl: no previous command to re-run')
utils.notify('hurl: no previous command to re-run', vim.log.levels.WARN)
end
end, { nargs = 0 })
end

return M

0 comments on commit 4b86f35

Please sign in to comment.