@@ -66,13 +66,28 @@ local function config() return require("rest-nvim.config") end
6666--- Open window based on command mods and return new window identifier
6767--- @param opts table
6868--- @return integer winnr
69+ --- @return boolean did_split
6970local function split_open_cmd (opts )
7071 local is_split = opts .smods .vertical or opts .smods .horizontal
7172 local is_tab = opts .smods .tab ~= - 1
7273 if is_split or is_tab then
7374 vim .cmd (opts .mods .. " split" )
7475 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" )
7691end
7792
7893--- @type table<string , RestCmd>
@@ -84,7 +99,7 @@ local rest_command_tbl = {
8499 end ,
85100 },
86101 run = {
87- impl = function (args , _ )
102+ impl = function (args , opts )
88103 if vim .bo .filetype ~= " http" or vim .b .__rest_no_http_file then
89104 vim .notify (
90105 " `:Rest run` can be only called from http file" ,
@@ -97,12 +112,16 @@ local rest_command_tbl = {
97112 vim .notify (" Running multiple request isn't supported yet" , vim .log .levels .WARN , { title = " rest.nvim" })
98113 return
99114 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
105122 end
123+ ui ().clear ()
124+ open_result_ui (opts )
106125 request ().run (args [1 ])
107126 end ,
108127 --- @return string[]
@@ -121,7 +140,17 @@ local rest_command_tbl = {
121140 end ,
122141 },
123142 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 )
125154 request ().run_last ()
126155 end ,
127156 },
@@ -281,6 +310,7 @@ function commands.setup()
281310 vim .api .nvim_create_user_command (" Rest" , rest , {
282311 nargs = " +" ,
283312 desc = " Run your HTTP requests" ,
313+ bar = true ,
284314 complete = function (arg_lead , cmdline , _ )
285315 local rest_commands = vim .tbl_keys (rest_command_tbl )
286316 local subcmd , subcmd_arg_lead = cmdline :match (" Rest*%s(%S+)%s(.*)$" )
0 commit comments