Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: find_upwards could go into infinite loop #129

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lua/neotest-golang/lib/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@ local M = {}
--- @param start_path string
--- @return string | nil
function M.file_upwards(filename, start_path)
local found_filepath = nil
while start_path ~= vim.fn.expand("$HOME") do
local files = scandir.scan_dir(start_path, {
-- Ensure start_path is a directory
local start_dir = vim.fn.isdirectory(start_path) == 1 and start_path
or vim.fn.fnamemodify(start_path, ":h")
local home_dir = vim.fn.expand("$HOME")

while start_dir ~= home_dir do
local files = scandir.scan_dir(start_dir, {
search_pattern = convert.to_lua_pattern(filename),
depth = 1,
add_dirs = false,
})
if #files > 0 then
found_filepath = files[1]
return found_filepath
return files[1]
end
end

if found_filepath == nil then
-- go up one directory and try again
start_path = vim.fn.fnamemodify(start_path, ":h")
return M.file_upwards(filename, start_path)
-- Go up one directory
start_dir = vim.fn.fnamemodify(start_dir, ":h")
end

return nil
end

-- Get all *_test.go files in a directory recursively.
Expand Down
Loading