Skip to content

Commit

Permalink
refactor: simplify search function
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 15, 2024
1 parent 91dabb0 commit c00c081
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lua/neotest-golang/lib/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

local scandir = require("plenary.scandir")

local convert = require("neotest-golang.lib.convert")
local logger = require("neotest-golang.logging")

local M = {}

Expand All @@ -17,13 +17,12 @@ function M.file_upwards(filename, start_path)
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
return files[1]
logger.debug("Searching for " .. filename .. " in " .. start_dir)

local try_path = start_dir .. "/" .. filename
if vim.fn.filereadable(try_path) == 1 then
logger.debug("Found " .. filename .. " at " .. try_path)
return try_path
end

-- Go up one directory
Expand Down

0 comments on commit c00c081

Please sign in to comment.