Skip to content

Commit 536c5c6

Browse files
authored
refactor(core): improve config handling and setup logic (#1290)
- Use metatable for lazy config loading in main module - Update setup to merge config values instead of replacing table - Remove unused autocmd trigger for CopilotChatLoaded - Set default separator directly when empty
1 parent 6eb4d81 commit 536c5c6

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

lua/CopilotChat/init.lua

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ local BLOCK_OUTPUT_FORMAT = '```%s\n%s\n```'
1515
---@class CopilotChat
1616
---@field config CopilotChat.config.Config
1717
---@field chat CopilotChat.ui.chat.Chat
18-
local M = {}
18+
local M = setmetatable({}, {
19+
__index = function(t, key)
20+
if key == 'config' then
21+
return require('CopilotChat.config')
22+
end
23+
return rawget(t, key)
24+
end,
25+
})
1926

2027
--- @class CopilotChat.source
2128
--- @field bufnr number
@@ -1187,8 +1194,10 @@ end
11871194
--- Set up the plugin
11881195
---@param config CopilotChat.config.Config?
11891196
function M.setup(config)
1190-
local default_config = require('CopilotChat.config')
1191-
M.config = vim.tbl_deep_extend('force', default_config, config or {})
1197+
-- Little bit of update magic
1198+
for k, v in pairs(vim.tbl_deep_extend('force', M.config, config or {})) do
1199+
M.config[k] = v
1200+
end
11921201

11931202
-- Save proxy and insecure settings
11941203
utils.curl_store_args({
@@ -1212,7 +1221,7 @@ function M.setup(config)
12121221
log.warn(
12131222
'Empty separator is not allowed, using default separator instead. Set `separator` in config to change this.'
12141223
)
1215-
M.config.separator = default_config.separator
1224+
M.config.separator = '---'
12161225
end
12171226

12181227
if M.chat then
@@ -1310,8 +1319,6 @@ function M.setup(config)
13101319
end
13111320
end
13121321
end
1313-
1314-
vim.api.nvim_exec_autocmds('User', { pattern = 'CopilotChatLoaded' })
13151322
end
13161323

13171324
return M

0 commit comments

Comments
 (0)