refine: replace vim.fn.system with vim.system (#2863)
This commit is contained in:
@@ -1425,7 +1425,7 @@ Avante allows you to define custom tools that can be used by the AI during code
|
|||||||
},
|
},
|
||||||
func = function(params, on_log, on_complete) -- Custom function to execute
|
func = function(params, on_log, on_complete) -- Custom function to execute
|
||||||
local target = params.target or "./..."
|
local target = params.target or "./..."
|
||||||
return vim.fn.system(string.format("go test -v %s", target))
|
return vim.system({ "go", "test", "-v", target }, { text = true }):wait().stdout
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -950,7 +950,7 @@ Avante 允许您定义自定义工具,AI 可以在代码生成和分析期间
|
|||||||
},
|
},
|
||||||
func = function(params, on_log, on_complete) -- 要执行的自定义函数
|
func = function(params, on_log, on_complete) -- 要执行的自定义函数
|
||||||
local target = params.target or "./..."
|
local target = params.target or "./..."
|
||||||
return vim.fn.system(string.format("go test -v %s", target))
|
return vim.system({ "go", "test", "-v", target }, { text = true }):wait().stdout
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -84,40 +84,72 @@ function M.func(input, opts)
|
|||||||
if search_cmd == "" then return "", "No search command found" end
|
if search_cmd == "" then return "", "No search command found" end
|
||||||
|
|
||||||
---execute the search command
|
---execute the search command
|
||||||
local cmd = ""
|
local cmd = {}
|
||||||
if search_cmd:find("rg") then
|
if search_cmd:find("rg") then
|
||||||
cmd = string.format("%s --files-with-matches --hidden", search_cmd)
|
cmd = { search_cmd, "--files-with-matches", "--hidden" }
|
||||||
if input.case_sensitive then
|
if input.case_sensitive then
|
||||||
cmd = string.format("%s --case-sensitive", cmd)
|
table.insert(cmd, "--case-sensitive")
|
||||||
else
|
else
|
||||||
cmd = string.format("%s --ignore-case", cmd)
|
table.insert(cmd, "--ignore-case")
|
||||||
end
|
end
|
||||||
if input.include_pattern then cmd = string.format("%s --glob '%s'", cmd, input.include_pattern) end
|
if input.include_pattern then
|
||||||
if input.exclude_pattern then cmd = string.format("%s --glob '!%s'", cmd, input.exclude_pattern) end
|
table.insert(cmd, "--glob")
|
||||||
cmd = string.format("%s '%s' %s", cmd, input.query, abs_path)
|
table.insert(cmd, input.include_pattern)
|
||||||
|
end
|
||||||
|
if input.exclude_pattern then
|
||||||
|
table.insert(cmd, "--glob")
|
||||||
|
table.insert(cmd, "!" .. input.exclude_pattern)
|
||||||
|
end
|
||||||
|
table.insert(cmd, input.query)
|
||||||
|
table.insert(cmd, abs_path)
|
||||||
elseif search_cmd:find("ag") then
|
elseif search_cmd:find("ag") then
|
||||||
cmd = string.format("%s --nocolor --nogroup --hidden", search_cmd)
|
cmd = { search_cmd, "--nocolor", "--nogroup", "--hidden" }
|
||||||
if input.case_sensitive then cmd = string.format("%s --case-sensitive", cmd) end
|
if input.case_sensitive then table.insert(cmd, "--case-sensitive") end
|
||||||
if input.include_pattern then cmd = string.format("%s --ignore '!%s'", cmd, input.include_pattern) end
|
if input.include_pattern then
|
||||||
if input.exclude_pattern then cmd = string.format("%s --ignore '%s'", cmd, input.exclude_pattern) end
|
table.insert(cmd, "--ignore")
|
||||||
cmd = string.format("%s '%s' %s", cmd, input.query, abs_path)
|
table.insert(cmd, "!" .. input.include_pattern)
|
||||||
|
end
|
||||||
|
if input.exclude_pattern then
|
||||||
|
table.insert(cmd, "--ignore")
|
||||||
|
table.insert(cmd, input.exclude_pattern)
|
||||||
|
end
|
||||||
|
table.insert(cmd, input.query)
|
||||||
|
table.insert(cmd, abs_path)
|
||||||
elseif search_cmd:find("ack") then
|
elseif search_cmd:find("ack") then
|
||||||
cmd = string.format("%s --nocolor --nogroup --hidden", search_cmd)
|
cmd = { search_cmd, "--nocolor", "--nogroup", "--hidden" }
|
||||||
if input.case_sensitive then cmd = string.format("%s --smart-case", cmd) end
|
if input.case_sensitive then table.insert(cmd, "--smart-case") end
|
||||||
if input.exclude_pattern then cmd = string.format("%s --ignore-dir '%s'", cmd, input.exclude_pattern) end
|
if input.exclude_pattern then
|
||||||
cmd = string.format("%s '%s' %s", cmd, input.query, abs_path)
|
table.insert(cmd, "--ignore-dir")
|
||||||
|
table.insert(cmd, input.exclude_pattern)
|
||||||
|
end
|
||||||
|
table.insert(cmd, input.query)
|
||||||
|
table.insert(cmd, abs_path)
|
||||||
elseif search_cmd:find("grep") then
|
elseif search_cmd:find("grep") then
|
||||||
cmd = string.format("cd %s && git ls-files -co --exclude-standard | xargs %s -rH", abs_path, search_cmd, abs_path)
|
local files =
|
||||||
if not input.case_sensitive then cmd = string.format("%s -i", cmd) end
|
vim.system({ "git", "-C", abs_path, "ls-files", "-co", "--exclude-standard" }, { text = true }):wait().stdout
|
||||||
if input.include_pattern then cmd = string.format("%s --include '%s'", cmd, input.include_pattern) end
|
cmd = { "grep", "-rH" }
|
||||||
if input.exclude_pattern then cmd = string.format("%s --exclude '%s'", cmd, input.exclude_pattern) end
|
if not input.case_sensitive then table.insert(cmd, "-i") end
|
||||||
cmd = string.format("%s '%s'", cmd, input.query)
|
if input.include_pattern then
|
||||||
|
table.insert(cmd, "--include")
|
||||||
|
table.insert(cmd, input.include_pattern)
|
||||||
|
end
|
||||||
|
if input.exclude_pattern then
|
||||||
|
table.insert(cmd, "--exclude")
|
||||||
|
table.insert(cmd, input.exclude_pattern)
|
||||||
|
end
|
||||||
|
table.insert(cmd, input.query)
|
||||||
|
if files ~= "" then
|
||||||
|
for _, path in ipairs(vim.split(files, "\n")) do
|
||||||
|
if not path:match("^%s*$") then table.insert(cmd, vim.fs.joinpath(abs_path, path)) end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
table.insert(cmd, abs_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Utils.debug("cmd", cmd)
|
Utils.debug("cmd", table.concat(cmd, " "))
|
||||||
if on_log then on_log("Running command: " .. cmd) end
|
if on_log then on_log("Running command: " .. table.concat(cmd, " ")) end
|
||||||
local result = vim.fn.system(cmd)
|
local result = vim.system(cmd, { text = true }):wait().stdout or ""
|
||||||
|
|
||||||
local filepaths = vim.split(result, "\n")
|
local filepaths = vim.split(result, "\n")
|
||||||
|
|
||||||
return vim.json.encode(filepaths), nil
|
return vim.json.encode(filepaths), nil
|
||||||
|
|||||||
@@ -129,21 +129,17 @@ end
|
|||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_ignored(abs_path)
|
function M.is_ignored(abs_path)
|
||||||
local project_root = Utils.get_project_root()
|
local project_root = Utils.get_project_root()
|
||||||
local cmd =
|
local exit_code = vim
|
||||||
string.format("git -C %s check-ignore %s", vim.fn.shellescape(project_root), vim.fn.shellescape(abs_path))
|
.system({ "git", "-C", vim.fn.shellescape(project_root), "check-ignore", vim.fn.shellescape(abs_path) }, { text = true })
|
||||||
|
:wait().code
|
||||||
|
|
||||||
local result = vim.fn.system(cmd)
|
-- If command failed or git is not available or not a git repository, fall back to old method
|
||||||
local exit_code = vim.v.shell_error
|
|
||||||
|
|
||||||
-- If command failed or git is not available, fall back to old method
|
|
||||||
if exit_code ~= 0 and exit_code ~= 1 then return old_is_ignored(abs_path) end
|
if exit_code ~= 0 and exit_code ~= 1 then return old_is_ignored(abs_path) end
|
||||||
|
|
||||||
-- Check if result indicates this is not a git repository
|
|
||||||
if result:sub(1, 26) == "fatal: not a git repository" then return old_is_ignored(abs_path) end
|
|
||||||
|
|
||||||
-- git check-ignore returns:
|
-- git check-ignore returns:
|
||||||
-- - exit code 0 and outputs the path if the file is ignored
|
-- - exit code 0 and outputs the path to stdout if the file is ignored
|
||||||
-- - exit code 1 and no output if the file is not ignored
|
-- - exit code 1 and no output to stdout if the file is not ignored
|
||||||
|
-- - exit code 128 and outputs the error info to stderr not stdout
|
||||||
return exit_code == 0
|
return exit_code == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -389,20 +389,20 @@ function M.git_diff(input, opts)
|
|||||||
if not project_root then return nil, "Not in a git repository" end
|
if not project_root then return nil, "Not in a git repository" end
|
||||||
|
|
||||||
-- Check if we're in a git repository
|
-- Check if we're in a git repository
|
||||||
local git_dir = vim.fn.system("git rev-parse --git-dir"):gsub("\n", "")
|
local git_dir = vim.system({ "git", "rev-parse", "--git-dir" }, { text = true }):wait().stdout:gsub("\n", "")
|
||||||
if git_dir == "" then return nil, "Not a git repository" end
|
if git_dir == "" then return nil, "Not a git repository" end
|
||||||
|
|
||||||
-- Get the diff
|
-- Get the diff
|
||||||
local scope = input.scope or ""
|
local scope = input.scope or ""
|
||||||
local cmd = string.format("git diff --cached %s", scope)
|
local cmd = { "git", "diff", "--cached", scope }
|
||||||
if on_log then on_log("Running command: " .. cmd) end
|
if on_log then on_log("Running command: " .. table.concat(cmd, " ")) end
|
||||||
local diff = vim.fn.system(cmd)
|
local diff = vim.system(cmd, { text = true }):wait().stdout
|
||||||
|
|
||||||
if diff == "" then
|
if diff == "" then
|
||||||
-- If there's no staged changes, get unstaged changes
|
-- If there's no staged changes, get unstaged changes
|
||||||
cmd = string.format("git diff %s", scope)
|
cmd = { "git", "diff", scope }
|
||||||
if on_log then on_log("No staged changes. Running command: " .. cmd) end
|
if on_log then on_log("No staged changes. Running command: " .. table.concat(cmd, " ")) end
|
||||||
diff = vim.fn.system(cmd)
|
diff = vim.system(cmd, { text = true }):wait().stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
if diff == "" then return nil, "No changes detected" end
|
if diff == "" then return nil, "No changes detected" end
|
||||||
@@ -421,20 +421,23 @@ function M.git_commit(input, opts)
|
|||||||
if not project_root then return false, "Not in a git repository" end
|
if not project_root then return false, "Not in a git repository" end
|
||||||
|
|
||||||
-- Check if we're in a git repository
|
-- Check if we're in a git repository
|
||||||
local git_dir = vim.fn.system("git rev-parse --git-dir"):gsub("\n", "")
|
local git_dir = vim.system({ "git", "rev-parse", "--git-dir" }, { text = true }):wait().stdout:gsub("\n", "")
|
||||||
if git_dir == "" then return false, "Not a git repository" end
|
if git_dir == "" then return false, "Not a git repository" end
|
||||||
|
|
||||||
-- First check if there are any changes to commit
|
-- First check if there are any changes to commit
|
||||||
local status = vim.fn.system("git status --porcelain")
|
local status = vim.system({ "git", "status", "--porcelain" }, { text = true }):wait().stdout
|
||||||
if status == "" then return false, "No changes to commit" end
|
if status == "" then return false, "No changes to commit" end
|
||||||
|
|
||||||
-- Get git user name and email
|
-- Get git user name and email
|
||||||
local git_user = vim.fn.system("git config user.name"):gsub("\n", "")
|
local git_user = vim.system({ "git", "config", "user.name" }, { text = true }):wait().stdout:gsub("\n", "")
|
||||||
local git_email = vim.fn.system("git config user.email"):gsub("\n", "")
|
local git_email = vim.system({ "git", "config", "user.email" }, { text = true }):wait().stdout:gsub("\n", "")
|
||||||
|
|
||||||
-- Check if GPG signing is available and configured
|
-- Check if GPG signing is available and configured
|
||||||
local has_gpg = false
|
local has_gpg = false
|
||||||
local signing_key = vim.fn.system("git config --get user.signingkey"):gsub("\n", "")
|
local signing_key = vim
|
||||||
|
.system({ "git", "config", "--get", "user.signingkey" }, { text = true })
|
||||||
|
:wait().stdout
|
||||||
|
:gsub("\n", "")
|
||||||
|
|
||||||
if signing_key ~= "" then
|
if signing_key ~= "" then
|
||||||
-- Try to find gpg executable based on OS
|
-- Try to find gpg executable based on OS
|
||||||
@@ -449,8 +452,7 @@ function M.git_commit(input, opts)
|
|||||||
|
|
||||||
if gpg_cmd ~= "" then
|
if gpg_cmd ~= "" then
|
||||||
-- Verify GPG is working
|
-- Verify GPG is working
|
||||||
local _ = vim.fn.system(string.format('"%s" --version', gpg_cmd))
|
has_gpg = vim.system({ gpg_cmd, "--version" }, { text = true }):wait().code == 0
|
||||||
has_gpg = vim.v.shell_error == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -486,11 +488,11 @@ function M.git_commit(input, opts)
|
|||||||
end
|
end
|
||||||
-- Stage changes if scope is provided
|
-- Stage changes if scope is provided
|
||||||
if input.scope then
|
if input.scope then
|
||||||
local stage_cmd = string.format("git add %s", input.scope)
|
local stage_cmd = { "git", "add", input.scope }
|
||||||
if on_log then on_log("Staging files: " .. stage_cmd) end
|
if on_log then on_log("Staging files: " .. table.concat(stage_cmd, " ")) end
|
||||||
local stage_result = vim.fn.system(stage_cmd)
|
local stage_result = vim.system(stage_cmd, { text = true }):wait()
|
||||||
if vim.v.shell_error ~= 0 then
|
if stage_result.code ~= 0 then
|
||||||
on_complete(false, "Failed to stage files: " .. stage_result)
|
on_complete(false, "Failed to stage files: " .. stage_result.stderr)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -501,16 +503,16 @@ function M.git_commit(input, opts)
|
|||||||
if has_gpg then table.insert(cmd_parts, "-S") end
|
if has_gpg then table.insert(cmd_parts, "-S") end
|
||||||
for _, line in ipairs(commit_msg_lines) do
|
for _, line in ipairs(commit_msg_lines) do
|
||||||
table.insert(cmd_parts, "-m")
|
table.insert(cmd_parts, "-m")
|
||||||
table.insert(cmd_parts, '"' .. line .. '"')
|
table.insert(cmd_parts, line)
|
||||||
end
|
end
|
||||||
local cmd = table.concat(cmd_parts, " ")
|
local cmd = table.concat(cmd_parts, " ")
|
||||||
|
|
||||||
-- Execute git commit
|
-- Execute git commit
|
||||||
if on_log then on_log("Running command: " .. cmd) end
|
if on_log then on_log("Running command: " .. cmd) end
|
||||||
local result = vim.fn.system(cmd)
|
local result = vim.system(cmd_parts, { text = true }):wait()
|
||||||
|
|
||||||
if vim.v.shell_error ~= 0 then
|
if result.code ~= 0 then
|
||||||
on_complete(false, "Failed to commit: " .. result)
|
on_complete(false, "Failed to commit: " .. result.stderr)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -42,10 +42,11 @@ local lockfile_path = vim.fn.stdpath("data") .. "/avante/copilot-timer.lock"
|
|||||||
|
|
||||||
-- Lockfile management
|
-- Lockfile management
|
||||||
local function is_process_running(pid)
|
local function is_process_running(pid)
|
||||||
if vim.fn.has("win32") == 1 then
|
local result = vim.uv.kill(pid, 0)
|
||||||
return vim.fn.system('tasklist /FI "PID eq ' .. pid .. '" 2>NUL | find /I "' .. pid .. '"') ~= ""
|
if result ~= nil and result == 0 then
|
||||||
|
return true
|
||||||
else
|
else
|
||||||
return vim.fn.system("ps -p " .. pid .. " > /dev/null 2>&1; echo $?") == "0\n"
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,10 @@ function M.get_data_path()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.get_current_image()
|
function M.get_current_image()
|
||||||
local cmd = string.format("docker inspect %s | grep Image | grep %s", container_name, container_name)
|
local cmd = { "docker", "inspect", "--format", "{{.Config.Image}}", container_name }
|
||||||
local result = vim.fn.system(cmd)
|
local result = vim.system(cmd, { text = true }):wait()
|
||||||
if result == "" then return nil end
|
if result.code ~= 0 or result.stdout == "" then return nil end
|
||||||
local exit_code = vim.v.shell_error
|
return result.stdout
|
||||||
if exit_code ~= 0 then return nil end
|
|
||||||
local image = result:match('"Image":%s*"(.*)"')
|
|
||||||
if image == nil then return nil end
|
|
||||||
return image
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_rag_service_runner() return (Config.rag_service and Config.rag_service.runner) or "docker" end
|
function M.get_rag_service_runner() return (Config.rag_service and Config.rag_service.runner) or "docker" end
|
||||||
@@ -80,9 +76,12 @@ function M.launch_rag_service(cb)
|
|||||||
if M.get_rag_service_runner() == "docker" then
|
if M.get_rag_service_runner() == "docker" then
|
||||||
local image = M.get_rag_service_image()
|
local image = M.get_rag_service_image()
|
||||||
local data_path = M.get_data_path()
|
local data_path = M.get_data_path()
|
||||||
local cmd = string.format("docker ps | grep '%s'", container_name)
|
local cmd = { "docker", "inspect", "--format", "{{.State.Status}}", container_name }
|
||||||
local result = vim.fn.system(cmd)
|
local result = vim.system(cmd, { text = true }):wait()
|
||||||
if result ~= "" then
|
if result.code ~= 0 then Utils.debug(string.format("cmd: %s execution error", table.concat(cmd, " "))) end
|
||||||
|
if result.stdout == "" then
|
||||||
|
Utils.debug(string.format("container %s not found, starting...", container_name))
|
||||||
|
elseif result.stdout == "running" then
|
||||||
Utils.debug(string.format("container %s already running", container_name))
|
Utils.debug(string.format("container %s already running", container_name))
|
||||||
local current_image = M.get_current_image()
|
local current_image = M.get_current_image()
|
||||||
if current_image == image then
|
if current_image == image then
|
||||||
@@ -98,11 +97,8 @@ function M.launch_rag_service(cb)
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
M.stop_rag_service()
|
M.stop_rag_service()
|
||||||
else
|
|
||||||
Utils.debug(string.format("container %s not found, starting...", container_name))
|
|
||||||
end
|
end
|
||||||
result = vim.fn.system(string.format("docker ps -a | grep '%s'", container_name))
|
if result.stdout ~= "running" then
|
||||||
if result ~= "" then
|
|
||||||
Utils.info(string.format("container %s already started but not running, stopping...", container_name))
|
Utils.info(string.format("container %s already started but not running, stopping...", container_name))
|
||||||
M.stop_rag_service()
|
M.stop_rag_service()
|
||||||
end
|
end
|
||||||
@@ -139,8 +135,8 @@ function M.launch_rag_service(cb)
|
|||||||
})
|
})
|
||||||
elseif M.get_rag_service_runner() == "nix" then
|
elseif M.get_rag_service_runner() == "nix" then
|
||||||
-- Check if service is already running
|
-- Check if service is already running
|
||||||
local check_cmd = string.format("pgrep -f '%s'", service_path)
|
local check_cmd = { "pgrep", "-f", service_path }
|
||||||
local check_result = vim.fn.system(check_cmd)
|
local check_result = vim.system(check_cmd, { text = true }):wait().stdout
|
||||||
if check_result ~= "" then
|
if check_result ~= "" then
|
||||||
Utils.debug(string.format("RAG service already running at %s", service_path))
|
Utils.debug(string.format("RAG service already running at %s", service_path))
|
||||||
cb()
|
cb()
|
||||||
@@ -187,28 +183,30 @@ end
|
|||||||
|
|
||||||
function M.stop_rag_service()
|
function M.stop_rag_service()
|
||||||
if M.get_rag_service_runner() == "docker" then
|
if M.get_rag_service_runner() == "docker" then
|
||||||
local cmd = string.format("docker ps -a | grep '%s'", container_name)
|
local cmd = { "docker", "inspect", "--format", "{{.State.Status}}", container_name }
|
||||||
local result = vim.fn.system(cmd)
|
local result = vim.system(cmd, { text = true }):wait().stdout
|
||||||
if result ~= "" then vim.fn.system(string.format("docker rm -fv %s", container_name)) end
|
if result ~= "" then vim.system({ "docker", "rm", "-fv", container_name }):wait() end
|
||||||
else
|
else
|
||||||
local cmd = string.format("pgrep -f '%s' | xargs -r kill -9", service_path)
|
local pid = vim.system({ "pgrep", "-f", service_path }, { text = true }):wait().stdout
|
||||||
vim.fn.system(cmd)
|
if pid ~= "" then
|
||||||
Utils.debug(string.format("Attempted to kill processes related to %s", service_path))
|
vim.system({ "kill", "-9", pid }):wait()
|
||||||
|
Utils.debug(string.format("Attempted to kill processes related to %s", service_path))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_rag_service_status()
|
function M.get_rag_service_status()
|
||||||
if M.get_rag_service_runner() == "docker" then
|
if M.get_rag_service_runner() == "docker" then
|
||||||
local cmd = string.format("docker ps -a | grep '%s'", container_name)
|
local cmd = { "docker", "inspect", "--format", "{{.State.Status}}", container_name }
|
||||||
local result = vim.fn.system(cmd)
|
local result = vim.system(cmd, { text = true }):wait().stdout
|
||||||
if result == "" then
|
if result ~= "running" then
|
||||||
return "stopped"
|
return "stopped"
|
||||||
else
|
else
|
||||||
return "running"
|
return "running"
|
||||||
end
|
end
|
||||||
elseif M.get_rag_service_runner() == "nix" then
|
elseif M.get_rag_service_runner() == "nix" then
|
||||||
local cmd = string.format("pgrep -f '%s'", service_path)
|
local cmd = { "pgrep", "-f", service_path }
|
||||||
local result = vim.fn.system(cmd)
|
local result = vim.system(cmd, { text = true }):wait().stdout
|
||||||
if result == "" then
|
if result == "" then
|
||||||
return "stopped"
|
return "stopped"
|
||||||
else
|
else
|
||||||
@@ -250,13 +248,12 @@ function M.to_local_uri(uri)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.is_ready()
|
function M.is_ready()
|
||||||
vim.fn.system(
|
return vim
|
||||||
string.format(
|
.system(
|
||||||
"curl -s -o /dev/null -w '%%{http_code}' %s",
|
{ "curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", M.get_rag_service_url() .. "/api/health" },
|
||||||
string.format("%s%s", M.get_rag_service_url(), "/api/health")
|
{ text = true }
|
||||||
)
|
)
|
||||||
)
|
:wait().code == 0
|
||||||
return vim.v.shell_error == 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class AvanteRagServiceAddResourceResponse
|
---@class AvanteRagServiceAddResourceResponse
|
||||||
|
|||||||
@@ -85,17 +85,22 @@ end
|
|||||||
---@param shell_cmd string?
|
---@param shell_cmd string?
|
||||||
local function get_cmd_for_shell(input_cmd, shell_cmd)
|
local function get_cmd_for_shell(input_cmd, shell_cmd)
|
||||||
local shell = vim.o.shell:lower()
|
local shell = vim.o.shell:lower()
|
||||||
local cmd ---@type string
|
local cmd = {}
|
||||||
|
|
||||||
-- powershell then we can just run the cmd
|
-- powershell then we can just run the cmd
|
||||||
if shell:match("powershell") or shell:match("pwsh") then
|
if shell:match("powershell") then
|
||||||
cmd = input_cmd
|
cmd = { "powershell.exe", "-NoProfile", "-Command", input_cmd:gsub('"', "'") }
|
||||||
|
elseif shell:match("pwsh") then
|
||||||
|
cmd = { "pwsh.exe", "-NoProfile", "-Command", input_cmd:gsub('"', "'") }
|
||||||
elseif fn.has("win32") > 0 then
|
elseif fn.has("win32") > 0 then
|
||||||
cmd = 'powershell.exe -NoProfile -Command "' .. input_cmd:gsub('"', "'") .. '"'
|
cmd = { "powershell.exe", "-NoProfile", "-Command", input_cmd:gsub('"', "'") }
|
||||||
else
|
else
|
||||||
-- linux and macos we will just do sh -c
|
-- linux and macos we will just do sh -c
|
||||||
shell_cmd = shell_cmd or "sh -c"
|
shell_cmd = shell_cmd or "sh -c"
|
||||||
cmd = shell_cmd .. " " .. fn.shellescape(input_cmd)
|
for _, cmd_part in ipairs(vim.split(shell_cmd, " ")) do
|
||||||
|
table.insert(cmd, cmd_part)
|
||||||
|
end
|
||||||
|
table.insert(cmd, input_cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
@@ -108,10 +113,9 @@ end
|
|||||||
function M.shell_run(input_cmd, shell_cmd)
|
function M.shell_run(input_cmd, shell_cmd)
|
||||||
local cmd = get_cmd_for_shell(input_cmd, shell_cmd)
|
local cmd = get_cmd_for_shell(input_cmd, shell_cmd)
|
||||||
|
|
||||||
local output = fn.system(cmd)
|
local result = vim.system(cmd, { text = true }):wait()
|
||||||
local code = vim.v.shell_error
|
|
||||||
|
|
||||||
return { stdout = output, code = code }
|
return { stdout = result.stdout, code = result.code }
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param input_cmd string
|
---@param input_cmd string
|
||||||
|
|||||||
Reference in New Issue
Block a user