Skip to content

Commit b8d6c0a

Browse files
Fix finding the start and end of the current query. (#239)
1. start_request was searching forward from the cursor position. Adding 'b' to the search flags fixed that. 2. Both start_request and end_request depended on the user having set 'nowrapscan' to prevent wrapping around the end of the file. Such wrapping could result in finding the wrong query. Adding 'W' to the search flags fixed that, and removed the need for the stopline parameter. 3. Refactored the way last_line is used in end_request.
1 parent 139b4c3 commit b8d6c0a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lua/rest-nvim/request/init.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ local function start_request(bufnr, linenumber)
193193
local oldlinenumber = linenumber
194194
utils.move_cursor(bufnr, linenumber)
195195

196-
local res = vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE", "cn")
196+
local res = vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE", "bcnW")
197197
-- restore cursor position
198198
utils.move_cursor(bufnr, oldlinenumber)
199199

@@ -206,20 +206,19 @@ end
206206
local function end_request(bufnr, linenumber)
207207
-- store old cursor position
208208
local oldlinenumber = linenumber
209+
local last_line = vim.fn.line("$")
209210

210211
-- start searching for next request from the next line
211212
-- as the current line does contain the current, not the next request
212-
if linenumber < vim.fn.line("$") then
213+
if linenumber < last_line then
213214
linenumber = linenumber + 1
214215
end
215216
utils.move_cursor(bufnr, linenumber)
216217

217-
local next =
218-
vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE\\|^###\\", "cn", vim.fn.line("$"))
218+
local next = vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE\\|^###\\", "cnW")
219219

220220
-- restore cursor position
221221
utils.move_cursor(bufnr, oldlinenumber)
222-
local last_line = vim.fn.line("$")
223222

224223
if next == 0 or (oldlinenumber == last_line) then
225224
return last_line

0 commit comments

Comments
 (0)