feat: silence debug msg (#636)

This commit is contained in:
yetone 2024-09-26 11:18:40 +08:00 committed by GitHub
parent 0d90c047ef
commit 22243bc316
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 18 deletions

View File

@ -73,9 +73,9 @@ M.build = function(opts)
local output = stdout local output = stdout
if #output == 0 then if #output == 0 then
table.insert(output, "") table.insert(output, "")
Utils.debug(output) Utils.debug("build output:", output)
else else
Utils.debug(stderr) Utils.debug("build error:", stderr)
end end
end end
end) end)

View File

@ -84,8 +84,7 @@ M.stream = function(opts)
:filter(function(k) return k ~= "" end) :filter(function(k) return k ~= "" end)
:totable() :totable()
Utils.debug(user_prompts) Utils.debug("user prompts:", user_prompts)
-- print(user_prompts[1])
---@type AvantePromptOptions ---@type AvantePromptOptions
local code_opts = { local code_opts = {
@ -102,7 +101,7 @@ M.stream = function(opts)
---@type AvanteCurlOutput ---@type AvanteCurlOutput
local spec = Provider.parse_curl_args(Provider, code_opts) local spec = Provider.parse_curl_args(Provider, code_opts)
Utils.debug(spec) Utils.debug("curl spec:", spec)
---@param line string ---@param line string
local function parse_stream_data(line) local function parse_stream_data(line)
@ -182,7 +181,7 @@ M.stream = function(opts)
-- Error: cannot resume dead coroutine -- Error: cannot resume dead coroutine
if active_job then if active_job then
xpcall(function() active_job:shutdown() end, function(err) return err end) 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 active_job = nil
end end
end, end,

View File

@ -81,7 +81,7 @@ function Suggestion:suggest()
Utils.error("Error while suggesting: " .. vim.inspect(err), { once = true, title = "Avante" }) Utils.error("Error while suggesting: " .. vim.inspect(err), { once = true, title = "Avante" })
return return
end end
Utils.debug("full_response: " .. vim.inspect(full_response)) Utils.debug("full_response:", full_response)
vim.schedule(function() vim.schedule(function()
local cursor_row, cursor_col = Utils.get_cursor_pos() local cursor_row, cursor_col = Utils.get_cursor_pos()
if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end

View File

@ -123,7 +123,7 @@ M.safe_keymap_set = function(mode, lhs, rhs, opts)
ok, H = pcall(require, "lazy.core.handler") ok, H = pcall(require, "lazy.core.handler")
if not ok then 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) vim.keymap.set(mode, lhs, rhs, opts)
return return
end end
@ -324,19 +324,22 @@ function M.warn(msg, opts)
M.notify(msg, opts) M.notify(msg, opts)
end end
---@param msg string|table function M.debug(...)
---@param opts? LazyNotifyOpts
function M.debug(msg, opts)
if not require("avante.config").options.debug then return end if not require("avante.config").options.debug then return end
opts = opts or {}
if opts.title then opts.title = "avante.nvim: " .. opts.title end local args = { ... }
if type(msg) == "string" then if #args == 0 then return end
M.notify(msg, opts) 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 else
opts.lang = "lua" table.insert(formated_args, vim.inspect(arg))
M.notify(vim.inspect(msg), opts)
end end
end end
print(unpack(formated_args))
end
function M.tbl_indexof(tbl, value) function M.tbl_indexof(tbl, value)
for i, v in ipairs(tbl) do for i, v in ipairs(tbl) do