Skip to content

Commit

Permalink
fix(adapters): check buffer is loaded (#160)
Browse files Browse the repository at this point in the history
`vim.api.nvim_buf_get_name()` will throw an error if run on an unloaded
buffer. I'm using `noice.nvim` which I think creates some unloaded
buffers.

This PR adds a check to ensure the buffer is loaded before trying to get
the name.
  • Loading branch information
corymhall authored Nov 18, 2022
1 parent 38f9631 commit cf4d935
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lua/neotest/adapters/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ function AdapterGroup:adapters_matching_open_bufs(existing_roots)
local buffers = async.api.nvim_list_bufs()

local paths = lib.func_util.map(function(i, buf)
local path = async.api.nvim_buf_get_name(buf)
local real = lib.files.path.real(path)
local real
if async.api.nvim_buf_is_loaded(buf) then
local path = async.api.nvim_buf_get_name(buf)
real = lib.files.path.real(path)
end
return i, real or false
end, buffers)

Expand Down

0 comments on commit cf4d935

Please sign in to comment.