chore: run stylua [generated] (#460)
* chore: add stylua Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: running stylua Signed-off-by: Aaron Pham <contact@aarnphm.xyz> --------- Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
@@ -10,9 +10,7 @@ local M = {}
|
||||
setmetatable(M, {
|
||||
__index = function(t, k)
|
||||
local ok, lazyutil = pcall(require, "lazy.core.util")
|
||||
if ok and lazyutil[k] then
|
||||
return lazyutil[k]
|
||||
end
|
||||
if ok and lazyutil[k] then return lazyutil[k] end
|
||||
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
t[k] = require("avante.utils." .. k)
|
||||
@@ -25,15 +23,11 @@ setmetatable(M, {
|
||||
---@return boolean
|
||||
M.has = function(plugin)
|
||||
local ok, LazyConfig = pcall(require, "lazy.core.config")
|
||||
if ok then
|
||||
return LazyConfig.plugins[plugin] ~= nil
|
||||
end
|
||||
if ok then return LazyConfig.plugins[plugin] ~= nil end
|
||||
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()
|
||||
@@ -58,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
|
||||
@@ -138,9 +132,7 @@ M.safe_keymap_set = function(mode, lhs, rhs, opts)
|
||||
---@cast modes -string
|
||||
|
||||
---@param m string
|
||||
modes = vim.tbl_filter(function(m)
|
||||
return not (Keys.have and Keys:have(lhs, m))
|
||||
end, modes)
|
||||
modes = vim.tbl_filter(function(m) return not (Keys.have and Keys:have(lhs, m)) end, modes)
|
||||
|
||||
-- don't create keymap if a lazy keys handler exists
|
||||
if #modes > 0 then
|
||||
@@ -157,16 +149,12 @@ end
|
||||
---@param str string
|
||||
---@param opts? {suffix?: string, prefix?: string}
|
||||
function M.trim(str, opts)
|
||||
if not opts then
|
||||
return str
|
||||
end
|
||||
if not opts then return str end
|
||||
local res = str
|
||||
if opts.suffix then
|
||||
res = str:sub(#str - #opts.suffix + 1) == opts.suffix and str:sub(1, #str - #opts.suffix) or str
|
||||
end
|
||||
if opts.prefix then
|
||||
res = str:sub(1, #opts.prefix) == opts.prefix and str:sub(#opts.prefix + 1) or str
|
||||
end
|
||||
if opts.prefix then res = str:sub(1, #opts.prefix) == opts.prefix and str:sub(#opts.prefix + 1) or str end
|
||||
return res
|
||||
end
|
||||
|
||||
@@ -178,15 +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
|
||||
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]
|
||||
@@ -219,9 +205,7 @@ function M.get_visual_selection_and_range()
|
||||
content = lines
|
||||
end
|
||||
end
|
||||
if not content then
|
||||
return nil
|
||||
end
|
||||
if not content then return nil end
|
||||
-- Return the selected content and range
|
||||
return SelectionResult.new(content, range)
|
||||
end
|
||||
@@ -231,16 +215,12 @@ end
|
||||
---@param end_ integer
|
||||
---@param buf integer?
|
||||
---@return string[]
|
||||
function M.get_buf_lines(start, end_, buf)
|
||||
return api.nvim_buf_get_lines(buf or 0, start, end_, false)
|
||||
end
|
||||
function M.get_buf_lines(start, end_, buf) return api.nvim_buf_get_lines(buf or 0, start, end_, false) end
|
||||
|
||||
---Get cursor row and column as (1, 0) based
|
||||
---@param win_id integer?
|
||||
---@return integer, integer
|
||||
function M.get_cursor_pos(win_id)
|
||||
return unpack(api.nvim_win_get_cursor(win_id or 0))
|
||||
end
|
||||
function M.get_cursor_pos(win_id) return unpack(api.nvim_win_get_cursor(win_id or 0)) end
|
||||
|
||||
---Check if the buffer is likely to have actionable conflict markers
|
||||
---@param bufnr integer?
|
||||
@@ -253,9 +233,7 @@ end
|
||||
---@param name string?
|
||||
---@return table<string, string>
|
||||
function M.get_hl(name)
|
||||
if not name then
|
||||
return {}
|
||||
end
|
||||
if not name then return {} end
|
||||
return api.nvim_get_hl(0, { name = name })
|
||||
end
|
||||
|
||||
@@ -278,9 +256,7 @@ end
|
||||
function M.norm(path)
|
||||
if path:sub(1, 1) == "~" then
|
||||
local home = vim.uv.os_homedir()
|
||||
if home:sub(-1) == "\\" or home:sub(-1) == "/" then
|
||||
home = home:sub(1, -2)
|
||||
end
|
||||
if home:sub(-1) == "\\" or home:sub(-1) == "/" then home = home:sub(1, -2) end
|
||||
path = home .. path:sub(2)
|
||||
end
|
||||
path = path:gsub("\\", "/"):gsub("/+", "/")
|
||||
@@ -290,38 +266,25 @@ end
|
||||
---@param msg string|string[]
|
||||
---@param opts? LazyNotifyOpts
|
||||
function M.notify(msg, opts)
|
||||
if vim.in_fast_event() then
|
||||
return vim.schedule(function()
|
||||
M.notify(msg, opts)
|
||||
end)
|
||||
end
|
||||
if vim.in_fast_event() then return vim.schedule(function() M.notify(msg, opts) end) end
|
||||
|
||||
opts = opts or {}
|
||||
if type(msg) == "table" then
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
msg = table.concat(
|
||||
vim.tbl_filter(function(line)
|
||||
return line or false
|
||||
end, msg),
|
||||
"\n"
|
||||
)
|
||||
msg = table.concat(vim.tbl_filter(function(line) return line or false end, msg), "\n")
|
||||
end
|
||||
---@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)
|
||||
if not ok then
|
||||
pcall(require, "nvim-treesitter")
|
||||
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 = ""
|
||||
vim.wo[win].spell = false
|
||||
@@ -354,9 +317,7 @@ end
|
||||
---@param msg string|string[]
|
||||
---@param opts? LazyNotifyOpts
|
||||
function M.warn(msg, opts)
|
||||
if require("avante.config").options.silent_warning then
|
||||
return
|
||||
end
|
||||
if require("avante.config").options.silent_warning then return end
|
||||
|
||||
opts = opts or {}
|
||||
opts.level = vim.log.levels.WARN
|
||||
@@ -366,13 +327,9 @@ end
|
||||
---@param msg string|table
|
||||
---@param opts? LazyNotifyOpts
|
||||
function M.debug(msg, opts)
|
||||
if not require("avante.config").options.debug then
|
||||
return
|
||||
end
|
||||
if not require("avante.config").options.debug then return end
|
||||
opts = opts or {}
|
||||
if opts.title then
|
||||
opts.title = "avante.nvim: " .. opts.title
|
||||
end
|
||||
if opts.title then opts.title = "avante.nvim: " .. opts.title end
|
||||
if type(msg) == "string" then
|
||||
M.notify(msg, opts)
|
||||
else
|
||||
@@ -383,9 +340,7 @@ end
|
||||
|
||||
function M.tbl_indexof(tbl, value)
|
||||
for i, v in ipairs(tbl) do
|
||||
if v == value then
|
||||
return i
|
||||
end
|
||||
if v == value then return i end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
@@ -396,9 +351,7 @@ function M.update_win_options(winid, opt_name, key, value)
|
||||
if cur_opt_value:find(key .. ":") then
|
||||
cur_opt_value = cur_opt_value:gsub(key .. ":[^,]*", key .. ":" .. value)
|
||||
else
|
||||
if #cur_opt_value > 0 then
|
||||
cur_opt_value = cur_opt_value .. ","
|
||||
end
|
||||
if #cur_opt_value > 0 then cur_opt_value = cur_opt_value .. "," end
|
||||
cur_opt_value = cur_opt_value .. key .. ":" .. value
|
||||
end
|
||||
|
||||
@@ -407,15 +360,11 @@ end
|
||||
|
||||
function M.get_win_options(winid, opt_name, key)
|
||||
local cur_opt_value = api.nvim_get_option_value(opt_name, { win = winid })
|
||||
if not cur_opt_value then
|
||||
return
|
||||
end
|
||||
if not cur_opt_value then return end
|
||||
local pieces = vim.split(cur_opt_value, ",")
|
||||
for _, piece in ipairs(pieces) do
|
||||
local kv_pair = vim.split(piece, ":")
|
||||
if kv_pair[1] == key then
|
||||
return kv_pair[2]
|
||||
end
|
||||
if kv_pair[1] == key then return kv_pair[2] end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -425,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
|
||||
@@ -453,14 +402,10 @@ end
|
||||
M.buf_list_wins = function(bufnr)
|
||||
local wins = {}
|
||||
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = api.nvim_get_current_buf()
|
||||
end
|
||||
if not bufnr or bufnr == 0 then bufnr = api.nvim_get_current_buf() end
|
||||
|
||||
for _, winnr in ipairs(api.nvim_list_wins()) do
|
||||
if api.nvim_win_is_valid(winnr) and api.nvim_win_get_buf(winnr) == bufnr then
|
||||
table.insert(wins, winnr)
|
||||
end
|
||||
if api.nvim_win_is_valid(winnr) and api.nvim_win_get_buf(winnr) == bufnr then table.insert(wins, winnr) end
|
||||
end
|
||||
|
||||
return wins
|
||||
@@ -468,25 +413,17 @@ end
|
||||
|
||||
local sidebar_buffer_var_name = "is_avante_sidebar_buffer"
|
||||
|
||||
function M.mark_as_sidebar_buffer(bufnr)
|
||||
api.nvim_buf_set_var(bufnr, sidebar_buffer_var_name, true)
|
||||
end
|
||||
function M.mark_as_sidebar_buffer(bufnr) api.nvim_buf_set_var(bufnr, sidebar_buffer_var_name, true) end
|
||||
|
||||
function M.is_sidebar_buffer(bufnr)
|
||||
local ok, v = pcall(api.nvim_buf_get_var, bufnr, sidebar_buffer_var_name)
|
||||
if not ok then
|
||||
return false
|
||||
end
|
||||
if not ok then return false end
|
||||
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
|
||||
function M.fallback(v, default_value) return type(v) == "nil" and default_value or v end
|
||||
|
||||
-- luacheck: push no max comment line length
|
||||
---@param type_name "'nil'" | "'number'" | "'string'" | "'boolean'" | "'table'" | "'function'" | "'thread'" | "'userdata'" | "'list'" | '"map"'
|
||||
@@ -494,13 +431,9 @@ end
|
||||
function M.is_type(type_name, v)
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
local islist = vim.islist or vim.tbl_islist
|
||||
if type_name == "list" then
|
||||
return islist(v)
|
||||
end
|
||||
if type_name == "list" then return islist(v) end
|
||||
|
||||
if type_name == "map" then
|
||||
return type(v) == "table" and not islist(v)
|
||||
end
|
||||
if type_name == "map" then return type(v) == "table" and not islist(v) end
|
||||
|
||||
return type(v) == type_name
|
||||
end
|
||||
@@ -508,20 +441,14 @@ 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
|
||||
function M.remove_indentation(code) return code:gsub("^%s*", "") end
|
||||
|
||||
local function relative_path(absolute)
|
||||
local relative = fn.fnamemodify(absolute, ":.")
|
||||
if string.sub(relative, 0, 1) == "/" then
|
||||
return fn.fnamemodify(absolute, ":t")
|
||||
end
|
||||
if string.sub(relative, 0, 1) == "/" then return fn.fnamemodify(absolute, ":t") end
|
||||
return relative
|
||||
end
|
||||
|
||||
@@ -558,9 +485,7 @@ function M.prepend_line_number(content, start_line)
|
||||
return table.concat(result, "\n")
|
||||
end
|
||||
|
||||
function M.trim_line_number(line)
|
||||
return line:gsub("^L%d+: ", "")
|
||||
end
|
||||
function M.trim_line_number(line) return line:gsub("^L%d+: ", "") end
|
||||
|
||||
function M.trim_all_line_numbers(content)
|
||||
return vim
|
||||
@@ -569,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)
|
||||
@@ -578,9 +503,7 @@ function M.debounce(func, delay)
|
||||
return function(...)
|
||||
local args = { ... }
|
||||
|
||||
if timer_id then
|
||||
fn.timer_stop(timer_id)
|
||||
end
|
||||
if timer_id then fn.timer_stop(timer_id) end
|
||||
|
||||
timer_id = fn.timer_start(delay, function()
|
||||
func(unpack(args))
|
||||
|
||||
Reference in New Issue
Block a user