fix: Get copilot refresh token asynchronously (#918)

This commit is contained in:
Arkuna 2024-12-01 14:00:42 +08:00 committed by GitHub
parent 71c9a7911b
commit 57311bf8cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -91,7 +91,7 @@ H.refresh_token = function()
not M.state.github_token
or (M.state.github_token.expires_at and M.state.github_token.expires_at < math.floor(os.time()))
then
local response = curl.get(H.chat_auth_url, {
curl.get(H.chat_auth_url, {
headers = {
["Authorization"] = "token " .. M.state.oauth_token,
["Accept"] = "application/json",
@ -99,8 +99,7 @@ H.refresh_token = function()
timeout = Config.copilot.timeout,
proxy = Config.copilot.proxy,
insecure = Config.copilot.allow_insecure,
})
callback = function(response)
if response.status == 200 then
M.state.github_token = vim.json.decode(response.body)
local file = Path:new(copilot_path)
@ -109,6 +108,8 @@ H.refresh_token = function()
else
error("Failed to get success response: " .. vim.inspect(response))
end
end,
})
end
end