Skip to content

Commit

Permalink
feat: add callbacks
Browse files Browse the repository at this point in the history
add events upon request start/stop so that users can customize rest.nvim
without modifying the plugin too much.
  • Loading branch information
teto committed Jul 11, 2023
1 parent 80283b7 commit dcea003
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lua/rest-nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,20 @@ rest.run_request = function(req, opts)
request.highlight(result.bufnr, result.start_line, result.end_line)
end

local request_id = vim.loop.now()
local data = {
requestId = request_id,
request = req
}

vim.api.nvim_exec_autocmds("User", {
pattern = "RestStartRequest",
modeline = false,
data = data
})
local success_req, req_err = pcall(curl.curl_cmd, Opts)
vim.api.nvim_exec_autocmds("User", { pattern = "RestStopRequest", modeline = false,
data = vim.tbl_extend("keep", { status = success_req, message = req_err }, data) })

if not success_req then
vim.api.nvim_err_writeln(
Expand Down

0 comments on commit dcea003

Please sign in to comment.