@@ -46,10 +46,28 @@ local function ui() return require("rest-nvim.ui.result") end
4646local function config () return require (" rest-nvim.config" ) end
4747-- stylua: ignore end
4848
49+ --- Open window based on command mods and return new window identifier
50+ --- @param opts table
51+ --- @return integer winnr
52+ local function split_open_cmd (opts )
53+ local is_split = opts .smods .vertical or opts .smods .horizontal
54+ local is_tab = opts .smods .tab ~= - 1
55+ if is_split or is_tab then
56+ vim .cmd (opts .mods .. " split" )
57+ end
58+ return vim .api .nvim_get_current_win ()
59+ end
60+
4961--- @type table<string , RestCmd>
5062local rest_command_tbl = {
63+ open = {
64+ impl = function (_ , opts )
65+ local winnr = split_open_cmd (opts )
66+ ui ().enter (winnr )
67+ end
68+ },
5169 run = {
52- impl = function (args , _opts )
70+ impl = function (args , _ )
5371 if vim .bo .filetype ~= " http" or vim .b .__rest_no_http_file then
5472 vim .notify (" `:Rest run` can be only called from http file" , vim .log .levels .ERROR )
5573 return
@@ -62,8 +80,11 @@ local rest_command_tbl = {
6280 return
6381 end
6482 ui ().clear ()
65- -- TODO: open result window here (use `:horizontal`)
66- ui ().open_ui ()
83+ if not ui ().is_open () then
84+ vim .cmd .wincmd (" v" )
85+ ui ().enter (0 )
86+ vim .cmd .wincmd (" p" )
87+ end
6788 request ().run ()
6889 end ,
6990 --- @return string[]
@@ -85,28 +106,19 @@ local rest_command_tbl = {
85106 },
86107 logs = {
87108 impl = function (_ , opts )
88- local is_split = opts .smods .vertiacal or opts .smods .horizontal
89- local is_tab = opts .smods .tab ~= - 1
90- if is_split or is_tab then
91- --- @diagnostic disable-next-line : invisible
92- vim .cmd (opts .mods .. " split " .. logger ().get_logfile ())
93- else
109+ local winnr = split_open_cmd (opts )
110+ vim .api .nvim_win_call (winnr , function ()
94111 --- @diagnostic disable-next-line : invisible
95112 vim .cmd .edit (logger ().get_logfile ())
96- end
113+ end )
97114 end ,
98115 },
99116 cookies = {
100117 impl = function (_ , opts )
101- local is_split = opts .smods .vertiacal or opts .smods .horizontal
102- local is_tab = opts .smods .tab ~= - 1
103- if is_split or is_tab then
104- --- @diagnostic disable-next-line : invisible
105- vim .cmd (opts .mods .. " split " .. config ().cookies .path )
106- else
107- --- @diagnostic disable-next-line : invisible
118+ local winnr = split_open_cmd (opts )
119+ vim .api .nvim_win_call (winnr , function ()
108120 vim .cmd .edit (config ().cookies .path )
109- end
121+ end )
110122 end ,
111123 },
112124 env = {
0 commit comments