Skip to content

Commit 5d23329

Browse files
committed
Revert "refactor: Use config from parent instead of duplication"
This reverts commit 312b199.
1 parent 312b199 commit 5d23329

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lua/CopilotChat/config/providers.lua

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
local constants = require('CopilotChat.constants')
22
local notify = require('CopilotChat.notify')
33
local utils = require('CopilotChat.utils')
4-
local config = require('CopilotChat.config')
54
local plenary_utils = require('plenary.async.util')
65
local log = require('plenary.log')
76

87
local EDITOR_VERSION = 'Neovim/' .. vim.version().major .. '.' .. vim.version().minor .. '.' .. vim.version().patch
98

9+
---@class CopilotChat
10+
---@field config CopilotChat.config.Config
11+
---@field chat CopilotChat.ui.chat.Chat
12+
local MC = setmetatable({}, {
13+
__index = function(t, key)
14+
if key == 'config' then
15+
return require('CopilotChat.config')
16+
end
17+
return rawget(t, key)
18+
end,
19+
})
20+
1021
local token_cache = nil
1122
local unsaved_token_cache = {}
1223
local function load_tokens()
@@ -52,7 +63,7 @@ end
5263
---@return string
5364
local function github_device_flow(tag, client_id, scope)
5465
local function request_device_code()
55-
local res = utils.curl_post('https://' .. config.github_instance_url .. '/login/device/code', {
66+
local res = utils.curl_post('https://' .. MC.config.github_instance_url .. '/login/device/code', {
5667
body = {
5768
client_id = client_id,
5869
scope = scope,
@@ -68,7 +79,7 @@ local function github_device_flow(tag, client_id, scope)
6879
while true do
6980
plenary_utils.sleep(interval * 1000)
7081

71-
local res = utils.curl_post('https://' .. config.github_instance_url .. '/login/oauth/access_token', {
82+
local res = utils.curl_post('https://' .. MC.config.github_instance_url .. '/login/oauth/access_token', {
7283
body = {
7384
client_id = client_id,
7485
device_code = device_code,
@@ -148,7 +159,7 @@ local function get_github_copilot_token(tag)
148159
local parsed_data = utils.json_decode(file_data)
149160
if parsed_data then
150161
for key, value in pairs(parsed_data) do
151-
if string.find(key, config.github_instance_url) and value and value.oauth_token then
162+
if string.find(key, MC.config.github_instance_url) and value and value.oauth_token then
152163
return set_token(tag, value.oauth_token, false)
153164
end
154165
end
@@ -175,7 +186,7 @@ local function get_github_models_token(tag)
175186

176187
-- loading token from gh cli if available
177188
if vim.fn.executable('gh') == 0 then
178-
local result = utils.system({ 'gh', 'auth', 'token', '-h', config.github_instance_url })
189+
local result = utils.system({ 'gh', 'auth', 'token', '-h', MC.config.github_instance_url })
179190
if result and result.code == 0 and result.stdout then
180191
local gh_token = vim.trim(result.stdout)
181192
if gh_token ~= '' and not gh_token:find('no oauth token') then
@@ -216,12 +227,12 @@ M.copilot = {
216227
endpoints_api = '',
217228

218229
get_headers = function()
219-
local url = 'https://' .. config.github_instance_api_url .. '/copilot_internal/v2/token'
230+
local url = 'https://' .. MC.config.github_instance_api_url .. '/copilot_internal/v2/token'
220231
log.debug('get headers - get ' .. url)
221232
local response, err = utils.curl_get(url, {
222233
json_response = true,
223234
headers = {
224-
['Authorization'] = 'Token ' .. get_github_copilot_token(config.github_instance_api_url),
235+
['Authorization'] = 'Token ' .. get_github_copilot_token(MC.config.github_instance_api_url),
225236
},
226237
})
227238

@@ -239,7 +250,7 @@ M.copilot = {
239250
)
240251
error(
241252
'get_headers authenticated, but missing key "endpoints.api" in server response. Check log for details: '
242-
.. config.log_path
253+
.. MC.config.log_path
243254
)
244255
end
245256

@@ -253,10 +264,10 @@ M.copilot = {
253264
end,
254265

255266
get_info = function(headers)
256-
local response, err = utils.curl_get('https://' .. config.github_instance_url .. '/copilot_internal/user', {
267+
local response, err = utils.curl_get('https://' .. MC.config.github_instance_url .. '/copilot_internal/user', {
257268
json_response = true,
258269
headers = {
259-
['Authorization'] = 'Token ' .. get_github_copilot_token(config.github_instance_url),
270+
['Authorization'] = 'Token ' .. get_github_copilot_token(MC.config.github_instance_url),
260271
},
261272
})
262273

0 commit comments

Comments
 (0)