From 945fab4f4596d1b5591d7f1f206a9547c0675f44 Mon Sep 17 00:00:00 2001 From: TheLeoP Date: Mon, 29 Jul 2024 22:32:55 -0500 Subject: [PATCH] fix(fs): avoid infinite loop searching parent dir --- lua/kulala/utils/fs.lua | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/lua/kulala/utils/fs.lua b/lua/kulala/utils/fs.lua index 5bac329..1bab695 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