diff --git a/lua/kulala/utils/fs.lua b/lua/kulala/utils/fs.lua index a64c551..11fcd2f 100644 --- a/lua/kulala/utils/fs.lua +++ b/lua/kulala/utils/fs.lua @@ -5,20 +5,7 @@ local M = {} --- @return string|nil --- @usage local p = fs.find_file_in_parent_dirs('Makefile') M.find_file_in_parent_dirs = function(filename) - local dir = vim.fn.expand('%:p:h') - -- make sure we don't go into an infinite loop - -- if the file is in the root directory of windows or unix - -- we should stop at the root directory - -- for linux, the root directory is '/' - -- for windows, the root directory is '[SOME_LETTER]:\' - while dir ~= '/' and dir:match('[A-Z]:\\') == nil do - local parent = dir .. '/' .. filename - if vim.fn.filereadable(parent) == 1 then - return parent - end - dir = vim.fn.fnamemodify(dir, ':h') - end - return nil + return vim.fs.find({filename}, {upward=true, limit=1})[1] end -- Writes string to file