feat(health): support checkhealth for plugins and providers (#769)
This commit is contained in:
@@ -8,13 +8,17 @@ if vim.fn.has("nvim-0.10") == 0 then
|
||||
vim.cmd([[quit]])
|
||||
end
|
||||
|
||||
--- NOTE: We will override vim.paste if img-clip.nvim is available to work with avante.nvim internal logic paste
|
||||
if vim.g.avante ~= nil then return end
|
||||
|
||||
vim.g.avante = 1
|
||||
|
||||
--- NOTE: We will override vim.paste if img-clip.nvim is available to work with avante.nvim internal logic paste
|
||||
local Clipboard = require("avante.clipboard")
|
||||
local Config = require("avante.config")
|
||||
local api = vim.api
|
||||
|
||||
if Config.support_paste_image() then
|
||||
vim.paste = (function(overriden)
|
||||
vim.paste = (function(overridden)
|
||||
---@param lines string[]
|
||||
---@param phase -1|1|2|3
|
||||
return function(lines, phase)
|
||||
@@ -22,13 +26,13 @@ if Config.support_paste_image() then
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
|
||||
if filetype ~= "AvanteInput" then return overriden(lines, phase) end
|
||||
if filetype ~= "AvanteInput" then return overridden(lines, phase) end
|
||||
|
||||
---@type string
|
||||
local line = lines[1]
|
||||
|
||||
local ok = Clipboard.paste_image(line)
|
||||
if not ok then return overriden(lines, phase) end
|
||||
if not ok then return overridden(lines, phase) end
|
||||
|
||||
-- After pasting, insert a new line and set cursor to this line
|
||||
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, { "" })
|
||||
@@ -37,3 +41,64 @@ if Config.support_paste_image() then
|
||||
end
|
||||
end)(vim.paste)
|
||||
end
|
||||
|
||||
---@param n string
|
||||
---@param c vim.api.keyset.user_command.callback
|
||||
---@param o vim.api.keyset.user_command.opts
|
||||
local cmd = function(n, c, o)
|
||||
o = vim.tbl_extend("force", { nargs = 0 }, o or {})
|
||||
api.nvim_create_user_command("Avante" .. n, c, o)
|
||||
end
|
||||
|
||||
cmd("Ask", function(opts)
|
||||
---@type AskOptions
|
||||
local args = { question = nil, win = {} }
|
||||
local q_parts = {}
|
||||
local q_ask = nil
|
||||
for _, arg in ipairs(opts.fargs) do
|
||||
local value = arg:match("position=(%w+)")
|
||||
local ask = arg:match("ask=(%w+)")
|
||||
if ask ~= nil then
|
||||
q_ask = ask == "true"
|
||||
elseif value then
|
||||
args.win.position = value
|
||||
else
|
||||
table.insert(q_parts, arg)
|
||||
end
|
||||
end
|
||||
require("avante.api").ask(
|
||||
vim.tbl_deep_extend("force", args, { ask = q_ask, question = #q_parts > 0 and table.concat(q_parts, " ") or nil })
|
||||
)
|
||||
end, {
|
||||
desc = "avante: ask AI for code suggestions",
|
||||
nargs = "*",
|
||||
complete = function(_, _, _)
|
||||
local candidates = {} ---@type string[]
|
||||
vim.list_extend(
|
||||
candidates,
|
||||
---@param x string
|
||||
vim.tbl_map(function(x) return "position=" .. x end, { "left", "right", "top", "bottom" })
|
||||
)
|
||||
vim.list_extend(candidates, vim.tbl_map(function(x) return "ask=" .. x end, { "true", "false" }))
|
||||
return candidates
|
||||
end,
|
||||
})
|
||||
cmd("Chat", function() require("avante.api").ask({ ask = false }) end, { desc = "avante: chat with the codebase" })
|
||||
cmd("Toggle", function() require("avante").toggle() end, { desc = "avante: toggle AI panel" })
|
||||
cmd(
|
||||
"Edit",
|
||||
function(opts) require("avante.api").edit(vim.trim(opts.args)) end,
|
||||
{ desc = "avante: edit selected block", nargs = "*" }
|
||||
)
|
||||
cmd("Refresh", function() require("avante.api").refresh() end, { desc = "avante: refresh windows" })
|
||||
cmd("Focus", function() require("avante.api").focus() end, { desc = "avante: switch focus windows" })
|
||||
cmd("SwitchProvider", function(opts) require("avante.api").switch_provider(vim.trim(opts.args or "")) end, {
|
||||
nargs = 1,
|
||||
desc = "avante: switch provider",
|
||||
complete = function(_, line, _)
|
||||
local prefix = line:match("AvanteSwitchProvider%s*(.*)$") or ""
|
||||
---@param key string
|
||||
return vim.tbl_filter(function(key) return key:find(prefix, 1, true) == 1 end, Config.providers)
|
||||
end,
|
||||
})
|
||||
cmd("Clear", function() require("avante.path").clear() end, { desc = "avante: clear all chat history" })
|
||||
|
||||
Reference in New Issue
Block a user