From 11c0d13b9a1c74711a2607bc97496cfcd0b66ddb Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Mon, 17 Feb 2025 00:01:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D=20add=20fi?= =?UTF-8?q?le=20=E4=BD=9C=E4=B8=BA=E4=B8=8A=E4=B8=8B=E6=96=87=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E6=89=BE=E4=B8=8D=E5=88=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/avante/utils/root.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/avante/utils/root.lua b/lua/avante/utils/root.lua index e61cfee..61aa057 100644 --- a/lua/avante/utils/root.lua +++ b/lua/avante/utils/root.lua @@ -81,9 +81,13 @@ function M.detect(opts) opts.spec = opts.spec or type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec opts.buf = (opts.buf == nil or opts.buf == 0) and vim.api.nvim_get_current_buf() or opts.buf + print("Detection Specs:", vim.inspect(opts.spec)) + local ret = {} ---@type AvanteRoot[] for _, spec in ipairs(opts.spec) do local paths = M.resolve(spec)(opts.buf) + print("Paths for Spec:", spec, vim.inspect(paths)) + paths = paths or {} paths = type(paths) == "table" and paths or { paths } local roots = {} ---@type string[] @@ -97,9 +101,11 @@ function M.detect(opts) if opts.all == false then break end end end + print("Detected Roots:", vim.inspect(ret)) return ret end + ---@type table M.cache = {} @@ -113,15 +119,27 @@ M.cache = {} function M.get(opts) opts = opts or {} local buf = opts.buf or vim.api.nvim_get_current_buf() + print("Current Buffer:", buf) + local ret = M.cache[buf] + print("Cached Root:", ret) + if not ret then local roots = M.detect({ all = false, buf = buf }) + print("Detected Roots:", vim.inspect(roots)) + ret = roots[1] and roots[1].paths[1] or vim.uv.cwd() + print("Selected Root:", ret) + M.cache[buf] = ret end + if opts and opts.normalize then return ret end + -- Ensure a non-empty return value ret = ret ~= "" and ret or vim.uv.cwd() + print("Final Root:", ret) + return Utils.is_win() and ret:gsub("/", "\\") or ret end