Skip to content

Commit

Permalink
fix(style): add parentheses (yetone#471)
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
  • Loading branch information
aarnphm authored Sep 3, 2024
1 parent 8cc674f commit 0d8098e
Show file tree
Hide file tree
Showing 25 changed files with 213 additions and 214 deletions.
6 changes: 3 additions & 3 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 Down Expand Up @@ -66,7 +66,7 @@ end

return setmetatable(M, {
__index = function(t, k)
local module = require "avante"
local module = require("avante")
---@class AvailableApi: ApiCaller
---@field api? boolean
local has = module[k]
Expand Down
16 changes: 8 additions & 8 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 @@ -19,7 +19,7 @@ local paste_directory = nil
---@return Path
local function get_paste_directory()
if paste_directory then return paste_directory end
paste_directory = Path:new(Config.history.storage_path):joinpath "pasted_images"
paste_directory = Path:new(Config.history.storage_path):joinpath("pasted_images")
return paste_directory
end

Expand All @@ -28,9 +28,9 @@ M.support_paste_image = Config.support_paste_image
M.setup = function()
get_paste_directory()

if not paste_directory:exists() then paste_directory:mkdir { parent = true } end
if not paste_directory:exists() then paste_directory:mkdir({ parent = true }) end

if M.support_paste_image() and ImgClip == nil then ImgClip = require "img-clip" end
if M.support_paste_image() and ImgClip == nil then ImgClip = require("img-clip") end
end

---@param line? string
Expand All @@ -46,7 +46,7 @@ M.paste_image = function(line)
},
}

if vim.fn.has "wsl" > 0 or vim.fn.has "win32" > 0 then opts.use_absolute_path = true end
if vim.fn.has("wsl") > 0 or vim.fn.has("win32") > 0 then opts.use_absolute_path = true end

return ImgClip.paste_image(opts, line)
end
Expand All @@ -65,7 +65,7 @@ M.get_base64_content = function(filepath)
if output.code == 0 then
return output.stdout
else
error "Failed to convert image to base64"
error("Failed to convert image to base64")
end
end

Expand Down
16 changes: 8 additions & 8 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 @@ -214,7 +214,7 @@ function M.setup(opts)
return acc
end)

vim.validate { provider = { M.options.provider, "string", false } }
vim.validate({ provider = { M.options.provider, "string", false } })

M.diff = vim.tbl_deep_extend(
"force",
Expand All @@ -227,14 +227,14 @@ function M.setup(opts)
for k, v in pairs(M.options.vendors) do
M.options.vendors[k] = type(v) == "function" and v() or v
end
vim.validate { vendors = { M.options.vendors, "table", true } }
vim.validate({ vendors = { M.options.vendors, "table", true } })
M.providers = vim.list_extend(M.providers, vim.tbl_keys(M.options.vendors))
end
end

---@param opts? avante.Config
function M.override(opts)
vim.validate { opts = { opts, "table", true } }
vim.validate({ opts = { opts, "table", true } })

M.options = vim.tbl_deep_extend("force", M.options, opts or {})
if not M.options.silent_warning then
Expand All @@ -254,7 +254,7 @@ function M.override(opts)
M.options.vendors[k] = type(v) == "function" and v() or v
if not vim.tbl_contains(M.providers, k) then M.providers = vim.list_extend(M.providers, { k }) end
end
vim.validate { vendors = { M.options.vendors, "table", true } }
vim.validate({ vendors = { M.options.vendors, "table", true } })
end
end

Expand All @@ -269,7 +269,7 @@ M.support_paste_image = function(skip_warning)
skip_warning = skip_warning or M.silent_warning
if skip_warning then return end

return Utils.has "img-clip.nvim" or Utils.has "img-clip"
return Utils.has("img-clip.nvim") or Utils.has("img-clip")
end

M.get_window_width = function() return math.ceil(vim.o.columns * (M.windows.width / 100)) end
Expand Down
34 changes: 17 additions & 17 deletions lua/avante/diff.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local api = vim.api

local Config = require "avante.config"
local Utils = require "avante.utils"
local Highlights = require "avante.highlights"
local Config = require("avante.config")
local Utils = require("avante.utils")
local Highlights = require("avante.highlights")

local H = {}
local M = {}
Expand Down Expand Up @@ -82,8 +82,8 @@ local INCOMING_HL = "AvanteConflictIncoming"
local CURRENT_LABEL_HL = "AvanteConflictCurrentLabel"
local INCOMING_LABEL_HL = "AvanteConflictIncomingLabel"
local PRIORITY = vim.highlight.priorities.user
local NAMESPACE = api.nvim_create_namespace "avante-conflict"
local KEYBINDING_NAMESPACE = api.nvim_create_namespace "avante-conflict-keybinding"
local NAMESPACE = api.nvim_create_namespace("avante-conflict")
local KEYBINDING_NAMESPACE = api.nvim_create_namespace("avante-conflict-keybinding")
local AUGROUP_NAME = "avante_conflicts"

local conflict_start = "^<<<<<<<"
Expand Down Expand Up @@ -354,18 +354,18 @@ H.setup_buffer_mappings = function(bufnr)
---@param desc string
local function opts(desc) return { silent = true, buffer = bufnr, desc = "avante(conflict): " .. desc } end

vim.keymap.set({ "n", "v" }, Config.diff.mappings.ours, function() M.choose "ours" end, opts "choose ours")
vim.keymap.set({ "n", "v" }, Config.diff.mappings.both, function() M.choose "both" end, opts "choose both")
vim.keymap.set({ "n", "v" }, Config.diff.mappings.theirs, function() M.choose "theirs" end, opts "choose theirs")
vim.keymap.set({ "n", "v" }, Config.diff.mappings.ours, function() M.choose("ours") end, opts("choose ours"))
vim.keymap.set({ "n", "v" }, Config.diff.mappings.both, function() M.choose("both") end, opts("choose both"))
vim.keymap.set({ "n", "v" }, Config.diff.mappings.theirs, function() M.choose("theirs") end, opts("choose theirs"))
vim.keymap.set(
{ "n", "v" },
Config.diff.mappings.all_theirs,
function() M.choose "all_theirs" end,
opts "choose all theirs"
function() M.choose("all_theirs") end,
opts("choose all theirs")
)
vim.keymap.set("n", Config.diff.mappings.cursor, function() M.choose "cursor" end, opts "choose under cursor")
vim.keymap.set("n", Config.diff.mappings.prev, function() M.find_prev "ours" end, opts "previous conflict")
vim.keymap.set("n", Config.diff.mappings.next, function() M.find_next "ours" end, opts "next conflict")
vim.keymap.set("n", Config.diff.mappings.cursor, function() M.choose("cursor") end, opts("choose under cursor"))
vim.keymap.set("n", Config.diff.mappings.prev, function() M.find_prev("ours") end, opts("previous conflict"))
vim.keymap.set("n", Config.diff.mappings.next, function() M.find_next("ours") end, opts("next conflict"))

vim.b[bufnr].avante_conflict_mappings_set = true
end
Expand All @@ -390,7 +390,7 @@ function M.setup()
callback = function(ev)
vim.diagnostic.enable(false, { bufnr = ev.buf })
if vim.lsp.inlay_hint then
previous_inlay_enabled = vim.lsp.inlay_hint.is_enabled { bufnr = ev.buf }
previous_inlay_enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = ev.buf })
vim.lsp.inlay_hint.enable(false, { bufnr = ev.buf })
end
H.setup_buffer_mappings(ev.buf)
Expand Down Expand Up @@ -515,7 +515,7 @@ function M.choose(side)
end, 50)
if Config.diff.autojump then
M.find_next(side)
vim.cmd [[normal! zz]]
vim.cmd([[normal! zz]])
end
return
end
Expand Down Expand Up @@ -550,7 +550,7 @@ function M.process_position(bufnr, side, position, enable_autojump)
lines = {}
elseif side == SIDES.CURSOR then
local cursor_line = Utils.get_cursor_pos()
for _, pos in ipairs { SIDES.OURS, SIDES.THEIRS, SIDES.BASE } do
for _, pos in ipairs({ SIDES.OURS, SIDES.THEIRS, SIDES.BASE }) do
local data = position[name_map[pos]] or {}
if data.range_start and data.range_start + 1 <= cursor_line and data.range_end + 1 >= cursor_line then
side = pos
Expand All @@ -572,7 +572,7 @@ function M.process_position(bufnr, side, position, enable_autojump)
parse_buffer(bufnr)
if enable_autojump and Config.diff.autojump then
M.find_next(side)
vim.cmd [[normal! zz]]
vim.cmd([[normal! zz]])
end
end

Expand Down
12 changes: 6 additions & 6 deletions lua/avante/highlights.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local api = vim.api

local Config = require "avante.config"
local bit = require "bit"
local Config = require("avante.config")
local bit = require("bit")
local rshift, band = bit.rshift, bit.band

local Highlights = {
Expand Down Expand Up @@ -29,8 +29,8 @@ local H = {}

local M = {}

M.input_ns = api.nvim_create_namespace "avante_input"
M.hint_ns = api.nvim_create_namespace "avante_hint"
M.input_ns = api.nvim_create_namespace("avante_input")
M.hint_ns = api.nvim_create_namespace("avante_hint")

local function has_set_colors(hl_group)
local hl = api.nvim_get_hl(0, { name = hl_group })
Expand All @@ -46,7 +46,7 @@ M.setup = function()
.iter(Highlights)
:filter(function(k, _)
-- return all uppercase key with underscore or fully uppercase key
return k:match "^%u+_" or k:match "^%u+$"
return k:match("^%u+_") or k:match("^%u+$")
end)
:each(function(_, hl)
if not has_set_colors(hl.name) then
Expand Down Expand Up @@ -113,7 +113,7 @@ setmetatable(M, {
---@param rgb_24bit number 24-bit RGB value
---@return {r: integer, g: integer, b: integer} with keys 'r', 'g', 'b' in [0,255]
H.decode_24bit_rgb = function(rgb_24bit)
vim.validate { rgb_24bit = { rgb_24bit, "n", true } }
vim.validate({ rgb_24bit = { rgb_24bit, "n", true } })
local r = band(rshift(rgb_24bit, 16), 255)
local g = band(rshift(rgb_24bit, 8), 255)
local b = band(rgb_24bit, 255)
Expand Down
48 changes: 24 additions & 24 deletions lua/avante/init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local api = vim.api

local Utils = require "avante.utils"
local Sidebar = require "avante.sidebar"
local Selection = require "avante.selection"
local Suggestion = require "avante.suggestion"
local Config = require "avante.config"
local Diff = require "avante.diff"
local Utils = require("avante.utils")
local Sidebar = require("avante.sidebar")
local Selection = require("avante.selection")
local Suggestion = require("avante.suggestion")
local Config = require("avante.config")
local Diff = require("avante.diff")

---@class Avante
local M = {
Expand Down Expand Up @@ -49,7 +49,7 @@ H.commands = function()
nargs = 1,
desc = "avante: switch provider",
complete = function(_, line, _)
local prefix = line:match "AvanteSwitchProvider%s*(.*)$" or ""
local prefix = line:match("AvanteSwitchProvider%s*(.*)$") or ""
---@param key string
return vim.tbl_filter(function(key) return key:find(prefix, 1, true) == 1 end, Config.providers)
end,
Expand All @@ -64,13 +64,13 @@ H.keymaps = function()
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function() M.toggle.debug() end)
vim.keymap.set("n", "<Plug>(AvanteToggleHint)", function() M.toggle.hint() end)

vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictOurs)", function() Diff.choose "ours" end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictBoth)", function() Diff.choose "both" end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictTheirs)", function() Diff.choose "theirs" end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictAllTheirs)", function() Diff.choose "all_theirs" end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictCursor)", function() Diff.choose "cursor" end)
vim.keymap.set("n", "<Plug>(AvanteConflictNextConflict)", function() Diff.find_next "ours" end)
vim.keymap.set("n", "<Plug>(AvanteConflictPrevConflict)", function() Diff.find_prev "ours" end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictOurs)", function() Diff.choose("ours") end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictBoth)", function() Diff.choose("both") end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictTheirs)", function() Diff.choose("theirs") end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictAllTheirs)", function() Diff.choose("all_theirs") end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictCursor)", function() Diff.choose("cursor") end)
vim.keymap.set("n", "<Plug>(AvanteConflictNextConflict)", function() Diff.find_next("ours") end)
vim.keymap.set("n", "<Plug>(AvanteConflictPrevConflict)", function() Diff.find_prev("ours") end)

if Config.behaviour.auto_set_keymaps then
Utils.safe_keymap_set(
Expand Down Expand Up @@ -194,14 +194,14 @@ H.autocmds = function()
-- automatically setup Avante filetype to markdown
vim.treesitter.language.register("markdown", "Avante")

vim.filetype.add {
vim.filetype.add({
extension = {
["avanterules"] = "jinja",
},
pattern = {
["%.avanterules%.[%w_.-]+"] = "jinja",
},
}
})
end

---@param current boolean? false to disable setting current, otherwise use this to track across tabs.
Expand Down Expand Up @@ -243,17 +243,17 @@ end

M.toggle = { api = true }

M.toggle.debug = H.api(Utils.toggle_wrap {
M.toggle.debug = H.api(Utils.toggle_wrap({
name = "debug",
get = function() return Config.debug end,
set = function(state) Config.override { debug = state } end,
})
set = function(state) Config.override({ debug = state }) end,
}))

M.toggle.hint = H.api(Utils.toggle_wrap {
M.toggle.hint = H.api(Utils.toggle_wrap({
name = "hint",
get = function() return Config.hints.enabled end,
set = function(state) Config.override { hints = { enabled = state } } end,
})
set = function(state) Config.override({ hints = { enabled = state } }) end,
}))

setmetatable(M.toggle, {
__index = M.toggle,
Expand All @@ -273,7 +273,7 @@ setmetatable(M.toggle, {
local function to_windows_path(path)
local winpath = path:gsub("/", "\\")

if winpath:match "^%a:" then winpath = winpath:sub(1, 2):upper() .. winpath:sub(3) end
if winpath:match("^%a:") then winpath = winpath:sub(1, 2):upper() .. winpath:sub(3) end

winpath = winpath:gsub("\\$", "")

Expand All @@ -285,7 +285,7 @@ M.build = H.api(function()
local git_root = vim.fs.find(".git", { path = dirname, upward = true })[1]
local build_directory = git_root and vim.fn.fnamemodify(git_root, ":h") or (dirname .. "/../../")

if not vim.fn.executable "cargo" then error("Building avante.nvim requires cargo to be installed.", 2) end
if not vim.fn.executable("cargo") then error("Building avante.nvim requires cargo to be installed.", 2) end

---@type string[]
local cmd
Expand Down
Loading

0 comments on commit 0d8098e

Please sign in to comment.