diff --git a/lua/vectorcode/cacher/default.lua b/lua/vectorcode/cacher/default.lua index b3773fa5..ff7340ac 100644 --- a/lua/vectorcode/cacher/default.lua +++ b/lua/vectorcode/cacher/default.lua @@ -1,5 +1,7 @@ ---@type VectorCode.CacheBackend local M = {} + +local utils = require("vectorcode.utils") local vc_config = require("vectorcode.config") local notify_opts = vc_config.notify_opts local jobrunner = require("vectorcode.jobrunner.cmd") @@ -54,7 +56,7 @@ local function async_runner(query_message, buf_nr) local project_root = cache.options.project_root if project_root ~= nil then assert( - vim.uv.fs_stat(vim.fs.normalize(project_root)).type == "directory", + utils.is_directory(project_root), ("%s is not a valid directory!"):format(project_root) ) vim.list_extend(args, { "--project_root", project_root }) diff --git a/lua/vectorcode/init.lua b/lua/vectorcode/init.lua index 75e12ca8..c9c4c474 100644 --- a/lua/vectorcode/init.lua +++ b/lua/vectorcode/init.lua @@ -149,10 +149,7 @@ M.vectorise = vc_config.check_cli_wrap( M.update = vc_config.check_cli_wrap(function(project_root) logger.info("vectorcode.update: ", project_root) local args = { "update" } - if - type(project_root) == "string" - and vim.uv.fs_stat(vim.fs.normalize(project_root)).type == "directory" - then + if project_root ~= nil and utils.is_directory(project_root) then vim.list_extend(args, { "--project_root", project_root }) end logger.debug("vectorcode.update cmd args: ", args) diff --git a/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua b/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua index b318aa1d..dcd9e80a 100644 --- a/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua @@ -33,8 +33,7 @@ return function(opts) or vim.fs.root(0, { ".vectorcode", ".git" }) if action.project_root ~= nil then action.project_root = vim.fs.normalize(action.project_root) - local stat = vim.uv.fs_stat(action.project_root) - if stat and stat.type == "directory" then + if utils.is_directory(action.project_root) then vim.list_extend(args, { "--project_root", action.project_root }) end end diff --git a/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua b/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua index a002f583..8b91e738 100644 --- a/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua @@ -2,6 +2,7 @@ local cc_common = require("vectorcode.integrations.codecompanion.common") local vc_config = require("vectorcode.config") +local utils = require("vectorcode.utils") local default_opts = { use_lsp = vc_config.get_user_config().async_backend == "lsp", @@ -59,8 +60,7 @@ The value should be one of the following: local args = { "files", "rm", "--pipe" } if action.project_root then local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root)) - local stat = vim.uv.fs_stat(project_root) - if stat and stat.type == "directory" then + if utils.is_directory(project_root) then vim.list_extend(args, { "--project_root", project_root }) else return { status = "error", data = "Invalid path " .. project_root } @@ -76,12 +76,7 @@ The value should be one of the following: :filter( ---@param item string function(item) - local stat = vim.uv.fs_stat(item) - if stat and stat.type == "file" then - return true - else - return false - end + return utils.is_file(item) end ) :totable() diff --git a/lua/vectorcode/integrations/codecompanion/query_tool.lua b/lua/vectorcode/integrations/codecompanion/query_tool.lua index 1f361642..4a267cb1 100644 --- a/lua/vectorcode/integrations/codecompanion/query_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/query_tool.lua @@ -417,10 +417,7 @@ return check_cli_wrap(function(opts) end if action.project_root ~= nil then action.project_root = vim.fs.normalize(action.project_root) - if - vim.uv.fs_stat(action.project_root) ~= nil - and vim.uv.fs_stat(action.project_root).type == "directory" - then + if utils.is_directory(action.project_root) then action.project_root = vim.fs.abspath(vim.fs.normalize(action.project_root)) vim.list_extend(args, { "--project_root", action.project_root }) else @@ -446,8 +443,7 @@ return check_cli_wrap(function(opts) elseif ref.bufnr then local fname = vim.api.nvim_buf_get_name(ref.bufnr) if fname ~= nil then - local stat = vim.uv.fs_stat(fname) - if stat and stat.type == "file" then + if utils.is_file(fname) then table.insert(existing_files, fname) end end diff --git a/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua b/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua index bbe1ffb9..addba165 100644 --- a/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua @@ -78,8 +78,7 @@ The value should be one of the following: local args = { "vectorise", "--pipe" } if action.project_root then local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root)) - local stat = vim.uv.fs_stat(project_root) - if stat and stat.type == "directory" then + if utils.is_directory(project_root) then vim.list_extend(args, { "--project_root", project_root }) else return { status = "error", data = "Invalid path " .. project_root } @@ -87,11 +86,7 @@ The value should be one of the following: end if vim.iter(action.paths):any(function(p) - local stat = vim.uv.fs_stat(vim.fs.normalize(p)) - if stat and stat.type == "directory" then - return true - end - return false + return utils.is_directory(p) end) then return {