Skip to content

Commit

Permalink
chore: run stylua [generated] (yetone#460)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
aarnphm authored Sep 3, 2024
1 parent 4ad9134 commit e8c71d9
Show file tree
Hide file tree
Showing 28 changed files with 611 additions and 1,184 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ stylecheck:
stylua --check lua/

stylefix:
stylua lua/
stylua lua/ plugin/
38 changes: 11 additions & 27 deletions lua/avante/api.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,28 +17,20 @@ local Utils = require("avante.utils")
local M = {}

---@param target Provider
M.switch_provider = function(target)
require("avante.providers").refresh(target)
end
M.switch_provider = function(target) require("avante.providers").refresh(target) end

---@param question? string
M.ask = function(question)
if not require("avante").toggle() then
return false
end
if question == nil or question == "" then
return true
end
if not require("avante").toggle() then return false end
if question == nil or question == "" then return true end
vim.api.nvim_exec_autocmds("User", { pattern = "AvanteInputSubmitted", data = { request = question } })
return true
end

---@param question? string
M.edit = function(question)
local _, selection = require("avante").get()
if not selection then
return
end
if not selection then return end
selection:create_editing_input()
if question ~= nil or question ~= "" then
vim.api.nvim_exec_autocmds("User", { pattern = "AvanteEditSubmitted", data = { request = question } })
Expand All @@ -53,23 +45,15 @@ end

M.refresh = function()
local sidebar = require("avante").get()
if not sidebar then
return
end
if not sidebar:is_open() then
return
end
if not sidebar then return end
if not sidebar:is_open() then return end
local curbuf = vim.api.nvim_get_current_buf()

local focused = sidebar.result.bufnr == curbuf or sidebar.input.bufnr == curbuf
if focused or not sidebar:is_open() then
return
end
if focused or not sidebar:is_open() then return end
local listed = vim.api.nvim_get_option_value("buflisted", { buf = curbuf })

if Utils.is_sidebar_buffer(curbuf) or not listed then
return
end
if Utils.is_sidebar_buffer(curbuf) or not listed then return end

local curwin = vim.api.nvim_get_current_win()

Expand All @@ -81,7 +65,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]
Expand Down
30 changes: 10 additions & 20 deletions lua/avante/clipboard.lua
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -18,10 +18,8 @@ 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")
if paste_directory then return paste_directory end
paste_directory = Path:new(Config.history.storage_path):joinpath "pasted_images"
return paste_directory
end

Expand All @@ -30,21 +28,15 @@ 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
M.paste_image = function(line)
line = line or nil
if not Config.support_paste_image(true) then
return false
end
if not Config.support_paste_image(true) then return false end

local opts = {
dir_path = paste_directory:absolute(),
Expand All @@ -54,9 +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
Expand All @@ -75,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

Expand Down
40 changes: 14 additions & 26 deletions lua/avante/config.lua
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -207,16 +207,14 @@ function M.setup(opts)
end
M.providers = vim
.iter(M.defaults)
:filter(function(_, value)
return type(value) == "table" and value.endpoint ~= nil
end)
:filter(function(_, value) return type(value) == "table" and value.endpoint ~= nil end)
:fold({}, function(acc, k)
acc = vim.list_extend({}, acc)
acc = vim.list_extend(acc, { k })
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",
Expand All @@ -229,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
Expand All @@ -254,41 +252,31 @@ function M.override(opts)
if next(M.options.vendors) ~= nil then
for k, v in pairs(M.options.vendors) do
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
vim.validate({ vendors = { M.options.vendors, "table", true } })
vim.validate { vendors = { M.options.vendors, "table", true } }
end
end

M = setmetatable(M, {
__index = function(_, k)
if M.options[k] then
return M.options[k]
end
if M.options[k] then return M.options[k] end
end,
})

---@param skip_warning? boolean
M.support_paste_image = function(skip_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

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

---@param provider Provider
---@return boolean
M.has_provider = function(provider)
return M.options[provider] ~= nil or M.vendors[provider] ~= nil
end
M.has_provider = function(provider) return M.options[provider] ~= nil or M.vendors[provider] ~= nil end

---get supported providers
---@param provider Provider
Expand Down
Loading

0 comments on commit e8c71d9

Please sign in to comment.