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