Skip to content

Commit

Permalink
fix: check real paths of buffers
Browse files Browse the repository at this point in the history
Buf names can contain the wrong type of file separators

See #141
  • Loading branch information
rcarriga committed Nov 10, 2022
1 parent 604dd92 commit e0868ea
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lua/neotest/adapters/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ function AdapterGroup:adapters_matching_open_bufs(existing_roots)
local buffers = async.api.nvim_list_bufs()

local paths = lib.func_util.map(function(i, buf)
return i, async.fn.fnamemodify(async.fn.bufname(buf), ":p")
local path = async.api.nvim_buf_get_name(buf)
local real = lib.files.path.real(path)
return i, real or false
end, buffers)

local matched_files = {}
for _, path in ipairs(paths) do
if not is_under_roots(path) then
if path and not is_under_roots(path) then
for _, adapter in ipairs(self:_path_adapters(path)) do
if adapter.is_test_file(path) and not matched_files[path] then
logger.info("Adapter", adapter.name, "matched buffer", path)
Expand Down
3 changes: 2 additions & 1 deletion lua/neotest/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ end
function NeotestClient:_update_open_buf_positions(adapter_id)
local adapter = self._adapters[adapter_id]
for _, bufnr in ipairs(async.api.nvim_list_bufs()) do
local file_path = async.api.nvim_buf_get_name(bufnr)
local name = async.api.nvim_buf_get_name(bufnr)
local file_path = lib.files.path.real(name) or name
if adapter.is_test_file(file_path) then
self:_update_positions(file_path, { adapter = adapter_id })
end
Expand Down
8 changes: 6 additions & 2 deletions lua/neotest/consumers/diagnostic.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local lib = require("neotest.lib")
local logger = require("neotest.logging")
local async = require("neotest.async")

Expand Down Expand Up @@ -198,8 +199,11 @@ local function init(client)
--- vimscript call to bufnr, we create the set of buffers that are loaded and check against that.
local valid_bufs = {}
for _, bufnr in ipairs(async.api.nvim_list_bufs()) do
local bufpath = async.fn.fnamemodify(async.api.nvim_buf_get_name(bufnr), ":p")
valid_bufs[bufpath] = true
local name = async.api.nvim_buf_get_name(bufnr)
local bufpath, _ = lib.files.path.real(name)
if bufpath then
valid_bufs[bufpath] = true
end
end

for pos_id, _ in pairs(results) do
Expand Down
3 changes: 1 addition & 2 deletions lua/neotest/consumers/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ function neotest.run.get_tree_from_args(args, store)
return client:get_position(nil, args)
end
if args[1] then
local position_id = lib.files.exists(args[1]) and async.fn.fnamemodify(args[1], ":p")
or args[1]
local position_id = lib.files.path.real(args[1]) or args[1]
return client:get_position(position_id, args)
end
local file_path = async.fn.expand("%:p")
Expand Down
9 changes: 9 additions & 0 deletions lua/neotest/lib/file/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ M.sep = (function()
return res
end)()

M.path = {
sep = M.sep,
exists = M.exists,
real = function(path)
local err, real = async.uv.fs_realpath(path)
return real, err
end,
}

---@type fun(path: string): string
M.detect_filetype = fu.memoize(filetype.detect)

Expand Down

0 comments on commit e0868ea

Please sign in to comment.