chore: run stylua [generated] (#460)
* chore: add stylua Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: running stylua Signed-off-by: Aaron Pham <contact@aarnphm.xyz> --------- Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
local api = vim.api
|
||||
|
||||
local Utils = require("avante.utils")
|
||||
local Sidebar = require("avante.sidebar")
|
||||
local Selection = require("avante.selection")
|
||||
local Suggestion = require("avante.suggestion")
|
||||
local Config = require("avante.config")
|
||||
local Diff = require("avante.diff")
|
||||
local Utils = require "avante.utils"
|
||||
local Sidebar = require "avante.sidebar"
|
||||
local Selection = require "avante.selection"
|
||||
local Suggestion = require "avante.suggestion"
|
||||
local Config = require "avante.config"
|
||||
local Diff = require "avante.diff"
|
||||
|
||||
---@class Avante
|
||||
local M = {
|
||||
@@ -32,97 +32,78 @@ H.commands = function()
|
||||
api.nvim_create_user_command("Avante" .. n, c, o)
|
||||
end
|
||||
|
||||
cmd("Ask", function(opts)
|
||||
require("avante.api").ask(vim.trim(opts.args))
|
||||
end, { desc = "avante: ask AI for code suggestions", nargs = "*" })
|
||||
cmd("Toggle", function()
|
||||
M.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("Build", function()
|
||||
M.build()
|
||||
end, { desc = "avante: build dependencies" })
|
||||
cmd("SwitchProvider", function(opts)
|
||||
require("avante.api").switch_provider(vim.trim(opts.args or ""))
|
||||
end, {
|
||||
cmd(
|
||||
"Ask",
|
||||
function(opts) require("avante.api").ask(vim.trim(opts.args)) end,
|
||||
{ desc = "avante: ask AI for code suggestions", nargs = "*" }
|
||||
)
|
||||
cmd("Toggle", function() M.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("Build", function() M.build() end, { desc = "avante: build dependencies" })
|
||||
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 ""
|
||||
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)
|
||||
return vim.tbl_filter(function(key) return key:find(prefix, 1, true) == 1 end, Config.providers)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
H.keymaps = function()
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteAsk)", function()
|
||||
require("avante.api").ask()
|
||||
end, { noremap = true })
|
||||
vim.keymap.set("v", "<Plug>(AvanteEdit)", function()
|
||||
require("avante.api").edit()
|
||||
end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteRefresh)", function()
|
||||
require("avante.api").refresh()
|
||||
end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggle)", function()
|
||||
M.toggle()
|
||||
end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function()
|
||||
M.toggle.debug()
|
||||
end)
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggleHint)", function()
|
||||
M.toggle.hint()
|
||||
end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteAsk)", function() require("avante.api").ask() end, { noremap = true })
|
||||
vim.keymap.set("v", "<Plug>(AvanteEdit)", function() require("avante.api").edit() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteRefresh)", function() require("avante.api").refresh() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggle)", function() M.toggle() end, { noremap = true })
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function() M.toggle.debug() end)
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggleHint)", function() M.toggle.hint() end)
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictOurs)", function()
|
||||
Diff.choose("ours")
|
||||
end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictBoth)", function()
|
||||
Diff.choose("both")
|
||||
end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictTheirs)", function()
|
||||
Diff.choose("theirs")
|
||||
end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictAllTheirs)", function()
|
||||
Diff.choose("all_theirs")
|
||||
end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictCursor)", function()
|
||||
Diff.choose("cursor")
|
||||
end)
|
||||
vim.keymap.set("n", "<Plug>(AvanteConflictNextConflict)", function()
|
||||
Diff.find_next("ours")
|
||||
end)
|
||||
vim.keymap.set("n", "<Plug>(AvanteConflictPrevConflict)", function()
|
||||
Diff.find_prev("ours")
|
||||
end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictOurs)", function() Diff.choose "ours" end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictBoth)", function() Diff.choose "both" end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictTheirs)", function() Diff.choose "theirs" end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictAllTheirs)", function() Diff.choose "all_theirs" end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictCursor)", function() Diff.choose "cursor" end)
|
||||
vim.keymap.set("n", "<Plug>(AvanteConflictNextConflict)", function() Diff.find_next "ours" end)
|
||||
vim.keymap.set("n", "<Plug>(AvanteConflictPrevConflict)", function() Diff.find_prev "ours" end)
|
||||
|
||||
if Config.behaviour.auto_set_keymaps then
|
||||
Utils.safe_keymap_set({ "n", "v" }, Config.mappings.ask, function()
|
||||
require("avante.api").ask()
|
||||
end, { desc = "avante: ask" })
|
||||
Utils.safe_keymap_set("v", Config.mappings.edit, function()
|
||||
require("avante.api").edit()
|
||||
end, { desc = "avante: edit" })
|
||||
Utils.safe_keymap_set("n", Config.mappings.refresh, function()
|
||||
require("avante.api").refresh()
|
||||
end, { desc = "avante: refresh" })
|
||||
Utils.safe_keymap_set("n", Config.mappings.toggle.default, function()
|
||||
M.toggle()
|
||||
end, { desc = "avante: toggle" })
|
||||
Utils.safe_keymap_set("n", Config.mappings.toggle.debug, function()
|
||||
M.toggle.debug()
|
||||
end, { desc = "avante: toggle debug" })
|
||||
Utils.safe_keymap_set("n", Config.mappings.toggle.hint, function()
|
||||
M.toggle.hint()
|
||||
end, { desc = "avante: toggle hint" })
|
||||
Utils.safe_keymap_set(
|
||||
{ "n", "v" },
|
||||
Config.mappings.ask,
|
||||
function() require("avante.api").ask() end,
|
||||
{ desc = "avante: ask" }
|
||||
)
|
||||
Utils.safe_keymap_set(
|
||||
"v",
|
||||
Config.mappings.edit,
|
||||
function() require("avante.api").edit() end,
|
||||
{ desc = "avante: edit" }
|
||||
)
|
||||
Utils.safe_keymap_set(
|
||||
"n",
|
||||
Config.mappings.refresh,
|
||||
function() require("avante.api").refresh() end,
|
||||
{ desc = "avante: refresh" }
|
||||
)
|
||||
Utils.safe_keymap_set("n", Config.mappings.toggle.default, function() M.toggle() end, { desc = "avante: toggle" })
|
||||
Utils.safe_keymap_set(
|
||||
"n",
|
||||
Config.mappings.toggle.debug,
|
||||
function() M.toggle.debug() end,
|
||||
{ desc = "avante: toggle debug" }
|
||||
)
|
||||
Utils.safe_keymap_set(
|
||||
"n",
|
||||
Config.mappings.toggle.hint,
|
||||
function() M.toggle.hint() end,
|
||||
{ desc = "avante: toggle hint" }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -131,15 +112,11 @@ end
|
||||
|
||||
H.api = function(fun)
|
||||
return setmetatable({ api = true }, {
|
||||
__call = function(...)
|
||||
return fun(...)
|
||||
end,
|
||||
__call = function(...) return fun(...) end,
|
||||
}) --[[@as ApiCaller]]
|
||||
end
|
||||
|
||||
H.signs = function()
|
||||
vim.fn.sign_define("AvanteInputPromptSign", { text = Config.windows.input.prefix })
|
||||
end
|
||||
H.signs = function() vim.fn.sign_define("AvanteInputPromptSign", { text = Config.windows.input.prefix }) end
|
||||
|
||||
H.augroup = api.nvim_create_augroup("avante_autocmds", { clear = true })
|
||||
|
||||
@@ -148,9 +125,7 @@ H.autocmds = function()
|
||||
|
||||
if ok then
|
||||
local name = "avante.nvim"
|
||||
local load_path = function()
|
||||
require("avante_lib").load()
|
||||
end
|
||||
local load_path = function() require("avante_lib").load() end
|
||||
|
||||
if LazyConfig.plugins[name] and LazyConfig.plugins[name]._.loaded then
|
||||
vim.schedule(load_path)
|
||||
@@ -179,9 +154,7 @@ H.autocmds = function()
|
||||
callback = function(ev)
|
||||
local tab = tonumber(ev.file)
|
||||
M._init(tab or api.nvim_get_current_tabpage())
|
||||
if Config.hints.enabled and not M.current.selection.did_setup then
|
||||
M.current.selection:setup_autocmds()
|
||||
end
|
||||
if Config.hints.enabled and not M.current.selection.did_setup then M.current.selection:setup_autocmds() end
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -189,12 +162,8 @@ H.autocmds = function()
|
||||
group = H.augroup,
|
||||
callback = function()
|
||||
local sidebar = M.get()
|
||||
if not sidebar then
|
||||
return
|
||||
end
|
||||
if not sidebar:is_open() then
|
||||
return
|
||||
end
|
||||
if not sidebar then return end
|
||||
if not sidebar:is_open() then return end
|
||||
sidebar:resize()
|
||||
end,
|
||||
})
|
||||
@@ -206,43 +175,33 @@ H.autocmds = function()
|
||||
local tab = tonumber(ev.file)
|
||||
local s = M.sidebars[tab]
|
||||
local sl = M.selections[tab]
|
||||
if s then
|
||||
s:reset()
|
||||
end
|
||||
if sl then
|
||||
sl:delete_autocmds()
|
||||
end
|
||||
if tab ~= nil then
|
||||
M.sidebars[tab] = nil
|
||||
end
|
||||
if s then s:reset() end
|
||||
if sl then sl:delete_autocmds() end
|
||||
if tab ~= nil then M.sidebars[tab] = nil end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.schedule(function()
|
||||
M._init(api.nvim_get_current_tabpage())
|
||||
if Config.hints.enabled then
|
||||
M.current.selection:setup_autocmds()
|
||||
end
|
||||
if Config.hints.enabled then M.current.selection:setup_autocmds() end
|
||||
end)
|
||||
|
||||
api.nvim_create_autocmd("ColorSchemePre", {
|
||||
group = H.augroup,
|
||||
callback = function()
|
||||
require("avante.highlights").setup()
|
||||
end,
|
||||
callback = function() require("avante.highlights").setup() end,
|
||||
})
|
||||
|
||||
-- automatically setup Avante filetype to markdown
|
||||
vim.treesitter.language.register("markdown", "Avante")
|
||||
|
||||
vim.filetype.add({
|
||||
vim.filetype.add {
|
||||
extension = {
|
||||
["avanterules"] = "jinja",
|
||||
},
|
||||
pattern = {
|
||||
["%.avanterules%.[%w_.-]+"] = "jinja",
|
||||
},
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
---@param current boolean? false to disable setting current, otherwise use this to track across tabs.
|
||||
@@ -284,25 +243,17 @@ end
|
||||
|
||||
M.toggle = { api = true }
|
||||
|
||||
M.toggle.debug = H.api(Utils.toggle_wrap({
|
||||
M.toggle.debug = H.api(Utils.toggle_wrap {
|
||||
name = "debug",
|
||||
get = function()
|
||||
return Config.debug
|
||||
end,
|
||||
set = function(state)
|
||||
Config.override({ debug = state })
|
||||
end,
|
||||
}))
|
||||
get = function() return Config.debug end,
|
||||
set = function(state) Config.override { debug = state } end,
|
||||
})
|
||||
|
||||
M.toggle.hint = H.api(Utils.toggle_wrap({
|
||||
M.toggle.hint = H.api(Utils.toggle_wrap {
|
||||
name = "hint",
|
||||
get = function()
|
||||
return Config.hints.enabled
|
||||
end,
|
||||
set = function(state)
|
||||
Config.override({ hints = { enabled = state } })
|
||||
end,
|
||||
}))
|
||||
get = function() return Config.hints.enabled end,
|
||||
set = function(state) Config.override { hints = { enabled = state } } end,
|
||||
})
|
||||
|
||||
setmetatable(M.toggle, {
|
||||
__index = M.toggle,
|
||||
@@ -322,9 +273,7 @@ setmetatable(M.toggle, {
|
||||
local function to_windows_path(path)
|
||||
local winpath = path:gsub("/", "\\")
|
||||
|
||||
if winpath:match("^%a:") then
|
||||
winpath = winpath:sub(1, 2):upper() .. winpath:sub(3)
|
||||
end
|
||||
if winpath:match "^%a:" then winpath = winpath:sub(1, 2):upper() .. winpath:sub(3) end
|
||||
|
||||
winpath = winpath:gsub("\\$", "")
|
||||
|
||||
@@ -336,9 +285,7 @@ M.build = H.api(function()
|
||||
local git_root = vim.fs.find(".git", { path = dirname, upward = true })[1]
|
||||
local build_directory = git_root and vim.fn.fnamemodify(git_root, ":h") or (dirname .. "/../../")
|
||||
|
||||
if not vim.fn.executable("cargo") then
|
||||
error("Building avante.nvim requires cargo to be installed.", 2)
|
||||
end
|
||||
if not vim.fn.executable "cargo" then error("Building avante.nvim requires cargo to be installed.", 2) end
|
||||
|
||||
---@type string[]
|
||||
local cmd
|
||||
@@ -372,9 +319,7 @@ function M.setup(opts)
|
||||
---but most of the other functionality will only be called once from lazy.nvim
|
||||
Config.setup(opts)
|
||||
|
||||
if M.did_setup then
|
||||
return
|
||||
end
|
||||
if M.did_setup then return end
|
||||
|
||||
require("avante.path").setup()
|
||||
require("avante.highlights").setup()
|
||||
|
||||
Reference in New Issue
Block a user