Skip to content

Commit f16b420

Browse files
refactor!: big rewrite
- rewrite request parser - rewrite request runner - rewrite variables feature - variables are local to file and not vim session by default - ditch some config options & APIs - refactor user commands - `Rest run` **only** runs request below the cursor - `Rest all` runs all requests in current document - `Rest env select` to select env file with `vim.ui.select` - `Rest result` : deprecated
1 parent e7843c5 commit f16b420

32 files changed

+975
-1280
lines changed

.busted

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
return {
2+
_all = {
3+
coverage = false,
4+
lpath = "lua/?.lua;lua/?/init.lua",
5+
lua = "nlua",
6+
},
7+
default = {
8+
verbose = true,
9+
},
10+
tests = {
11+
verbose = true,
12+
},
13+
}

.luarc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
3+
"runtime": {
4+
"version": "LuaJIT"
5+
},
6+
"workspace": {
7+
"library": [
8+
"lua",
9+
"$VIMRUNTIME",
10+
"${3rd}/luassert/library",
11+
"${3rd}/busted/library"
12+
],
13+
"checkThirdParty": "Disable"
14+
},
15+
"diagnostics": {
16+
"unusedLocalExclude": [ "_*" ]
17+
}
18+
}

README.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ get a good experience during autocompletion :)
121121
122122
```lua
123123
local default_config = {
124-
client = "curl",
125-
env_file = ".env",
126124
env_pattern = "\\.env$",
127125
env_edit_command = "tabedit",
128126
encode_url = true,
@@ -176,30 +174,14 @@ local default_config = {
176174
},
177175
},
178176
keybinds = {
179-
buffer_local = true,
180177
prev = "H",
181178
next = "L",
182179
},
183180
},
184181
highlight = {
185182
enable = true,
186-
timeout = 750,
183+
timeout = 250,
187184
},
188-
---Example:
189-
---
190-
---```lua
191-
---keybinds = {
192-
--- {
193-
--- "<localleader>rr", "<cmd>Rest run<cr>", "Run request under the cursor",
194-
--- },
195-
--- {
196-
--- "<localleader>rl", "<cmd>Rest run last<cr>", "Re-run latest request",
197-
--- },
198-
---}
199-
---
200-
---```
201-
---@see vim.keymap.set
202-
keybinds = {},
203185
}
204186
```
205187

after/queries/http/highlights.scm

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
; Keywords
2-
(scheme) @module
3-
4-
; Methods
5-
(method) @function.method
6-
7-
; Constants
8-
(const_spec) @constant
9-
10-
; Headers
11-
(header
12-
name: (name) @constant)
13-
14-
; Variables
15-
(variable_declaration
16-
name: (identifier) @variable)
17-
18-
(variable_declaration
19-
value: (number) @number)
20-
21-
(variable_declaration
22-
value: (boolean) @boolean)
23-
24-
(variable_declaration
25-
value: (string) @string)
26-
27-
; Fields
28-
(pair
29-
name: (identifier) @variable.member)
30-
31-
; URL / Host
32-
(host) @string.special.url
33-
34-
(host
35-
(identifier) @string.special.url)
36-
37-
(path
38-
(identifier) @string.special.url)
39-
40-
; Parameters
41-
(query_param
42-
(key) @variable.parameter)
43-
44-
; Operators
45-
[
46-
"="
47-
"?"
48-
"&"
49-
"@"
50-
"<"
51-
] @operator
52-
53-
; Literals
54-
(target_url) @string.special.url
55-
56-
(http_version) @constant
57-
58-
(string) @string
59-
60-
(number) @number
61-
62-
(boolean) @boolean
63-
64-
; Punctuation
65-
[
66-
"{{"
67-
"}}"
68-
] @punctuation.bracket
69-
70-
":" @punctuation.delimiter
71-
72-
; external JSON body
73-
(external_body
74-
file_path: (path) @string.special.path)
75-
76-
; Comments
77-
(comment) @comment @spell
1+
; ; Keywords
2+
; (scheme) @module
3+
;
4+
; ; Methods
5+
; (method) @function.method
6+
;
7+
; ; Constants
8+
; (const_spec) @constant
9+
;
10+
; ; Headers
11+
; (header
12+
; name: (name) @constant)
13+
;
14+
; ; Variables
15+
; (variable_declaration
16+
; name: (identifier) @variable)
17+
;
18+
; (variable_declaration
19+
; value: (number) @number)
20+
;
21+
; (variable_declaration
22+
; value: (boolean) @boolean)
23+
;
24+
; (variable_declaration
25+
; value: (string) @string)
26+
;
27+
; ; Fields
28+
; (pair
29+
; name: (identifier) @variable.member)
30+
;
31+
; ; URL / Host
32+
; (host) @string.special.url
33+
;
34+
; (host
35+
; (identifier) @string.special.url)
36+
;
37+
; (path
38+
; (identifier) @string.special.url)
39+
;
40+
; ; Parameters
41+
; (query_param
42+
; (key) @variable.parameter)
43+
;
44+
; ; Operators
45+
; [
46+
; "="
47+
; "?"
48+
; "&"
49+
; "@"
50+
; "<"
51+
; ] @operator
52+
;
53+
; ; Literals
54+
; (target_url) @string.special.url
55+
;
56+
; (http_version) @constant
57+
;
58+
; (string) @string
59+
;
60+
; (number) @number
61+
;
62+
; (boolean) @boolean
63+
;
64+
; ; Punctuation
65+
; [
66+
; "{{"
67+
; "}}"
68+
; ] @punctuation.bracket
69+
;
70+
; ":" @punctuation.delimiter
71+
;
72+
; ; external JSON body
73+
; (external_body
74+
; file_path: (path) @string.special.path)
75+
;
76+
; ; Comments
77+
; (comment) @comment @spell

after/queries/http/injections.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
(#set! injection.language "graphql"))
1414

1515
; Lua scripting
16-
((script_variable) @injection.content
16+
((script) @injection.content
1717
(#set! injection.language "lua"))

ftplugin/http.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
vim.bo.commentstring = "# %s"
2+
3+
local commands = require("rest-nvim.commands")
4+
commands.init(0)

lua/lualine/components/rest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222
function M.update_status()
2323
local current_filetype = vim.bo.filetype
2424
if current_filetype == "http" then
25-
return _G._rest_nvim.env_file
25+
return vim.b._rest_nvim_env_file
2626
end
2727
return ""
2828
end

lua/rest-nvim/api.lua

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99

1010
local api = {}
1111

12-
local keybinds = require("rest-nvim.keybinds")
1312
local autocmds = require("rest-nvim.autocmds")
1413
local commands = require("rest-nvim.commands")
1514

1615
---rest.nvim API version, equals to the current rest.nvim version. Meant to be used by modules later
1716
---@type string
1817
---@see vim.version
19-
api.VERSION = "2.0.0"
18+
api.VERSION = "3.0.0"
2019

2120
---rest.nvim namespace used for buffer highlights
2221
---@type number
@@ -41,39 +40,4 @@ function api.register_rest_subcommand(name, cmd)
4140
commands.register_subcommand(name, cmd)
4241
end
4342

44-
---Register a new keybinding
45-
---@see vim.keymap.set
46-
---
47-
---@param mode string Keybind mode
48-
---@param lhs string Keybind trigger
49-
---@param cmd string Command to be run
50-
---@param opts table Keybind options
51-
function api.register_rest_keybind(mode, lhs, cmd, opts)
52-
keybinds.register_keybind(mode, lhs, cmd, opts)
53-
end
54-
55-
---Execute all the pre-request hooks, functions that are meant to run before executing a request
56-
---
57-
---This function is called automatically during the execution of the requests, invoking it again could cause inconveniences
58-
---@see vim.api.nvim_exec_autocmds
59-
---@package
60-
function api.exec_pre_request_hooks()
61-
vim.api.nvim_exec_autocmds("User", {
62-
pattern = "RestStartRequest",
63-
modeline = false,
64-
})
65-
end
66-
67-
---Execute all the post-request hooks, functions that are meant to run after executing a request
68-
---
69-
---This function is called automatically during the execution of the requests, invoking it again could cause inconveniences
70-
---@see vim.api.nvim_exec_autocmds
71-
---@package
72-
function api.exec_post_request_hooks()
73-
vim.api.nvim_exec_autocmds("User", {
74-
pattern = "RestStopRequest",
75-
modeline = false,
76-
})
77-
end
78-
7943
return api

lua/rest-nvim/autocmds.lua

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,29 @@
88

99
local autocmds = {}
1010

11-
local commands = require("rest-nvim.commands")
12-
local functions = require("rest-nvim.functions")
11+
local result = require("rest-nvim.result")
1312
local result_help = require("rest-nvim.result.help")
1413

15-
---Set up Rest autocommands group and set `:Rest` command on `*.http` files
14+
---Set up Rest autocommands group
1615
function autocmds.setup()
1716
local rest_nvim_augroup = vim.api.nvim_create_augroup("Rest", {})
1817
local keybinds = _G._rest_nvim.result.keybinds
19-
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
20-
group = rest_nvim_augroup,
21-
pattern = "*.http",
22-
callback = function(args)
23-
commands.init(args.buf)
24-
end,
25-
desc = "Set up rest.nvim commands",
26-
})
2718

2819
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
2920
group = rest_nvim_augroup,
3021
pattern = "rest_nvim_results",
3122
callback = function(args)
3223
vim.keymap.set("n", keybinds.prev, function()
33-
functions.cycle_result_pane("prev")
24+
result.cycle_pane(-1)
3425
end, {
3526
desc = "Go to previous winbar pane",
36-
buffer = keybinds.buffer_local and args.buf or nil,
27+
buffer = args.buf,
3728
})
3829
vim.keymap.set("n", keybinds.next, function()
39-
functions.cycle_result_pane("next")
30+
result.cycle_pane(1)
4031
end, {
4132
desc = "Go to next winbar pane",
42-
buffer = keybinds.buffer_local and args.buf or nil,
33+
buffer = args.buf,
4334
})
4435
vim.keymap.set("n", "?", result_help.open, {
4536
desc = "Open rest.nvim request results help window",

0 commit comments

Comments
 (0)