From 42ed8e4493d4d1a6918031f273cb0d555f4b576f Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 23 Feb 2025 02:04:43 +0800 Subject: [PATCH] fix: asynchronously start rag service (#1355) --- lua/avante/rag_service.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lua/avante/rag_service.lua b/lua/avante/rag_service.lua index b1d210c..4eb2370 100644 --- a/lua/avante/rag_service.lua +++ b/lua/avante/rag_service.lua @@ -68,13 +68,20 @@ function M.launch_rag_service() openai_base_url, image ) - local result_ = vim.fn.system(cmd_) - local exit_code = vim.v.shell_error - if exit_code ~= 0 then - Utils.error(string.format("failed to start rag service: %s", result_)) - return false - end - Utils.debug(string.format("container %s started", container_name)) + vim.fn.jobstart(cmd_, { + detach = true, + on_stderr = function(_, data, _) + Utils.error(string.format("container %s failed to start: %s", container_name, data)) + end, + on_exit = function(_, exit_code) + if exit_code ~= 0 then + Utils.error(string.format("container %s failed to start, exit code: %d", container_name, exit_code)) + else + Utils.debug(string.format("container %s started", container_name)) + end + return true + end, + }) return true end