Skip to content

Commit 7604c36

Browse files
docs: update
1 parent 9346bcc commit 7604c36

File tree

9 files changed

+86
-40
lines changed

9 files changed

+86
-40
lines changed

doc/rest-nvim-api.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,27 @@ utils.ts_highlight_node({bufnr}, {node}, {ns})
192192
{ns} (number)
193193

194194

195-
utils.ts_parse_source({source}) *utils.ts_parse_source*
195+
utils.ts_get_parser({source}) *utils.ts_get_parser*
196196

197197
Parameters: ~
198198
{source} (string|integer)
199199

200200
Returns: ~
201201
(vim.treesitter.LanguageTree)
202-
(TSTree)
203202

204203

205-
utils.ts_find({node}, {type}) *utils.ts_find*
204+
utils.ts_parse_source({source}) *utils.ts_parse_source*
206205

207206
Parameters: ~
208-
{node} (TSNode)
209-
{type} (string) @return TSNode?
207+
{source} (string|integer)
208+
209+
Returns: ~
210+
(vim.treesitter.LanguageTree)
211+
(TSTree)
212+
213+
214+
utils.ts_find() *utils.ts_find*
215+
@return TSNode?
210216

211217

212218
utils.ts_upper_node({node}) *utils.ts_upper_node*

doc/rest-nvim.txt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ rest.nvim *rest-nvim*
55
A fast and asynchronous Neovim HTTP client written in Lua
66

77

8+
==============================================================================
9+
Table of Contents *rocks-contents*
10+
11+
rest.nvim ·························································· |rest-nvim|
12+
rest.nvim commands ········································ |rest-nvim.commands|
13+
rest.nvim configuration ····································· |rest-nvim.config|
14+
815
rest.setup({user_configs?}) *rest.setup*
9-
@deprecated
16+
@deprecated use `vim.g.rest_nvim` instead
1017
Set up rest.nvim
1118
This api does nothing but set `vim.g.rest_nvim` to `user_configs`
1219

@@ -58,15 +65,6 @@ rest.nvim commands *rest-nvim.commands*
5865
split
5966

6067

61-
RestCmd *RestCmd*
62-
63-
Fields: ~
64-
{impl} (fun) The command implementation
65-
66-
67-
commands.setup() *commands.setup*
68-
69-
7068
==============================================================================
7169
rest.nvim configuration *rest-nvim.config*
7270

@@ -106,7 +104,10 @@ rest.Opts.Request *rest.Opts.Request*
106104
rest.Opts.Request.Hooks *rest.Opts.Request.Hooks*
107105

108106
Fields: ~
109-
{encode_url?} (boolean) Encode URL before making request (Default: `true`)
107+
{encode_url?} (boolean) Encode URL before making request (Default: `true`)
108+
{user_agent?} (string) Set `User-Agent` header when it is empty. Set as empty string to disable.
109+
(Default: `rest.nvim {version}`)
110+
{set_content_type?} (boolean) Set `Content-Type` header when it is empty but request body is provided
110111

111112

112113
rest.Opts.Response *rest.Opts.Response*

lua/rest-nvim/autocmds.lua

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
11
---@mod rest-nvim.autocmds rest.nvim autocommands
22
---
3+
---@mod rest-nvim.autocmds rest.nvim autocommands
4+
---
35
---@brief [[
46
---
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+
---<
643
---
744
---@brief ]]
845

946
local autocmds = {}
1047

1148
---Set up Rest autocommands group
49+
---@package
1250
function autocmds.setup()
1351
vim.api.nvim_create_augroup("Rest", { clear = true })
1452

lua/rest-nvim/commands.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@
3737
--- copying command to clipboard, directly insert curl
3838
--- command as a comment.
3939
---
40-
--- NOTE: All `:Rest` commands opening new window support |command-modifiers|.
41-
--- For example, you can run `:hor Rest open` to open result pane in horizontal
42-
--- split
40+
---NOTE: All `:Rest` commands opening new window support |command-modifiers|.
41+
---For example, you can run `:hor Rest open` to open result pane in horizontal
42+
---split or run `:tab Rest logs` to open logs file in a new tab.
4343
---
4444
---@brief ]]
4545

46-
-- HACK: what is the type of opts here?
47-
46+
---@package
4847
---@class RestCmd
4948
---The command implementation
5049
---@field impl fun(args:string[], opts: table?)
@@ -269,6 +268,7 @@ local function rest(opts)
269268
command.impl(args, opts)
270269
end
271270

271+
---@package
272272
function commands.setup()
273273
vim.api.nvim_create_user_command("Rest", rest, {
274274
nargs = "+",

lua/rest-nvim/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
---
77
---@brief ]]
88

9+
---@toc rocks-contents
10+
911
local rest = {}
1012

11-
---@deprecated
13+
---@deprecated use `vim.g.rest_nvim` instead
1214
---Set up rest.nvim
1315
---This api does nothing but set `vim.g.rest_nvim` to `user_configs`
1416
---@param user_configs? rest.Opts User configurations

lua/rest-nvim/request.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ local Context = require("rest-nvim.context").Context
2626
---@field body? rest.Request.Body
2727
---@field handlers fun()[]
2828

29+
---@class rest.Response
30+
---@field status rest.Response.status Status information from response
31+
---@field body string? Raw response body
32+
---@field headers table<string,string[]> Response headers
33+
---@field statistics table<string,string> Response statistics
34+
35+
---@class rest.Response.status
36+
---@field code number
37+
---@field version string
38+
---@field text string
39+
2940
---@type rest.Request|nil
3041
local rest_nvim_last_request = nil
3142

@@ -65,9 +76,6 @@ local function run_request(req)
6576
vim.iter(req.handlers):each(function (f) f(res) end)
6677
logger.info("handler done")
6778

68-
-- update cookie jar
69-
jar.update_jar(req.url, res)
70-
7179
_G.rest_request = req
7280
_G.rest_response = res
7381
vim.api.nvim_exec_autocmds("User", {
@@ -76,6 +84,9 @@ local function run_request(req)
7684
_G.rest_request = nil
7785
_G.rest_response = nil
7886

87+
-- update cookie jar
88+
jar.update_jar(req.url, res)
89+
7990
-- update result UI
8091
ui.update({response = res})
8192
end)

lua/rest-nvim/response.lua

Lines changed: 0 additions & 14 deletions
This file was deleted.

lua/rest-nvim/ui/result.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ local panes = {
7979
elseif res_type == "octet_stream" then
8080
body = { "Binary answer" }
8181
elseif config.response.hooks.format then
82+
-- NOTE: format hook runs here because it should be done last.
8283
body = utils.gq_lines(body, res_type)
8384
end
8485
end

plugin/rest-nvim.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---@diagnostic disable: invisible
12
if vim.fn.has("nvim-0.9.0") ~= 1 then
23
vim.notify_once("[rest.nvim] rest.nvim requires at least Neovim >= 0.9 in order to work")
34
return

0 commit comments

Comments
 (0)