From f04bb93e982060ed27e5cf6e4a8d97edeb0910b6 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 9 Jan 2025 23:17:37 +0100 Subject: extract the upwards find code into the util module --- util.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'util.lua') diff --git a/util.lua b/util.lua index 3bdf227..114aad4 100644 --- a/util.lua +++ b/util.lua @@ -7,6 +7,9 @@ -- @copyright 2024 git-bruh local util = {} +local source_str = debug.getinfo(1, 'S').source:sub(2) +local source_path = source_str:match('(.*/)') + local lspc function util.init(lspc_) @@ -161,4 +164,18 @@ function util.file_line_iterator_to_n(path) end end +--- Find file based on globs in the parent file system tree +-- @param globs a new line separated string of file globs +-- @param start the starting path +function util.find_upwards(globs, start) + local status, out = vis:pipe(globs, source_path .. '/tools/find-upwards "' .. start .. '"') + + if status ~= 0 then + return nil + end + + -- Skip trailing newline + return out:sub(1, #out - 1) +end + return util -- cgit v1.2.3