From 310109fc8ba475a43dff8a9a86dc84d5f7f8e3e7 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:52:35 +0000 Subject: [PATCH] feat: Updated lua/hurl/main.lua --- lua/hurl/main.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/lua/hurl/main.lua b/lua/hurl/main.lua index fcd2cbb..efa4a58 100644 --- a/lua/hurl/main.lua +++ b/lua/hurl/main.lua @@ -226,7 +226,56 @@ local function find_http_verb(line, current_line_number) return nil end - local verbs = { 'GET', 'POST', 'PUT', 'DELETE', 'PATCH' } + local httpVerbs = { 'GET', 'POST', 'PUT', 'DELETE', 'PATCH' } + local verb_start, verb_end, verb + + for _, httpVerb in ipairs(httpVerbs) do + verb_start, verb_end = line:find(httpVerb) + if verb_start then + verb = httpVerb + break + end + end + + if verb_start then + return { + line_number = current_line_number, + start_pos = verb_start, + end_pos = verb_end, + method = verb, + } + else + return nil + end +end + +local function find_http_verb_positions_in_buffer() + local buf = vim.api.nvim_get_current_buf() + local total_lines = vim.api.nvim_buf_line_count(buf) + local cursor = vim.api.nvim_win_get_cursor(0) + local current_line_number = cursor[1] + + local total = 0 + local current = 0 + + for i = 1, total_lines do + local line = vim.api.nvim_buf_get_lines(buf, i - 1, i, false)[1] + local result = find_http_verb(line) + if result ~= nil then + total = total + 1 + if i == current_line_number then + current = total + end + end + end + + return { + total = total, + current = current, + } +end + + local httpVerbs = { 'GET', 'POST', 'PUT', 'DELETE', 'PATCH' } local verb_start, verb_end, verb for _, v in ipairs(verbs) do