|
1 | 1 | ---@mod rest-nvim.autocmds rest.nvim autocommands |
2 | 2 | --- |
| 3 | +---@mod rest-nvim.autocmds rest.nvim autocommands |
| 4 | +--- |
3 | 5 | ---@brief [[ |
4 | 6 | --- |
5 | | ---- rest.nvim autocommands |
| 7 | +--- rest.nvim user events |
| 8 | +--- |
| 9 | +---rest.nvim provides several |User| |events|. |
| 10 | +--- |
| 11 | +---RestRequest or RestRequestPre *RestRequest* *RestRequestPre* |
| 12 | +--- Just before executing a request. The request object (with |rest.Request| |
| 13 | +--- type) will be temporarily assigned to the global variable `rest_request`. |
| 14 | +--- Modifing this variable will affect the actual request. Example: >lua |
| 15 | +--- |
| 16 | +--- vim.api.nvim_create_autocmd("User", { |
| 17 | +--- pattern = "RestRequestPre", |
| 18 | +--- callback = function() |
| 19 | +--- local req = _G.rest_request |
| 20 | +--- req.headers["user-agent"] = { "myneovim" } |
| 21 | +--- end, |
| 22 | +--- }) |
| 23 | +---< |
| 24 | +--- |
| 25 | +---RestResponse or RestResponsePre *RestResponse* *RestResponsePre* |
| 26 | +--- After received the response and all response handlers are executed. |
| 27 | +--- The request and response objects (|rest.Request| and |rest.Response| |
| 28 | +--- types) will be termporarily assigned to the global variabels |
| 29 | +--- `rest_request` and `rest_response`. Modifing this variable won't affect |
| 30 | +--- response handlers but updating cookies and rendering result UI will be |
| 31 | +--- affected. Example: >lua |
| 32 | +--- |
| 33 | +--- vim.api.nvim_create_autocmd("User", { |
| 34 | +--- pattern = "RestResponsePre", |
| 35 | +--- callback = function() |
| 36 | +--- local req = _G.rest_request |
| 37 | +--- local res = _G.rest_response |
| 38 | +--- req.url = url_decode(req.url) |
| 39 | +--- res.body = trim_trailing_whitespace(res.body) |
| 40 | +--- end, |
| 41 | +--- }) |
| 42 | +---< |
6 | 43 | --- |
7 | 44 | ---@brief ]] |
8 | 45 |
|
9 | 46 | local autocmds = {} |
10 | 47 |
|
11 | 48 | ---Set up Rest autocommands group |
| 49 | +---@package |
12 | 50 | function autocmds.setup() |
13 | 51 | vim.api.nvim_create_augroup("Rest", { clear = true }) |
14 | 52 |
|
|
0 commit comments