From c00c0811a29a9ae6023b4350d3f6a617057fc0f4 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Mon, 15 Jul 2024 21:35:01 +0200 Subject: [PATCH] refactor: simplify search function --- lua/neotest-golang/lib/find.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lua/neotest-golang/lib/find.lua b/lua/neotest-golang/lib/find.lua index 3caa48e4..bd2339cd 100644 --- a/lua/neotest-golang/lib/find.lua +++ b/lua/neotest-golang/lib/find.lua @@ -2,7 +2,7 @@ local scandir = require("plenary.scandir") -local convert = require("neotest-golang.lib.convert") +local logger = require("neotest-golang.logging") local M = {} @@ -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