fix(style): add parentheses (#471)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
parent
8cc674f1da
commit
0d8098e4eb
@ -1,5 +1,5 @@
|
||||
local Config = require "avante.config"
|
||||
local Utils = require "avante.utils"
|
||||
local Config = require("avante.config")
|
||||
local Utils = require("avante.utils")
|
||||
|
||||
---@class avante.ApiToggle
|
||||
---@operator call(): boolean
|
||||
@ -66,7 +66,7 @@ end
|
||||
|
||||
return setmetatable(M, {
|
||||
__index = function(t, k)
|
||||
local module = require "avante"
|
||||
local module = require("avante")
|
||||
---@class AvailableApi: ApiCaller
|
||||
---@field api? boolean
|
||||
local has = module[k]
|
||||
|
@ -1,9 +1,9 @@
|
||||
---NOTE: this module is inspired by https://github.com/HakonHarnes/img-clip.nvim/tree/main
|
||||
---@see https://github.com/ekickx/clipboard-image.nvim/blob/main/lua/clipboard-image/paste.lua
|
||||
|
||||
local Path = require "plenary.path"
|
||||
local Utils = require "avante.utils"
|
||||
local Config = require "avante.config"
|
||||
local Path = require("plenary.path")
|
||||
local Utils = require("avante.utils")
|
||||
local Config = require("avante.config")
|
||||
---@module "img-clip"
|
||||
local ImgClip = nil
|
||||
|
||||
@ -19,7 +19,7 @@ local paste_directory = nil
|
||||
---@return Path
|
||||
local function get_paste_directory()
|
||||
if paste_directory then return paste_directory end
|
||||
paste_directory = Path:new(Config.history.storage_path):joinpath "pasted_images"
|
||||
paste_directory = Path:new(Config.history.storage_path):joinpath("pasted_images")
|
||||
return paste_directory
|
||||
end
|
||||
|
||||
@ -28,9 +28,9 @@ M.support_paste_image = Config.support_paste_image
|
||||
M.setup = function()
|
||||
get_paste_directory()
|
||||
|
||||
if not paste_directory:exists() then paste_directory:mkdir { parent = true } end
|
||||
if not paste_directory:exists() then paste_directory:mkdir({ parent = true }) end
|
||||
|
||||
if M.support_paste_image() and ImgClip == nil then ImgClip = require "img-clip" end
|
||||
if M.support_paste_image() and ImgClip == nil then ImgClip = require("img-clip") end
|
||||
end
|
||||
|
||||
---@param line? string
|
||||
@ -46,7 +46,7 @@ M.paste_image = function(line)
|
||||
},
|
||||
}
|
||||
|
||||
if vim.fn.has "wsl" > 0 or vim.fn.has "win32" > 0 then opts.use_absolute_path = true end
|
||||
if vim.fn.has("wsl") > 0 or vim.fn.has("win32") > 0 then opts.use_absolute_path = true end
|
||||
|
||||
return ImgClip.paste_image(opts, line)
|
||||
end
|
||||
@ -65,7 +65,7 @@ M.get_base64_content = function(filepath)
|
||||
if output.code == 0 then
|
||||
return output.stdout
|
||||
else
|
||||
error "Failed to convert image to base64"
|
||||
error("Failed to convert image to base64")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
---NOTE: user will be merged with defaults and
|
||||
---we add a default var_accessor for this table to config values.
|
||||
|
||||
local Utils = require "avante.utils"
|
||||
local Utils = require("avante.utils")
|
||||
|
||||
---@class avante.CoreConfig: avante.Config
|
||||
local M = {}
|
||||
@ -100,7 +100,7 @@ You are an excellent programming expert.
|
||||
support_paste_from_clipboard = false,
|
||||
},
|
||||
history = {
|
||||
storage_path = vim.fn.stdpath "state" .. "/avante",
|
||||
storage_path = vim.fn.stdpath("state") .. "/avante",
|
||||
paste = {
|
||||
extension = "png",
|
||||
filename = "pasted-%Y-%m-%d-%H-%M-%S",
|
||||
@ -188,7 +188,7 @@ M.providers = {}
|
||||
|
||||
---@param opts? avante.Config
|
||||
function M.setup(opts)
|
||||
vim.validate { opts = { opts, "table", true } }
|
||||
vim.validate({ opts = { opts, "table", true } })
|
||||
|
||||
M.options = vim.tbl_deep_extend(
|
||||
"force",
|
||||
@ -214,7 +214,7 @@ function M.setup(opts)
|
||||
return acc
|
||||
end)
|
||||
|
||||
vim.validate { provider = { M.options.provider, "string", false } }
|
||||
vim.validate({ provider = { M.options.provider, "string", false } })
|
||||
|
||||
M.diff = vim.tbl_deep_extend(
|
||||
"force",
|
||||
@ -227,14 +227,14 @@ function M.setup(opts)
|
||||
for k, v in pairs(M.options.vendors) do
|
||||
M.options.vendors[k] = type(v) == "function" and v() or v
|
||||
end
|
||||
vim.validate { vendors = { M.options.vendors, "table", true } }
|
||||
vim.validate({ vendors = { M.options.vendors, "table", true } })
|
||||
M.providers = vim.list_extend(M.providers, vim.tbl_keys(M.options.vendors))
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts? avante.Config
|
||||
function M.override(opts)
|
||||
vim.validate { opts = { opts, "table", true } }
|
||||
vim.validate({ opts = { opts, "table", true } })
|
||||
|
||||
M.options = vim.tbl_deep_extend("force", M.options, opts or {})
|
||||
if not M.options.silent_warning then
|
||||
@ -254,7 +254,7 @@ function M.override(opts)
|
||||
M.options.vendors[k] = type(v) == "function" and v() or v
|
||||
if not vim.tbl_contains(M.providers, k) then M.providers = vim.list_extend(M.providers, { k }) end
|
||||
end
|
||||
vim.validate { vendors = { M.options.vendors, "table", true } }
|
||||
vim.validate({ vendors = { M.options.vendors, "table", true } })
|
||||
end
|
||||
end
|
||||
|
||||
@ -269,7 +269,7 @@ M.support_paste_image = function(skip_warning)
|
||||
skip_warning = skip_warning or M.silent_warning
|
||||
if skip_warning then return end
|
||||
|
||||
return Utils.has "img-clip.nvim" or Utils.has "img-clip"
|
||||
return Utils.has("img-clip.nvim") or Utils.has("img-clip")
|
||||
end
|
||||
|
||||
M.get_window_width = function() return math.ceil(vim.o.columns * (M.windows.width / 100)) end
|
||||
|
@ -1,8 +1,8 @@
|
||||
local api = vim.api
|
||||
|
||||
local Config = require "avante.config"
|
||||
local Utils = require "avante.utils"
|
||||
local Highlights = require "avante.highlights"
|
||||
local Config = require("avante.config")
|
||||
local Utils = require("avante.utils")
|
||||
local Highlights = require("avante.highlights")
|
||||
|
||||
local H = {}
|
||||
local M = {}
|
||||
@ -82,8 +82,8 @@ local INCOMING_HL = "AvanteConflictIncoming"
|
||||
local CURRENT_LABEL_HL = "AvanteConflictCurrentLabel"
|
||||
local INCOMING_LABEL_HL = "AvanteConflictIncomingLabel"
|
||||
local PRIORITY = vim.highlight.priorities.user
|
||||
local NAMESPACE = api.nvim_create_namespace "avante-conflict"
|
||||
local KEYBINDING_NAMESPACE = api.nvim_create_namespace "avante-conflict-keybinding"
|
||||
local NAMESPACE = api.nvim_create_namespace("avante-conflict")
|
||||
local KEYBINDING_NAMESPACE = api.nvim_create_namespace("avante-conflict-keybinding")
|
||||
local AUGROUP_NAME = "avante_conflicts"
|
||||
|
||||
local conflict_start = "^<<<<<<<"
|
||||
@ -354,18 +354,18 @@ H.setup_buffer_mappings = function(bufnr)
|
||||
---@param desc string
|
||||
local function opts(desc) return { silent = true, buffer = bufnr, desc = "avante(conflict): " .. desc } end
|
||||
|
||||
vim.keymap.set({ "n", "v" }, Config.diff.mappings.ours, function() M.choose "ours" end, opts "choose ours")
|
||||
vim.keymap.set({ "n", "v" }, Config.diff.mappings.both, function() M.choose "both" end, opts "choose both")
|
||||
vim.keymap.set({ "n", "v" }, Config.diff.mappings.theirs, function() M.choose "theirs" end, opts "choose theirs")
|
||||
vim.keymap.set({ "n", "v" }, Config.diff.mappings.ours, function() M.choose("ours") end, opts("choose ours"))
|
||||
vim.keymap.set({ "n", "v" }, Config.diff.mappings.both, function() M.choose("both") end, opts("choose both"))
|
||||
vim.keymap.set({ "n", "v" }, Config.diff.mappings.theirs, function() M.choose("theirs") end, opts("choose theirs"))
|
||||
vim.keymap.set(
|
||||
{ "n", "v" },
|
||||
Config.diff.mappings.all_theirs,
|
||||
function() M.choose "all_theirs" end,
|
||||
opts "choose all theirs"
|
||||
function() M.choose("all_theirs") end,
|
||||
opts("choose all theirs")
|
||||
)
|
||||
vim.keymap.set("n", Config.diff.mappings.cursor, function() M.choose "cursor" end, opts "choose under cursor")
|
||||
vim.keymap.set("n", Config.diff.mappings.prev, function() M.find_prev "ours" end, opts "previous conflict")
|
||||
vim.keymap.set("n", Config.diff.mappings.next, function() M.find_next "ours" end, opts "next conflict")
|
||||
vim.keymap.set("n", Config.diff.mappings.cursor, function() M.choose("cursor") end, opts("choose under cursor"))
|
||||
vim.keymap.set("n", Config.diff.mappings.prev, function() M.find_prev("ours") end, opts("previous conflict"))
|
||||
vim.keymap.set("n", Config.diff.mappings.next, function() M.find_next("ours") end, opts("next conflict"))
|
||||
|
||||
vim.b[bufnr].avante_conflict_mappings_set = true
|
||||
end
|
||||
@ -390,7 +390,7 @@ function M.setup()
|
||||
callback = function(ev)
|
||||
vim.diagnostic.enable(false, { bufnr = ev.buf })
|
||||
if vim.lsp.inlay_hint then
|
||||
previous_inlay_enabled = vim.lsp.inlay_hint.is_enabled { bufnr = ev.buf }
|
||||
previous_inlay_enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = ev.buf })
|
||||
vim.lsp.inlay_hint.enable(false, { bufnr = ev.buf })
|
||||
end
|
||||
H.setup_buffer_mappings(ev.buf)
|
||||
@ -515,7 +515,7 @@ function M.choose(side)
|
||||
end, 50)
|
||||
if Config.diff.autojump then
|
||||
M.find_next(side)
|
||||
vim.cmd [[normal! zz]]
|
||||
vim.cmd([[normal! zz]])
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -550,7 +550,7 @@ function M.process_position(bufnr, side, position, enable_autojump)
|
||||
lines = {}
|
||||
elseif side == SIDES.CURSOR then
|
||||
local cursor_line = Utils.get_cursor_pos()
|
||||
for _, pos in ipairs { SIDES.OURS, SIDES.THEIRS, SIDES.BASE } do
|
||||
for _, pos in ipairs({ SIDES.OURS, SIDES.THEIRS, SIDES.BASE }) do
|
||||
local data = position[name_map[pos]] or {}
|
||||
if data.range_start and data.range_start + 1 <= cursor_line and data.range_end + 1 >= cursor_line then
|
||||
side = pos
|
||||
@ -572,7 +572,7 @@ function M.process_position(bufnr, side, position, enable_autojump)
|
||||
parse_buffer(bufnr)
|
||||
if enable_autojump and Config.diff.autojump then
|
||||
M.find_next(side)
|
||||
vim.cmd [[normal! zz]]
|
||||
vim.cmd([[normal! zz]])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
local api = vim.api
|
||||
|
||||
local Config = require "avante.config"
|
||||
local bit = require "bit"
|
||||
local Config = require("avante.config")
|
||||
local bit = require("bit")
|
||||
local rshift, band = bit.rshift, bit.band
|
||||
|
||||
local Highlights = {
|
||||
@ -29,8 +29,8 @@ local H = {}
|
||||
|
||||
local M = {}
|
||||
|
||||
M.input_ns = api.nvim_create_namespace "avante_input"
|
||||
M.hint_ns = api.nvim_create_namespace "avante_hint"
|
||||
M.input_ns = api.nvim_create_namespace("avante_input")
|
||||
M.hint_ns = api.nvim_create_namespace("avante_hint")
|
||||
|
||||
local function has_set_colors(hl_group)
|
||||
local hl = api.nvim_get_hl(0, { name = hl_group })
|
||||
@ -46,7 +46,7 @@ M.setup = function()
|
||||
.iter(Highlights)
|
||||
:filter(function(k, _)
|
||||
-- return all uppercase key with underscore or fully uppercase key
|
||||
return k:match "^%u+_" or k:match "^%u+$"
|
||||
return k:match("^%u+_") or k:match("^%u+$")
|
||||
end)
|
||||
:each(function(_, hl)
|
||||
if not has_set_colors(hl.name) then
|
||||
@ -113,7 +113,7 @@ setmetatable(M, {
|
||||
---@param rgb_24bit number 24-bit RGB value
|
||||
---@return {r: integer, g: integer, b: integer} with keys 'r', 'g', 'b' in [0,255]
|
||||
H.decode_24bit_rgb = function(rgb_24bit)
|
||||
vim.validate { rgb_24bit = { rgb_24bit, "n", true } }
|
||||
vim.validate({ rgb_24bit = { rgb_24bit, "n", true } })
|
||||
local r = band(rshift(rgb_24bit, 16), 255)
|
||||
local g = band(rshift(rgb_24bit, 8), 255)
|
||||
local b = band(rgb_24bit, 255)
|
||||
|
@ -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 = {
|
||||
@ -49,7 +49,7 @@ H.commands = function()
|
||||
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)
|
||||
end,
|
||||
@ -64,13 +64,13 @@ H.keymaps = function()
|
||||
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(
|
||||
@ -194,14 +194,14 @@ H.autocmds = function()
|
||||
-- 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.
|
||||
@ -243,17 +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,
|
||||
})
|
||||
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,
|
||||
})
|
||||
set = function(state) Config.override({ hints = { enabled = state } }) end,
|
||||
}))
|
||||
|
||||
setmetatable(M.toggle, {
|
||||
__index = M.toggle,
|
||||
@ -273,7 +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("\\$", "")
|
||||
|
||||
@ -285,7 +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
|
||||
|
@ -1,11 +1,11 @@
|
||||
local api = vim.api
|
||||
|
||||
local curl = require "plenary.curl"
|
||||
local curl = require("plenary.curl")
|
||||
|
||||
local Utils = require "avante.utils"
|
||||
local Config = require "avante.config"
|
||||
local Path = require "avante.path"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local Config = require("avante.config")
|
||||
local Path = require("avante.path")
|
||||
local P = require("avante.providers")
|
||||
|
||||
---@class avante.LLM
|
||||
local M = {}
|
||||
@ -44,10 +44,10 @@ M.stream = function(opts)
|
||||
-- Check if the instructions contains an image path
|
||||
local image_paths = {}
|
||||
local original_instructions = opts.instructions
|
||||
if opts.instructions:match "image: " then
|
||||
if opts.instructions:match("image: ") then
|
||||
local lines = vim.split(opts.instructions, "\n")
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match "^image: " then
|
||||
if line:match("^image: ") then
|
||||
local image_path = line:gsub("^image: ", "")
|
||||
table.insert(image_paths, image_path)
|
||||
table.remove(lines, i)
|
||||
@ -89,12 +89,12 @@ M.stream = function(opts)
|
||||
|
||||
---@param line string
|
||||
local function parse_stream_data(line)
|
||||
local event = line:match "^event: (.+)$"
|
||||
local event = line:match("^event: (.+)$")
|
||||
if event then
|
||||
current_event_state = event
|
||||
return
|
||||
end
|
||||
local data_match = line:match "^data: (.+)$"
|
||||
local data_match = line:match("^data: (.+)$")
|
||||
if data_match then Provider.parse_response(data_match, current_event_state, handler_opts) end
|
||||
end
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
local fn, api = vim.fn, vim.api
|
||||
local Utils = require "avante.utils"
|
||||
local Path = require "plenary.path"
|
||||
local Scan = require "plenary.scandir"
|
||||
local Config = require "avante.config"
|
||||
local Utils = require("avante.utils")
|
||||
local Path = require("plenary.path")
|
||||
local Scan = require("plenary.scandir")
|
||||
local Config = require("avante.config")
|
||||
|
||||
---@class avante.Path
|
||||
---@field history_path Path
|
||||
@ -75,26 +75,26 @@ N.get = function(bufnr)
|
||||
if not P.available() then error("Make sure to build avante (missing avante_templates)", 2) end
|
||||
|
||||
-- get root directory of given bufnr
|
||||
local directory = Path:new(Utils.root.get { buf = bufnr })
|
||||
local directory = Path:new(Utils.root.get({ buf = bufnr }))
|
||||
---@cast directory Path
|
||||
---@type Path
|
||||
local cache_prompt_dir = P.cache_path:joinpath(directory)
|
||||
if not cache_prompt_dir:exists() then cache_prompt_dir:mkdir { parents = true } end
|
||||
if not cache_prompt_dir:exists() then cache_prompt_dir:mkdir({ parents = true }) end
|
||||
|
||||
local scanner = Scan.scan_dir(directory:absolute(), { depth = 1, add_dirs = true })
|
||||
for _, entry in ipairs(scanner) do
|
||||
local file = Path:new(entry)
|
||||
if entry:find "planning" and N.templates.planning == nil then
|
||||
if entry:find("planning") and N.templates.planning == nil then
|
||||
N.templates.planning = file:read()
|
||||
elseif entry:find "editing" and N.templates.editing == nil then
|
||||
elseif entry:find("editing") and N.templates.editing == nil then
|
||||
N.templates.editing = file:read()
|
||||
elseif entry:find "suggesting" and N.templates.suggesting == nil then
|
||||
elseif entry:find("suggesting") and N.templates.suggesting == nil then
|
||||
N.templates.suggesting = file:read()
|
||||
end
|
||||
end
|
||||
|
||||
Path:new(debug.getinfo(1).source:match("@?(.*/)"):gsub("/lua/avante/path.lua$", "") .. "templates")
|
||||
:copy { destination = cache_prompt_dir, recursive = true }
|
||||
:copy({ destination = cache_prompt_dir, recursive = true })
|
||||
|
||||
vim.iter(N.templates):filter(function(_, v) return v ~= nil end):each(function(k, v)
|
||||
local f = cache_prompt_dir:joinpath(H.get_mode_file(k))
|
||||
@ -120,11 +120,11 @@ P.prompts = N
|
||||
|
||||
P.setup = function()
|
||||
local history_path = Path:new(Config.history.storage_path)
|
||||
if not history_path:exists() then history_path:mkdir { parents = true } end
|
||||
if not history_path:exists() then history_path:mkdir({ parents = true }) end
|
||||
P.history_path = history_path
|
||||
|
||||
local cache_path = Path:new(vim.fn.stdpath "cache" .. "/avante")
|
||||
if not cache_path:exists() then cache_path:mkdir { parents = true } end
|
||||
local cache_path = Path:new(vim.fn.stdpath("cache") .. "/avante")
|
||||
if not cache_path:exists() then cache_path:mkdir({ parents = true }) end
|
||||
P.cache_path = cache_path
|
||||
|
||||
vim.defer_fn(function()
|
||||
@ -138,6 +138,6 @@ end
|
||||
|
||||
P.available = function() return templates ~= nil end
|
||||
|
||||
P.clear = function() P.cache_path:rm { recursive = true } end
|
||||
P.clear = function() P.cache_path:rm({ recursive = true }) end
|
||||
|
||||
return P
|
||||
|
@ -4,8 +4,8 @@
|
||||
---@field temperature number
|
||||
---@field max_tokens number
|
||||
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
local O = require("avante.providers").openai
|
||||
|
||||
---@class AvanteProviderFunctor
|
||||
@ -23,7 +23,7 @@ M.parse_curl_args = function(provider, code_opts)
|
||||
local headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
}
|
||||
if not P.env.is_local "azure" then headers["api-key"] = provider.parse_api_key() end
|
||||
if not P.env.is_local("azure") then headers["api-key"] = provider.parse_api_key() end
|
||||
|
||||
return {
|
||||
url = Utils.trim(base.endpoint, { suffix = "/" })
|
||||
|
@ -1,6 +1,6 @@
|
||||
local Utils = require "avante.utils"
|
||||
local Clipboard = require "avante.clipboard"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local Clipboard = require("avante.clipboard")
|
||||
local P = require("avante.providers")
|
||||
|
||||
---@class AvanteProviderFunctor
|
||||
local M = {}
|
||||
@ -65,7 +65,7 @@ M.parse_curl_args = function(provider, prompt_opts)
|
||||
["anthropic-version"] = "2023-06-01",
|
||||
["anthropic-beta"] = "prompt-caching-2024-07-31",
|
||||
}
|
||||
if not P.env.is_local "claude" then headers["x-api-key"] = provider.parse_api_key() end
|
||||
if not P.env.is_local("claude") then headers["x-api-key"] = provider.parse_api_key() end
|
||||
|
||||
local messages = M.parse_message(prompt_opts)
|
||||
|
||||
@ -104,7 +104,7 @@ M.on_error = function(result)
|
||||
|
||||
if error_type == "insufficient_quota" then
|
||||
error_msg = "You don't have any credits or have exceeded your quota. Please check your plan and billing details."
|
||||
elseif error_type == "invalid_request_error" and error_msg:match "temperature" then
|
||||
elseif error_type == "invalid_request_error" and error_msg:match("temperature") then
|
||||
error_msg = "Invalid temperature value. Please ensure it's between 0 and 1."
|
||||
end
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
|
||||
---@alias CohereFinishReason "COMPLETE" | "LENGTH" | "ERROR"
|
||||
---
|
||||
@ -69,7 +69,7 @@ M.parse_curl_args = function(provider, code_opts)
|
||||
.. "."
|
||||
.. vim.version().patch,
|
||||
}
|
||||
if not P.env.is_local "cohere" then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
||||
if not P.env.is_local("cohere") then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
||||
|
||||
return {
|
||||
url = Utils.trim(base.endpoint, { suffix = "/" }) .. "/chat",
|
||||
|
@ -25,12 +25,12 @@
|
||||
---@field xcode boolean
|
||||
---@field xcode_chat boolean
|
||||
|
||||
local curl = require "plenary.curl"
|
||||
local curl = require("plenary.curl")
|
||||
|
||||
local Config = require "avante.config"
|
||||
local Path = require "plenary.path"
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Config = require("avante.config")
|
||||
local Path = require("plenary.path")
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
local O = require("avante.providers").openai
|
||||
|
||||
local H = {}
|
||||
@ -41,15 +41,15 @@ local H = {}
|
||||
---
|
||||
---@return string
|
||||
H.get_oauth_token = function()
|
||||
local xdg_config = vim.fn.expand "$XDG_CONFIG_HOME"
|
||||
local xdg_config = vim.fn.expand("$XDG_CONFIG_HOME")
|
||||
local os_name = Utils.get_os_name()
|
||||
---@type string
|
||||
local config_dir
|
||||
|
||||
if vim.tbl_contains({ "linux", "darwin" }, os_name) then
|
||||
config_dir = (xdg_config and vim.fn.isdirectory(xdg_config) > 0) and xdg_config or vim.fn.expand "~/.config"
|
||||
config_dir = (xdg_config and vim.fn.isdirectory(xdg_config) > 0) and xdg_config or vim.fn.expand("~/.config")
|
||||
else
|
||||
config_dir = vim.fn.expand "~/AppData/Local"
|
||||
config_dir = vim.fn.expand("~/AppData/Local")
|
||||
end
|
||||
|
||||
--- hosts.json (copilot.lua), apps.json (copilot.vim)
|
||||
@ -67,7 +67,7 @@ H.get_oauth_token = function()
|
||||
---@type table<string, OAuthToken>
|
||||
vim.json.decode(yason:read())
|
||||
)
|
||||
:filter(function(k, _) return k:match "github.com" end)
|
||||
:filter(function(k, _) return k:match("github.com") end)
|
||||
---@param acc {oauth_token: string}
|
||||
:fold({}, function(acc, _, v)
|
||||
acc.oauth_token = v.oauth_token
|
||||
@ -83,7 +83,7 @@ H.chat_completion_url = function(base_url) return Utils.trim(base_url, { prefix
|
||||
local M = {}
|
||||
|
||||
H.refresh_token = function()
|
||||
if not M.state then error "internal initialization error" end
|
||||
if not M.state then error("internal initialization error") end
|
||||
|
||||
if
|
||||
not M.state.github_token
|
||||
|
@ -1,6 +1,6 @@
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Clipboard = require "avante.clipboard"
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
local Clipboard = require("avante.clipboard")
|
||||
|
||||
---@class AvanteProviderFunctor
|
||||
local M = {}
|
||||
|
@ -1,8 +1,8 @@
|
||||
local api = vim.api
|
||||
|
||||
local Config = require "avante.config"
|
||||
local Utils = require "avante.utils"
|
||||
local Dressing = require "avante.ui.dressing"
|
||||
local Config = require("avante.config")
|
||||
local Utils = require("avante.utils")
|
||||
local Dressing = require("avante.ui.dressing")
|
||||
|
||||
---@class AvanteHandlerOptions: table<[string], string>
|
||||
---@field on_chunk AvanteChunkParser
|
||||
@ -98,11 +98,11 @@ E.cache = {}
|
||||
---@return string | nil
|
||||
E.parse_envvar = function(Opts)
|
||||
local api_key_name = Opts.api_key_name
|
||||
if api_key_name == nil then error "Requires api_key_name" end
|
||||
if api_key_name == nil then error("Requires api_key_name") end
|
||||
|
||||
if E.cache[api_key_name] ~= nil then return E.cache[api_key_name] end
|
||||
|
||||
local cmd = api_key_name:match "^cmd:(.*)"
|
||||
local cmd = api_key_name:match("^cmd:(.*)")
|
||||
|
||||
local key = nil
|
||||
|
||||
@ -173,7 +173,7 @@ E.setup = function(opts)
|
||||
opts.provider.setup()
|
||||
|
||||
-- check if var is a all caps string
|
||||
if var == M.AVANTE_INTERNAL_KEY or var:match "^cmd:(.*)" then return end
|
||||
if var == M.AVANTE_INTERNAL_KEY or var:match("^cmd:(.*)") then return end
|
||||
|
||||
local refresh = opts.refresh or false
|
||||
|
||||
@ -208,10 +208,10 @@ E.setup = function(opts)
|
||||
"noice",
|
||||
}
|
||||
if not vim.tbl_contains(exclude_filetypes, vim.bo.filetype) and not opts.provider.has() then
|
||||
Dressing.initialize_input_buffer {
|
||||
Dressing.initialize_input_buffer({
|
||||
opts = { prompt = "Enter " .. var .. ": " },
|
||||
on_confirm = on_confirm,
|
||||
}
|
||||
})
|
||||
end
|
||||
end, 200)
|
||||
end
|
||||
@ -284,16 +284,16 @@ M.setup = function()
|
||||
|
||||
---@type AvanteProviderFunctor
|
||||
local provider = M[Config.provider]
|
||||
E.setup { provider = provider }
|
||||
E.setup({ provider = provider })
|
||||
end
|
||||
|
||||
---@param provider Provider
|
||||
function M.refresh(provider)
|
||||
require("avante.config").override { provider = provider }
|
||||
require("avante.config").override({ provider = provider })
|
||||
|
||||
---@type AvanteProviderFunctor
|
||||
local p = M[Config.provider]
|
||||
E.setup { provider = p, refresh = true }
|
||||
E.setup({ provider = p, refresh = true })
|
||||
Utils.info("Switch to provider: " .. provider, { once = true, title = "Avante" })
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
local Utils = require "avante.utils"
|
||||
local Config = require "avante.config"
|
||||
local Clipboard = require "avante.clipboard"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local Config = require("avante.config")
|
||||
local Clipboard = require("avante.clipboard")
|
||||
local P = require("avante.providers")
|
||||
|
||||
---@class OpenAIChatResponse
|
||||
---@field id string
|
||||
@ -56,11 +56,11 @@ M.parse_message = function(opts)
|
||||
end
|
||||
|
||||
M.parse_response = function(data_stream, _, opts)
|
||||
if data_stream:match '"%[DONE%]":' then
|
||||
if data_stream:match('"%[DONE%]":') then
|
||||
opts.on_complete(nil)
|
||||
return
|
||||
end
|
||||
if data_stream:match '"delta":' then
|
||||
if data_stream:match('"delta":') then
|
||||
---@type OpenAIChatResponse
|
||||
local json = vim.json.decode(data_stream)
|
||||
if json.choices and json.choices[1] then
|
||||
@ -80,7 +80,7 @@ M.parse_curl_args = function(provider, code_opts)
|
||||
local headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
}
|
||||
if not P.env.is_local "openai" then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
||||
if not P.env.is_local("openai") then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
||||
|
||||
return {
|
||||
url = Utils.trim(base.endpoint, { suffix = "/" }) .. "/chat/completions",
|
||||
|
@ -1,13 +1,13 @@
|
||||
local Utils = require "avante.utils"
|
||||
local Config = require "avante.config"
|
||||
local Llm = require "avante.llm"
|
||||
local Highlights = require "avante.highlights"
|
||||
local Utils = require("avante.utils")
|
||||
local Config = require("avante.config")
|
||||
local Llm = require("avante.llm")
|
||||
local Highlights = require("avante.highlights")
|
||||
|
||||
local api = vim.api
|
||||
local fn = vim.fn
|
||||
|
||||
local NAMESPACE = api.nvim_create_namespace "avante_selection"
|
||||
local SELECTED_CODE_NAMESPACE = api.nvim_create_namespace "avante_selected_code"
|
||||
local NAMESPACE = api.nvim_create_namespace("avante_selection")
|
||||
local SELECTED_CODE_NAMESPACE = api.nvim_create_namespace("avante_selected_code")
|
||||
local PRIORITY = vim.highlight.priorities.user
|
||||
|
||||
local EDITING_INPUT_START_SPINNER_PATTERN = "AvanteEditingInputStartSpinner"
|
||||
@ -43,7 +43,7 @@ function Selection:new(id)
|
||||
end
|
||||
|
||||
function Selection:get_virt_text_line()
|
||||
local current_pos = fn.getpos "."
|
||||
local current_pos = fn.getpos(".")
|
||||
|
||||
-- Get the current and start position line numbers
|
||||
local current_line = current_pos[2] - 1 -- 0-indexed
|
||||
@ -81,7 +81,7 @@ end
|
||||
function Selection:close_editing_input()
|
||||
self:close_editing_input_shortcuts_hints()
|
||||
Llm.cancel_inflight_request()
|
||||
if api.nvim_get_mode().mode == "i" then vim.cmd [[stopinsert]] end
|
||||
if api.nvim_get_mode().mode == "i" then vim.cmd([[stopinsert]]) end
|
||||
if self.editing_input_winid and api.nvim_win_is_valid(self.editing_input_winid) then
|
||||
api.nvim_win_close(self.editing_input_winid, true)
|
||||
self.editing_input_winid = nil
|
||||
@ -387,7 +387,7 @@ function Selection:create_editing_input()
|
||||
|
||||
local filetype = api.nvim_get_option_value("filetype", { buf = code_bufnr })
|
||||
|
||||
Llm.stream {
|
||||
Llm.stream({
|
||||
bufnr = code_bufnr,
|
||||
file_content = code_content,
|
||||
code_lang = filetype,
|
||||
@ -396,7 +396,7 @@ function Selection:create_editing_input()
|
||||
mode = "editing",
|
||||
on_chunk = on_chunk,
|
||||
on_complete = on_complete,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
---@return string
|
||||
|
@ -1,19 +1,19 @@
|
||||
local api = vim.api
|
||||
local fn = vim.fn
|
||||
|
||||
local Split = require "nui.split"
|
||||
local Split = require("nui.split")
|
||||
local event = require("nui.utils.autocmd").event
|
||||
|
||||
local Path = require "avante.path"
|
||||
local Config = require "avante.config"
|
||||
local Diff = require "avante.diff"
|
||||
local Llm = require "avante.llm"
|
||||
local Utils = require "avante.utils"
|
||||
local Highlights = require "avante.highlights"
|
||||
local Path = require("avante.path")
|
||||
local Config = require("avante.config")
|
||||
local Diff = require("avante.diff")
|
||||
local Llm = require("avante.llm")
|
||||
local Utils = require("avante.utils")
|
||||
local Highlights = require("avante.highlights")
|
||||
|
||||
local RESULT_BUF_NAME = "AVANTE_RESULT"
|
||||
local VIEW_BUFFER_UPDATED_PATTERN = "AvanteViewBufferUpdated"
|
||||
local CODEBLOCK_KEYBINDING_NAMESPACE = api.nvim_create_namespace "AVANTE_CODEBLOCK_KEYBINDING"
|
||||
local CODEBLOCK_KEYBINDING_NAMESPACE = api.nvim_create_namespace("AVANTE_CODEBLOCK_KEYBINDING")
|
||||
local PRIORITY = vim.highlight.priorities.user
|
||||
|
||||
---@class avante.Sidebar
|
||||
@ -82,7 +82,7 @@ function Sidebar:open()
|
||||
self:focus()
|
||||
end
|
||||
|
||||
vim.cmd "wincmd ="
|
||||
vim.cmd("wincmd =")
|
||||
return self
|
||||
end
|
||||
|
||||
@ -93,7 +93,7 @@ function Sidebar:close()
|
||||
end
|
||||
if self.code and self.code.winid and api.nvim_win_is_valid(self.code.winid) then fn.win_gotoid(self.code.winid) end
|
||||
|
||||
vim.cmd "wincmd ="
|
||||
vim.cmd("wincmd =")
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
@ -322,12 +322,12 @@ local function extract_code_snippets(code_content, response_content)
|
||||
local explanation = ""
|
||||
|
||||
for idx, line in ipairs(vim.split(response_content, "\n")) do
|
||||
local start_line_str, end_line_str = line:match "^Replace lines: (%d+)-(%d+)"
|
||||
local start_line_str, end_line_str = line:match("^Replace lines: (%d+)-(%d+)")
|
||||
if start_line_str ~= nil and end_line_str ~= nil then
|
||||
start_line = tonumber(start_line_str)
|
||||
end_line = tonumber(end_line_str)
|
||||
end
|
||||
if line:match "^```" then
|
||||
if line:match("^```") then
|
||||
if in_code_block then
|
||||
if start_line ~= nil and end_line ~= nil then
|
||||
local snippet = {
|
||||
@ -346,7 +346,7 @@ local function extract_code_snippets(code_content, response_content)
|
||||
explanation = ""
|
||||
in_code_block = false
|
||||
else
|
||||
lang = line:match "^```(%w+)"
|
||||
lang = line:match("^```(%w+)")
|
||||
if not lang or lang == "" then lang = "text" end
|
||||
in_code_block = true
|
||||
start_line_in_response_buf = idx
|
||||
@ -471,9 +471,9 @@ local function parse_codeblocks(buf)
|
||||
|
||||
local lines = Utils.get_buf_lines(0, -1, buf)
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match "^```" then
|
||||
if line:match("^```") then
|
||||
-- parse language
|
||||
local lang_ = line:match "^```(%w+)"
|
||||
local lang_ = line:match("^```(%w+)")
|
||||
if in_codeblock and not lang_ then
|
||||
table.insert(codeblocks, { start_line = start_line, end_line = i - 1, lang = lang })
|
||||
in_codeblock = false
|
||||
@ -521,8 +521,8 @@ function Sidebar:apply(current_cursor)
|
||||
Diff.process(self.code.bufnr)
|
||||
api.nvim_win_set_cursor(self.code.winid, { 1, 0 })
|
||||
vim.defer_fn(function()
|
||||
Diff.find_next "ours"
|
||||
vim.cmd "normal! zz"
|
||||
Diff.find_next("ours")
|
||||
vim.cmd("normal! zz")
|
||||
end, 1000)
|
||||
end, 10)
|
||||
end
|
||||
@ -723,7 +723,7 @@ function Sidebar:on_mount()
|
||||
|
||||
if target_block then
|
||||
api.nvim_win_set_cursor(self.result.winid, { target_block.start_line + 1, 0 })
|
||||
vim.cmd "normal! zz"
|
||||
vim.cmd("normal! zz")
|
||||
end
|
||||
end
|
||||
|
||||
@ -731,13 +731,13 @@ function Sidebar:on_mount()
|
||||
vim.keymap.set(
|
||||
"n",
|
||||
Config.mappings.jump.next,
|
||||
function() jump_to_codeblock "next" end,
|
||||
function() jump_to_codeblock("next") end,
|
||||
{ buffer = self.result.bufnr, noremap = true, silent = true }
|
||||
)
|
||||
vim.keymap.set(
|
||||
"n",
|
||||
Config.mappings.jump.prev,
|
||||
function() jump_to_codeblock "prev" end,
|
||||
function() jump_to_codeblock("prev") end,
|
||||
{ buffer = self.result.bufnr, noremap = true, silent = true }
|
||||
)
|
||||
end
|
||||
@ -898,7 +898,7 @@ function Sidebar:resize()
|
||||
self:render_result()
|
||||
self:render_input()
|
||||
self:render_selected_code()
|
||||
vim.defer_fn(function() vim.cmd "AvanteRefresh" end, 200)
|
||||
vim.defer_fn(function() vim.cmd("AvanteRefresh") end, 200)
|
||||
end
|
||||
|
||||
--- Initialize the sidebar instance.
|
||||
@ -978,7 +978,7 @@ function Sidebar:update_content(content, opts)
|
||||
end
|
||||
|
||||
-- Function to get current timestamp
|
||||
local function get_timestamp() return os.date "%Y-%m-%d %H:%M:%S" end
|
||||
local function get_timestamp() return os.date("%Y-%m-%d %H:%M:%S") end
|
||||
|
||||
local function get_chat_record_prefix(timestamp, provider, model, request)
|
||||
provider = provider or "unknown"
|
||||
@ -1119,7 +1119,7 @@ function Sidebar:create_selected_code()
|
||||
local selected_code_size = self:get_selected_code_size()
|
||||
|
||||
if self.code.selection ~= nil then
|
||||
self.selected_code = Split {
|
||||
self.selected_code = Split({
|
||||
enter = false,
|
||||
relative = {
|
||||
type = "win",
|
||||
@ -1131,7 +1131,7 @@ function Sidebar:create_selected_code()
|
||||
size = {
|
||||
height = selected_code_size + 3,
|
||||
},
|
||||
}
|
||||
})
|
||||
self.selected_code:mount()
|
||||
if self:get_layout() == "horizontal" then
|
||||
api.nvim_win_set_height(self.result.winid, api.nvim_win_get_height(self.result.winid) - selected_code_size - 3)
|
||||
@ -1174,7 +1174,7 @@ function Sidebar:create_input()
|
||||
end
|
||||
|
||||
if request:sub(1, 1) == "/" then
|
||||
local command, args = request:match "^/(%S+)%s*(.*)"
|
||||
local command, args = request:match("^/(%S+)%s*(.*)")
|
||||
if command == nil then
|
||||
self:update_content("Invalid command", { focus = false, scroll = false })
|
||||
return
|
||||
@ -1185,7 +1185,7 @@ function Sidebar:create_input()
|
||||
if cmd then
|
||||
if command == "lines" then
|
||||
cmd.callback(args, function(args_)
|
||||
local start_line, end_line, question = args_:match "(%d+)-(%d+)%s+(.*)"
|
||||
local start_line, end_line, question = args_:match("(%d+)-(%d+)%s+(.*)")
|
||||
---@cast start_line integer
|
||||
start_line = tonumber(start_line)
|
||||
---@cast end_line integer
|
||||
@ -1223,7 +1223,7 @@ function Sidebar:create_input()
|
||||
return
|
||||
end
|
||||
self:update_content(chunk, { stream = true, scroll = true })
|
||||
vim.schedule(function() vim.cmd "redraw" end)
|
||||
vim.schedule(function() vim.cmd("redraw") end)
|
||||
end
|
||||
|
||||
---@type AvanteCompleteParser
|
||||
@ -1257,7 +1257,7 @@ function Sidebar:create_input()
|
||||
Path.history.save(self.code.bufnr, chat_history)
|
||||
end
|
||||
|
||||
Llm.stream {
|
||||
Llm.stream({
|
||||
bufnr = self.code.bufnr,
|
||||
file_content = content_with_line_numbers,
|
||||
code_lang = filetype,
|
||||
@ -1266,7 +1266,7 @@ function Sidebar:create_input()
|
||||
mode = "planning",
|
||||
on_chunk = on_chunk,
|
||||
on_complete = on_complete,
|
||||
}
|
||||
})
|
||||
|
||||
if Config.behaviour.auto_apply_diff_after_generation then self:apply(false) end
|
||||
end
|
||||
@ -1289,7 +1289,7 @@ function Sidebar:create_input()
|
||||
}
|
||||
end
|
||||
|
||||
self.input = Split {
|
||||
self.input = Split({
|
||||
enter = false,
|
||||
relative = {
|
||||
type = "win",
|
||||
@ -1298,7 +1298,7 @@ function Sidebar:create_input()
|
||||
win_options = vim.tbl_deep_extend("force", base_win_options, { signcolumn = "yes" }),
|
||||
position = get_position(),
|
||||
size = get_size(),
|
||||
}
|
||||
})
|
||||
|
||||
local function on_submit()
|
||||
if not vim.g.avante_login then
|
||||
@ -1349,12 +1349,12 @@ function Sidebar:create_input()
|
||||
self.registered_cmp = true
|
||||
cmp.register_source("avante_commands", require("cmp_avante.commands").new(self))
|
||||
end
|
||||
cmp.setup.buffer {
|
||||
cmp.setup.buffer({
|
||||
enabled = true,
|
||||
sources = {
|
||||
{ name = "avante_commands" },
|
||||
},
|
||||
}
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
@ -1495,7 +1495,7 @@ function Sidebar:render()
|
||||
return math.max(1, api.nvim_win_get_width(self.code.winid))
|
||||
end
|
||||
|
||||
self.result = Split {
|
||||
self.result = Split({
|
||||
enter = false,
|
||||
relative = "editor",
|
||||
position = get_position(),
|
||||
@ -1511,7 +1511,7 @@ function Sidebar:render()
|
||||
width = get_width(),
|
||||
height = get_height(),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
self.result:mount()
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
local Utils = require "avante.utils"
|
||||
local Llm = require "avante.llm"
|
||||
local Highlights = require "avante.highlights"
|
||||
local Config = require "avante.config"
|
||||
local Utils = require("avante.utils")
|
||||
local Llm = require("avante.llm")
|
||||
local Highlights = require("avante.highlights")
|
||||
local Config = require("avante.config")
|
||||
local api = vim.api
|
||||
local fn = vim.fn
|
||||
|
||||
local SUGGESTION_NS = api.nvim_create_namespace "avante_suggestion"
|
||||
local SUGGESTION_NS = api.nvim_create_namespace("avante_suggestion")
|
||||
|
||||
---@class avante.SuggestionItem
|
||||
---@field content string
|
||||
@ -87,7 +87,7 @@ function Suggestion:setup_mappings()
|
||||
end
|
||||
|
||||
function Suggestion:suggest()
|
||||
Utils.debug "suggesting"
|
||||
Utils.debug("suggesting")
|
||||
|
||||
local ctx = self:ctx()
|
||||
local doc = Utils.get_doc()
|
||||
@ -100,7 +100,7 @@ function Suggestion:suggest()
|
||||
|
||||
local full_response = ""
|
||||
|
||||
Llm.stream {
|
||||
Llm.stream({
|
||||
bufnr = bufnr,
|
||||
file_content = code_content,
|
||||
code_lang = filetype,
|
||||
@ -132,13 +132,13 @@ function Suggestion:suggest()
|
||||
ctx.current_suggestion_idx = 1
|
||||
self:show()
|
||||
end,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
function Suggestion:show()
|
||||
self:hide()
|
||||
|
||||
if not fn.mode():match "^[iR]" then return end
|
||||
if not fn.mode():match("^[iR]") then return end
|
||||
|
||||
local ctx = self:ctx()
|
||||
local suggestion = ctx.suggestions[ctx.current_suggestion_idx]
|
||||
@ -332,7 +332,7 @@ function Suggestion:setup_autocmds()
|
||||
api.nvim_create_autocmd("BufEnter", {
|
||||
group = self.augroup,
|
||||
callback = function()
|
||||
if fn.mode():match "^[iR]" then suggest_callback() end
|
||||
if fn.mode():match("^[iR]") then suggest_callback() end
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
local Utils = require "avante.utils"
|
||||
local Utils = require("avante.utils")
|
||||
|
||||
---@class AvanteTokenizer
|
||||
---@field from_pretrained fun(model: string): nil
|
||||
@ -19,7 +19,7 @@ M.setup = function(model)
|
||||
core.from_pretrained(model)
|
||||
end, 1000)
|
||||
|
||||
local HF_TOKEN = os.getenv "HF_TOKEN"
|
||||
local HF_TOKEN = os.getenv("HF_TOKEN")
|
||||
if HF_TOKEN == nil and model ~= "gpt-4o" then
|
||||
Utils.warn(
|
||||
"Please set HF_TOKEN environment variable to use HuggingFace tokenizer if " .. model .. " is gated",
|
||||
|
@ -27,7 +27,7 @@ M.has = function(plugin)
|
||||
return package.loaded[plugin] ~= nil
|
||||
end
|
||||
|
||||
M.is_win = function() return jit.os:find "Windows" ~= nil end
|
||||
M.is_win = function() return jit.os:find("Windows") ~= nil end
|
||||
|
||||
---@return "linux" | "darwin" | "windows"
|
||||
M.get_os_name = function()
|
||||
@ -52,12 +52,12 @@ M.shell_run = function(input_cmd)
|
||||
local cmd
|
||||
|
||||
-- powershell then we can just run the cmd
|
||||
if shell:match "powershell" or shell:match "pwsh" then
|
||||
if shell:match("powershell") or shell:match("pwsh") then
|
||||
cmd = input_cmd
|
||||
elseif vim.fn.has "wsl" > 0 then
|
||||
elseif vim.fn.has("wsl") > 0 then
|
||||
-- wsl: powershell.exe -Command 'command "/path"'
|
||||
cmd = "powershell.exe -NoProfile -Command '" .. input_cmd:gsub("'", '"') .. "'"
|
||||
elseif vim.fn.has "win32" > 0 then
|
||||
elseif vim.fn.has("win32") > 0 then
|
||||
cmd = 'powershell.exe -NoProfile -Command "' .. input_cmd:gsub('"', "'") .. '"'
|
||||
else
|
||||
-- linux and macos we wil just do sh -c
|
||||
@ -166,13 +166,13 @@ end
|
||||
---Get the selected content and range in Visual mode
|
||||
---@return avante.SelectionResult | nil Selected content and range
|
||||
function M.get_visual_selection_and_range()
|
||||
local Range = require "avante.range"
|
||||
local SelectionResult = require "avante.selection_result"
|
||||
local Range = require("avante.range")
|
||||
local SelectionResult = require("avante.selection_result")
|
||||
|
||||
if not M.in_visual_mode() then return nil end
|
||||
-- Get the start and end positions of Visual mode
|
||||
local start_pos = vim.fn.getpos "v"
|
||||
local end_pos = vim.fn.getpos "."
|
||||
local start_pos = vim.fn.getpos("v")
|
||||
local end_pos = vim.fn.getpos(".")
|
||||
-- Get the start and end line and column numbers
|
||||
local start_line = start_pos[2]
|
||||
local start_col = start_pos[3]
|
||||
@ -276,14 +276,14 @@ function M.notify(msg, opts)
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
if opts.stacktrace then
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
msg = msg .. M.pretty_trace { level = opts.stacklevel or 2 }
|
||||
msg = msg .. M.pretty_trace({ level = opts.stacklevel or 2 })
|
||||
end
|
||||
local lang = opts.lang or "markdown"
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
local n = opts.once and vim.notify_once or vim.notify
|
||||
n(msg, opts.level or vim.log.levels.INFO, {
|
||||
on_open = function(win)
|
||||
local ok = pcall(function() vim.treesitter.language.add "markdown" end)
|
||||
local ok = pcall(function() vim.treesitter.language.add("markdown") end)
|
||||
if not ok then pcall(require, "nvim-treesitter") end
|
||||
vim.wo[win].conceallevel = 3
|
||||
vim.wo[win].concealcursor = ""
|
||||
@ -374,7 +374,7 @@ function M.unlock_buf(bufnr)
|
||||
end
|
||||
|
||||
function M.lock_buf(bufnr)
|
||||
vim.cmd "stopinsert"
|
||||
vim.cmd("stopinsert")
|
||||
vim.bo[bufnr].modified = false
|
||||
vim.bo[bufnr].modifiable = false
|
||||
end
|
||||
@ -421,7 +421,7 @@ function M.is_sidebar_buffer(bufnr)
|
||||
return v == true
|
||||
end
|
||||
|
||||
function M.trim_spaces(s) return s:match "^%s*(.-)%s*$" end
|
||||
function M.trim_spaces(s) return s:match("^%s*(.-)%s*$") end
|
||||
|
||||
function M.fallback(v, default_value) return type(v) == "nil" and default_value or v end
|
||||
|
||||
@ -441,7 +441,7 @@ end
|
||||
|
||||
---@param code string
|
||||
---@return string
|
||||
function M.get_indentation(code) return code:match "^%s*" or "" end
|
||||
function M.get_indentation(code) return code:match("^%s*") or "" end
|
||||
|
||||
--- remove indentation from code: spaces or tabs
|
||||
function M.remove_indentation(code) return code:gsub("^%s*", "") end
|
||||
@ -494,7 +494,7 @@ function M.trim_all_line_numbers(content)
|
||||
local new_line = M.trim_line_number(line)
|
||||
return new_line
|
||||
end)
|
||||
:join "\n"
|
||||
:join("\n")
|
||||
end
|
||||
|
||||
function M.debounce(func, delay)
|
||||
|
@ -1,5 +1,5 @@
|
||||
-- COPIED and MODIFIED from https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/root.lua
|
||||
local Utils = require "avante.utils"
|
||||
local Utils = require("avante.utils")
|
||||
|
||||
---@class avante.utils.root
|
||||
---@overload fun(): string
|
||||
@ -27,7 +27,7 @@ function M.detectors.lsp(buf)
|
||||
local bufpath = M.bufpath(buf)
|
||||
if not bufpath then return {} end
|
||||
local roots = {} ---@type string[]
|
||||
for _, client in pairs(Utils.lsp.get_clients { bufnr = buf }) do
|
||||
for _, client in pairs(Utils.lsp.get_clients({ bufnr = buf })) do
|
||||
local workspace = client.config.workspace_folders
|
||||
for _, ws in pairs(workspace or {}) do
|
||||
roots[#roots + 1] = vim.uri_to_fname(ws.uri)
|
||||
@ -115,7 +115,7 @@ function M.get(opts)
|
||||
local buf = opts.buf or vim.api.nvim_get_current_buf()
|
||||
local ret = M.cache[buf]
|
||||
if not ret then
|
||||
local roots = M.detect { all = false, buf = buf }
|
||||
local roots = M.detect({ all = false, buf = buf })
|
||||
ret = roots[1] and roots[1].paths[1] or vim.uv.cwd()
|
||||
M.cache[buf] = ret
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
--Taken from https://github.com/jackMort/ChatGPT.nvim/blob/main/lua/chatgpt/flows/chat/tokens.lua
|
||||
local Tokenizer = require "avante.tokenizers"
|
||||
local Tokenizer = require("avante.tokenizers")
|
||||
|
||||
---@class avante.utils.tokens
|
||||
local Tokens = {}
|
||||
@ -17,7 +17,7 @@ function Tokens.calculate_tokens(text)
|
||||
|
||||
local tokens = 0
|
||||
local current_token = ""
|
||||
for char in text:gmatch "." do
|
||||
for char in text:gmatch(".") do
|
||||
if char == " " or char == "\n" then
|
||||
if current_token ~= "" then
|
||||
tokens = tokens + 1
|
||||
|
@ -33,10 +33,10 @@ function source:complete(_, callback)
|
||||
})
|
||||
end
|
||||
|
||||
callback {
|
||||
callback({
|
||||
items = items,
|
||||
isIncomplete = false,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
return source
|
||||
|
@ -1,17 +1,17 @@
|
||||
if vim.fn.has "nvim-0.10" == 0 then
|
||||
if vim.fn.has("nvim-0.10") == 0 then
|
||||
vim.api.nvim_echo({
|
||||
{ "Avante requires at least nvim-0.10", "ErrorMsg" },
|
||||
{ "Please upgrade your neovim version", "WarningMsg" },
|
||||
{ "Press any key to exit", "ErrorMsg" },
|
||||
}, true, {})
|
||||
vim.fn.getchar()
|
||||
vim.cmd [[quit]]
|
||||
vim.cmd([[quit]])
|
||||
end
|
||||
|
||||
--- 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 Clipboard = require("avante.clipboard")
|
||||
local Config = require("avante.config")
|
||||
|
||||
if Config.support_paste_image(true) then
|
||||
vim.paste = (function(overriden)
|
||||
|
@ -1,6 +1,5 @@
|
||||
indent_type = "Spaces"
|
||||
indent_width = 2
|
||||
no_call_parentheses = true
|
||||
column_width = 119
|
||||
line_endings = "Unix"
|
||||
quote_style = "AutoPreferDouble"
|
||||
|
Loading…
x
Reference in New Issue
Block a user