Skip to content

Commit

Permalink
Update lua/hurl/codelens.lua
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
jellydn and coderabbitai[bot] authored Oct 29, 2024
1 parent 57986e4 commit 5a9e3c1
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lua/hurl/codelens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ function M.add_virtual_text_for_hurl_entries()

local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)

-- Create a dedicated namespace for Hurl entry markers
local ns_id = vim.api.nvim_create_namespace('hurl_entries')

-- Define all supported HTTP methods
local http_methods = {
'GET', 'POST', 'PUT', 'DELETE',
'PATCH', 'HEAD', 'OPTIONS'
}

-- Clear existing virtual text
vim.api.nvim_buf_clear_namespace(bufnr, -1, 0, -1)
vim.api.nvim_buf_clear_namespace(bufnr, ns_id, 0, -1)

local entry_number = 1
for i, line in ipairs(lines) do
-- Simple pattern to match common HTTP verbs
if
line:match('^%s*GET')
or line:match('^%s*POST')
or line:match('^%s*PUT')
or line:match('^%s*DELETE')
then
vim.api.nvim_buf_set_virtual_text(bufnr, -1, i - 1, {
-- Match any HTTP method, ignoring preceding whitespace and comments
local method = line:match('^%s*#?%s*([A-Z]+)')
if method and vim.tbl_contains(http_methods, method) then
vim.api.nvim_buf_set_virtual_text(bufnr, ns_id, i - 1, {
{ 'Entry #' .. entry_number, 'Comment' },
}, {})
entry_number = entry_number + 1
Expand Down

0 comments on commit 5a9e3c1

Please sign in to comment.