Skip to content

Commit ce55212

Browse files
feat(commands): use command-modifiers like :tab
1 parent a9040da commit ce55212

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lua/rest-nvim/commands.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
---
2929
---@brief ]]
3030

31+
-- HACK: what is the type of opts here?
32+
3133
---@class RestCmd
32-
---@field impl fun(args:string[], opts: vim.api.keyset.user_command?) The command implementation
34+
---@field impl fun(args:string[], opts: any) The command implementation
3335
---@field complete? fun(subcmd_arg_lead: string): string[] Command completions callback, taking the lead of the subcommand's argument
3436

3537
local commands = {}
@@ -43,7 +45,7 @@ local logger = require("rest-nvim.logger")
4345
local rest_command_tbl = {
4446
run = {
4547
-- TODO: run request by name
46-
impl = function(args)
48+
impl = function(args, opts)
4749
if #args > 1 then
4850
vim.notify("Running request by name isn't supported yet", vim.log.levels.INFO)
4951
return
@@ -53,17 +55,25 @@ local rest_command_tbl = {
5355
end,
5456
},
5557
last = {
56-
impl = function(_)
58+
impl = function(_, _)
5759
request.run_last()
5860
end,
5961
},
6062
logs = {
61-
impl = function(_)
62-
vim.cmd.e(logger.get_logfile())
63+
impl = function(_, opts)
64+
local is_split = opts.smods.vertiacal or opts.smods.horizontal
65+
local is_tab = opts.smods.tab ~= -1
66+
if is_split or is_tab then
67+
---@diagnostic disable-next-line: invisible
68+
vim.cmd(opts.mods .. " split " .. logger.get_logfile())
69+
else
70+
---@diagnostic disable-next-line: invisible
71+
vim.cmd.edit(logger.get_logfile())
72+
end
6373
end,
6474
},
6575
env = {
66-
impl = function(args)
76+
impl = function(args, _)
6777
if not args[1] or args[1] == "show" then
6878
dotenv.show_registered_file()
6979
return
@@ -120,7 +130,7 @@ local function rest(opts)
120130
return
121131
end
122132

123-
command.impl(args)
133+
command.impl(args, opts)
124134
end
125135

126136
---@package

lua/rest-nvim/config/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ local default_config = {
8484
result = {
8585
---@class RestConfigResultWindow
8686
window = {
87+
-- TODO: use `:horizontal` instead. see `:h command-modifiers` and opts.smods
8788
---@type boolean Open request results in a horizontal split
8889
horizontal = false,
8990
---@type boolean Change the focus to the results window or stay in the current window (HTTP file)

0 commit comments

Comments
 (0)