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:
Aaron Pham
2024-09-03 04:19:54 -04:00
committed by GitHub
parent 4ad913435c
commit e8c71d931e
28 changed files with 608 additions and 1181 deletions

View File

@@ -25,12 +25,12 @@
---@field xcode boolean
---@field xcode_chat boolean
local curl = require("plenary.curl")
local curl = require "plenary.curl"
local Config = require("avante.config")
local Path = require("plenary.path")
local Utils = require("avante.utils")
local P = require("avante.providers")
local Config = require "avante.config"
local Path = require "plenary.path"
local Utils = require "avante.utils"
local P = require "avante.providers"
local O = require("avante.providers").openai
local H = {}
@@ -41,29 +41,25 @@ local H = {}
---
---@return string
H.get_oauth_token = function()
local xdg_config = vim.fn.expand("$XDG_CONFIG_HOME")
local xdg_config = vim.fn.expand "$XDG_CONFIG_HOME"
local os_name = Utils.get_os_name()
---@type string
local config_dir
if vim.tbl_contains({ "linux", "darwin" }, os_name) then
config_dir = (xdg_config and vim.fn.isdirectory(xdg_config) > 0) and xdg_config or vim.fn.expand("~/.config")
config_dir = (xdg_config and vim.fn.isdirectory(xdg_config) > 0) and xdg_config or vim.fn.expand "~/.config"
else
config_dir = vim.fn.expand("~/AppData/Local")
config_dir = vim.fn.expand "~/AppData/Local"
end
--- hosts.json (copilot.lua), apps.json (copilot.vim)
---@type Path[]
local paths = vim.iter({ "hosts.json", "apps.json" }):fold({}, function(acc, path)
local yason = Path:new(config_dir):joinpath("github-copilot", path)
if yason:exists() then
table.insert(acc, yason)
end
if yason:exists() then table.insert(acc, yason) end
return acc
end)
if #paths == 0 then
error("You must setup copilot with either copilot.lua or copilot.vim", 2)
end
if #paths == 0 then error("You must setup copilot with either copilot.lua or copilot.vim", 2) end
local yason = paths[1]
return vim
@@ -71,9 +67,7 @@ H.get_oauth_token = function()
---@type table<string, OAuthToken>
vim.json.decode(yason:read())
)
:filter(function(k, _)
return k:match("github.com")
end)
:filter(function(k, _) return k:match "github.com" end)
---@param acc {oauth_token: string}
:fold({}, function(acc, _, v)
acc.oauth_token = v.oauth_token
@@ -83,17 +77,13 @@ H.get_oauth_token = function()
end
H.chat_auth_url = "https://api.github.com/copilot_internal/v2/token"
H.chat_completion_url = function(base_url)
return Utils.trim(base_url, { prefix = "/" }) .. "/chat/completions"
end
H.chat_completion_url = function(base_url) return Utils.trim(base_url, { prefix = "/" }) .. "/chat/completions" end
---@class AvanteProviderFunctor
local M = {}
H.refresh_token = function()
if not M.state then
error("internal initialization error")
end
if not M.state then error "internal initialization error" end
if
not M.state.github_token
@@ -107,14 +97,10 @@ H.refresh_token = function()
timeout = Config.copilot.timeout,
proxy = Config.copilot.proxy,
insecure = Config.copilot.allow_insecure,
on_error = function(err)
error("Failed to get response: " .. vim.inspect(err))
end,
on_error = function(err) error("Failed to get response: " .. vim.inspect(err)) end,
callback = function(output)
M.state.github_token = vim.json.decode(output.body)
if not vim.g.avante_login then
vim.g.avante_login = true
end
if not vim.g.avante_login then vim.g.avante_login = true end
end,
})
end