Skip to content

Commit

Permalink
fix: keep all lines until next log entry (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil authored Sep 7, 2024
1 parent 83ee03a commit 8e3698a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lua/neotest-golang/utils/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@ function M.filter(word)
-- Get all lines in the buffer
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)

-- Create a new table to store lines containing the word
-- Create a new table to store filtered lines
local new_lines = {}

-- Flag to track if we're currently in a matching block
local in_matching_block = false

-- Iterate through all lines
for _, line in ipairs(lines) do
-- If the line contains "neotest-golang", add it to new_lines
if line:match(lib.convert.to_lua_pattern(word)) then
-- Check if the line starts with a log level
local is_log_start = line:match("^%u+%s+|")

if is_log_start then
-- If it's a new log entry, reset the flag
in_matching_block = false
end

-- If the line contains the word or we're in a matching block, add it
if line:match(lib.convert.to_lua_pattern(word)) or in_matching_block then
table.insert(new_lines, line)
in_matching_block = true
end
end

-- Replace the buffer contents with the new lines
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, new_lines)

vim.notify("Removed lines not containing '" .. word .. "'")
end

return M

0 comments on commit 8e3698a

Please sign in to comment.