Skip to content

Commit

Permalink
chore: add buffer filtering util
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 16, 2024
1 parent 0ee537a commit 9e4a19f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,17 @@ debugging issues with Neotest.

You can get ahold of the log file's path using
`require("neotest.logging"):get_filename()`, which usually points to your
`~/.local/state/nvim/neotest.log`.
`~/.local/state/nvim/neotest.Log`.

The logfile tends to be ginormous and if you are only looking for neotest-golang
related entries, you can either search for the `[neotest-golang]` prefix, or
open the log in a Neovim buffer and then filter out only the adapter-related
entries:

```lua
:edit ~/.local/state/nvim/neotest.log
:lua require("neotest-golang.utils.buffer").filter("[neotest-golang]")
```

### Neotest is slowing down Neovim

Expand Down
29 changes: 29 additions & 0 deletions lua/neotest-golang/utils/buffer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local lib = require("neotest-golang.lib")

local M = {}

function M.filter(word)
-- Get the current buffer
local bufnr = vim.api.nvim_get_current_buf()

-- 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
local new_lines = {}

-- 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
table.insert(new_lines, line)
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
5 changes: 5 additions & 0 deletions lua/neotest-golang/utils/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local M = {}

M.buffer = require("neotest-golang.utils.buffer")

return M

0 comments on commit 9e4a19f

Please sign in to comment.