Skip to content

Commit dfa7669

Browse files
committed
refactor: use table for adding headers to buffer
1 parent 897c72e commit dfa7669

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lua/rest-nvim/init.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,16 @@ local function curl_cmd(opts)
231231
end
232232

233233
--- Add metadata into the created buffer (status code, date, etc)
234-
local line_count = api.nvim_buf_line_count(res_bufnr) - 1
235234
-- Request statement (METHOD URL)
236235
api.nvim_buf_set_lines(
237236
res_bufnr,
238-
line_count,
239-
line_count,
237+
0,
238+
0,
240239
false,
241240
{ parsed_url.method .. ' ' .. parsed_url.url }
242241
)
243242
-- HTTP version, status code and its meaning, e.g. HTTP/1.1 200 OK
244-
line_count = api.nvim_buf_line_count(res_bufnr)
243+
local line_count = api.nvim_buf_line_count(res_bufnr)
245244
api.nvim_buf_set_lines(
246245
res_bufnr,
247246
line_count,
@@ -250,10 +249,13 @@ local function curl_cmd(opts)
250249
{ 'HTTP/1.1 ' .. utils.http_status(res.status) }
251250
)
252251
-- Headers, e.g. Content-Type: application/json
253-
for _, header in ipairs(res.headers) do
254-
line_count = api.nvim_buf_line_count(res_bufnr)
255-
api.nvim_buf_set_lines(res_bufnr, line_count, line_count, false, { header })
256-
end
252+
api.nvim_buf_set_lines(
253+
res_bufnr,
254+
line_count + 1,
255+
line_count + #res.headers,
256+
false,
257+
res.headers
258+
)
257259

258260
--- Add the curl command results into the created buffer
259261
if json_body then

0 commit comments

Comments
 (0)