@@ -66,13 +66,28 @@ local function config() return require("rest-nvim.config") end
66
66
--- Open window based on command mods and return new window identifier
67
67
--- @param opts table
68
68
--- @return integer winnr
69
+ --- @return boolean did_split
69
70
local function split_open_cmd (opts )
70
71
local is_split = opts .smods .vertical or opts .smods .horizontal
71
72
local is_tab = opts .smods .tab ~= - 1
72
73
if is_split or is_tab then
73
74
vim .cmd (opts .mods .. " split" )
74
75
end
75
- return vim .api .nvim_get_current_win ()
76
+ return vim .api .nvim_get_current_win (), (is_split or is_tab )
77
+ end
78
+
79
+ --- @param opts table
80
+ local function open_result_ui (opts )
81
+ if ui ().is_open () then
82
+ return
83
+ end
84
+ local winnr , did_split = split_open_cmd (opts )
85
+ if not did_split then
86
+ vim .cmd .wincmd (" v" )
87
+ winnr = vim .api .nvim_get_current_win ()
88
+ end
89
+ ui ().enter (winnr )
90
+ vim .cmd .wincmd (" p" )
76
91
end
77
92
78
93
--- @type table<string , RestCmd>
@@ -84,7 +99,7 @@ local rest_command_tbl = {
84
99
end ,
85
100
},
86
101
run = {
87
- impl = function (args , _ )
102
+ impl = function (args , opts )
88
103
if vim .bo .filetype ~= " http" or vim .b .__rest_no_http_file then
89
104
vim .notify (
90
105
" `:Rest run` can be only called from http file" ,
@@ -97,12 +112,16 @@ local rest_command_tbl = {
97
112
vim .notify (" Running multiple request isn't supported yet" , vim .log .levels .WARN , { title = " rest.nvim" })
98
113
return
99
114
end
100
- ui ().clear ()
101
- if not ui ().is_open () then
102
- vim .cmd .wincmd (" v" )
103
- ui ().enter (0 )
104
- vim .cmd .wincmd (" p" )
115
+ if opts .smods .tab ~= - 1 then
116
+ vim .notify (
117
+ " `:Rest run` cannot be run with `:tab` command modifier" ,
118
+ vim .log .levels .ERROR ,
119
+ { title = " rest.nvim" }
120
+ )
121
+ return
105
122
end
123
+ ui ().clear ()
124
+ open_result_ui (opts )
106
125
request ().run (args [1 ])
107
126
end ,
108
127
--- @return string[]
@@ -121,7 +140,17 @@ local rest_command_tbl = {
121
140
end ,
122
141
},
123
142
last = {
124
- impl = function (_ , _ )
143
+ impl = function (_ , opts )
144
+ if opts .smods .tab ~= - 1 then
145
+ vim .notify (
146
+ " `:Rest last` cannot be run with `:tab` command modifier" ,
147
+ vim .log .levels .ERROR ,
148
+ { title = " rest.nvim" }
149
+ )
150
+ return
151
+ end
152
+ ui ().clear ()
153
+ open_result_ui (opts )
125
154
request ().run_last ()
126
155
end ,
127
156
},
@@ -281,6 +310,7 @@ function commands.setup()
281
310
vim .api .nvim_create_user_command (" Rest" , rest , {
282
311
nargs = " +" ,
283
312
desc = " Run your HTTP requests" ,
313
+ bar = true ,
284
314
complete = function (arg_lead , cmdline , _ )
285
315
local rest_commands = vim .tbl_keys (rest_command_tbl )
286
316
local subcmd , subcmd_arg_lead = cmdline :match (" Rest*%s(%S+)%s(.*)$" )
0 commit comments