From cf4d935253cacd50e939e7ae717c5a858222964b Mon Sep 17 00:00:00 2001 From: Cory Hall <43035978+corymhall@users.noreply.github.com> Date: Fri, 18 Nov 2022 13:43:59 -0500 Subject: [PATCH] fix(adapters): check buffer is loaded (#160) `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. --- lua/neotest/adapters/init.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/neotest/adapters/init.lua b/lua/neotest/adapters/init.lua index f0a064ca..c41533d3 100644 --- a/lua/neotest/adapters/init.lua +++ b/lua/neotest/adapters/init.lua @@ -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)