diff --git a/lua/avante/api.lua b/lua/avante/api.lua index a755980..2be7487 100644 --- a/lua/avante/api.lua +++ b/lua/avante/api.lua @@ -73,9 +73,9 @@ M.build = function(opts) local output = stdout if #output == 0 then table.insert(output, "") - Utils.debug(output) + Utils.debug("build output:", output) else - Utils.debug(stderr) + Utils.debug("build error:", stderr) end end end) diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index 2aff73c..f171b24 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -84,8 +84,7 @@ M.stream = function(opts) :filter(function(k) return k ~= "" end) :totable() - Utils.debug(user_prompts) - -- print(user_prompts[1]) + Utils.debug("user prompts:", user_prompts) ---@type AvantePromptOptions local code_opts = { @@ -102,7 +101,7 @@ M.stream = function(opts) ---@type AvanteCurlOutput local spec = Provider.parse_curl_args(Provider, code_opts) - Utils.debug(spec) + Utils.debug("curl spec:", spec) ---@param line string local function parse_stream_data(line) @@ -182,7 +181,7 @@ M.stream = function(opts) -- Error: cannot resume dead coroutine if active_job then xpcall(function() active_job:shutdown() end, function(err) return err end) - Utils.debug("LLM request cancelled", { title = "Avante" }) + Utils.debug("LLM request cancelled") active_job = nil end end, diff --git a/lua/avante/suggestion.lua b/lua/avante/suggestion.lua index 8f998f1..e3414e7 100644 --- a/lua/avante/suggestion.lua +++ b/lua/avante/suggestion.lua @@ -81,7 +81,7 @@ function Suggestion:suggest() Utils.error("Error while suggesting: " .. vim.inspect(err), { once = true, title = "Avante" }) return end - Utils.debug("full_response: " .. vim.inspect(full_response)) + Utils.debug("full_response:", full_response) vim.schedule(function() local cursor_row, cursor_col = Utils.get_cursor_pos() if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end diff --git a/lua/avante/utils/init.lua b/lua/avante/utils/init.lua index d8d8ed8..34f1050 100644 --- a/lua/avante/utils/init.lua +++ b/lua/avante/utils/init.lua @@ -123,7 +123,7 @@ M.safe_keymap_set = function(mode, lhs, rhs, opts) ok, H = pcall(require, "lazy.core.handler") if not ok then - M.debug("lazy.nvim is not available. Avante will use vim.keymap.set", { once = true }) + M.debug("lazy.nvim is not available. Avante will use vim.keymap.set") vim.keymap.set(mode, lhs, rhs, opts) return end @@ -324,18 +324,21 @@ function M.warn(msg, opts) M.notify(msg, opts) end ----@param msg string|table ----@param opts? LazyNotifyOpts -function M.debug(msg, opts) +function M.debug(...) if not require("avante.config").options.debug then return end - opts = opts or {} - if opts.title then opts.title = "avante.nvim: " .. opts.title end - if type(msg) == "string" then - M.notify(msg, opts) - else - opts.lang = "lua" - M.notify(vim.inspect(msg), opts) + + local args = { ... } + if #args == 0 then return end + local timestamp = os.date("%Y-%m-%d %H:%M:%S") + local formated_args = { "[" .. timestamp .. "] [AVANTE] [DEBUG]" } + for _, arg in ipairs(args) do + if type(arg) == "string" then + table.insert(formated_args, arg) + else + table.insert(formated_args, vim.inspect(arg)) + end end + print(unpack(formated_args)) end function M.tbl_indexof(tbl, value)