Skip to content

Commit

Permalink
fix #51: body_start is calculated correctly even if the last request has
Browse files Browse the repository at this point in the history
no body
  • Loading branch information
jens1205 committed Aug 24, 2021
1 parent e0f023e commit 52448f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lua/rest-nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,14 @@ end

-- get_headers retrieves all the found headers and returns a lua table with them
-- @param bufnr Buffer number, a.k.a id
-- @param query_line Line to set cursor position
local function get_headers(bufnr, query_line)
-- @param start_line Line where the request starts
-- @param end_line Line where the request ends
local function get_headers(bufnr, start_line, end_line)
local headers = {}
-- Set stop at end of buffer
local stop_line = vim.fn.line("$")
local body_start = 0
local body_start = end_line

-- Iterate over all buffer lines
for line_number = query_line + 1, stop_line do
-- Iterate over all buffer lines starting after the request line
for line_number = start_line + 1, end_line do
local line = vim.fn.getbufline(bufnr, line_number)
local line_content = line[1]

Expand Down Expand Up @@ -302,15 +301,15 @@ rest.run = function(verbose)

local start_line = start_request()
if start_line == 0 then
error("[rest.nvim]: No request found")
vim.api.nvim_err_writeln("[rest.nvim]: No request found")
return
end
local end_line = end_request()
go_to_line(bufnr, start_line)

local parsed_url = parse_url(vim.fn.getline(start_line))

local headers, body_start = get_headers(bufnr, start_line)
local headers, body_start = get_headers(bufnr, start_line, end_line)

local body = get_body(bufnr, body_start, end_line)

Expand Down
File renamed without changes.

0 comments on commit 52448f5

Please sign in to comment.