Skip to content

Commit 067de70

Browse files
committed
refactor(config): split config into static and shared parts properly
Split the plugin configuration into two parts: - Static config that can only be set via setup() - Shared config that can be passed as runtime parameters to functions This improves the configuration management by clearly separating configuration parameters that should be set only once during setup from those that can be modified during runtime. Also renamed no_chat option to headless for better clarity.
1 parent b7c4d3b commit 067de70

5 files changed

Lines changed: 168 additions & 178 deletions

File tree

README.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -420,34 +420,16 @@ Also see [here](/lua/CopilotChat/config.lua):
420420

421421
```lua
422422
{
423-
debug = false, -- Enable debug logging (same as 'log_level = 'debug')
424-
log_level = 'info', -- Log level to use, 'trace', 'debug', 'info', 'warn', 'error', 'fatal'
425-
proxy = nil, -- [protocol://]host[:port] Use this proxy
426-
allow_insecure = false, -- Allow insecure server connections
423+
424+
-- Shared config starts here (can be passed to functions at runtime)
427425

428426
system_prompt = prompts.COPILOT_INSTRUCTIONS, -- System prompt to use (can be specified manually in prompt via /).
429427
model = 'gpt-4o', -- Default model to use, see ':CopilotChatModels' for available models (can be specified manually in prompt via $).
430428
agent = 'copilot', -- Default agent to use, see ':CopilotChatAgents' for available agents (can be specified manually in prompt via @).
431429
context = nil, -- Default context or array of contexts to use (can be specified manually in prompt via #).
432430
temperature = 0.1, -- GPT result temperature
433431

434-
question_header = '## User ', -- Header to use for user questions
435-
answer_header = '## Copilot ', -- Header to use for AI answers
436-
error_header = '## Error ', -- Header to use for errors
437-
separator = '───', -- Separator to use in chat
438-
439-
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)
440-
show_folds = true, -- Shows folds for sections in chat
441-
show_help = true, -- Shows help message as virtual lines when waiting for user input
442-
auto_follow_cursor = true, -- Auto-follow cursor in chat
443-
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
444-
insert_at_end = false, -- Move cursor to end of buffer when inserting text
445-
clear_chat_on_new_prompt = false, -- Clears chat on every new prompt
446-
highlight_selection = true, -- Highlight selection
447-
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
448-
449-
history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
450-
no_chat = false, -- Do not write to chat buffer and use history(useful for using callback for custom processing)
432+
headless = false, -- Do not write to chat buffer and use history(useful for using callback for custom processing)
451433
callback = nil, -- Callback to use when ask response is received
452434

453435
-- default selection
@@ -470,6 +452,30 @@ Also see [here](/lua/CopilotChat/config.lua):
470452
zindex = 1, -- determines if window is on top or below other floating windows
471453
},
472454

455+
-- Static config starts here (can be configured only via setup function)
456+
457+
debug = false, -- Enable debug logging (same as 'log_level = 'debug')
458+
log_level = 'info', -- Log level to use, 'trace', 'debug', 'info', 'warn', 'error', 'fatal'
459+
proxy = nil, -- [protocol://]host[:port] Use this proxy
460+
allow_insecure = false, -- Allow insecure server connections
461+
history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
462+
463+
question_header = '## User ', -- Header to use for user questions
464+
answer_header = '## Copilot ', -- Header to use for AI answers
465+
error_header = '## Error ', -- Header to use for errors
466+
separator = '───', -- Separator to use in chat
467+
468+
show_folds = true, -- Shows folds for sections in chat
469+
show_help = true, -- Shows help message as virtual lines when waiting for user input
470+
highlight_selection = true, -- Highlight selection
471+
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
472+
473+
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)
474+
auto_follow_cursor = true, -- Auto-follow cursor in chat
475+
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
476+
insert_at_end = false, -- Move cursor to end of buffer when inserting text
477+
clear_chat_on_new_prompt = false, -- Clears chat on every new prompt
478+
473479
-- default contexts
474480
contexts = {
475481
buffer = {

lua/CopilotChat/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function M.help_actions()
1313
end
1414

1515
--- User prompt actions
16-
---@param config CopilotChat.config?: The chat configuration
16+
---@param config CopilotChat.config.shared?: The chat configuration
1717
---@return CopilotChat.integrations.actions?: The prompt actions
1818
function M.prompt_actions(config)
1919
local actions = {}

lua/CopilotChat/config.lua

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,7 @@ local utils = require('CopilotChat.utils')
7474
---@field agent string?
7575
---@field context string|table<string>|nil
7676
---@field temperature number?
77-
---@field question_header string?
78-
---@field answer_header string?
79-
---@field error_header string?
80-
---@field separator string?
81-
---@field show_folds boolean?
82-
---@field show_help boolean?
83-
---@field auto_follow_cursor boolean?
84-
---@field auto_insert_mode boolean?
85-
---@field clear_chat_on_new_prompt boolean?
86-
---@field highlight_selection boolean?
87-
---@field highlight_headers boolean?
88-
---@field no_chat boolean?
77+
---@field headless boolean?
8978
---@field callback fun(response: string, source: CopilotChat.config.source)?
9079
---@field selection nil|fun(source: CopilotChat.config.source):CopilotChat.config.selection?
9180
---@field window CopilotChat.config.window?
@@ -96,40 +85,34 @@ local utils = require('CopilotChat.utils')
9685
---@field log_level string?
9786
---@field proxy string?
9887
---@field allow_insecure boolean?
99-
---@field chat_autocomplete boolean?
10088
---@field history_path string?
89+
---@field question_header string?
90+
---@field answer_header string?
91+
---@field error_header string?
92+
---@field separator string?
93+
---@field show_folds boolean?
94+
---@field show_help boolean?
95+
---@field highlight_selection boolean?
96+
---@field highlight_headers boolean?
97+
---@field chat_autocomplete boolean?
98+
---@field auto_follow_cursor boolean?
99+
---@field auto_insert_mode boolean?
100+
---@field insert_at_end boolean?
101+
---@field clear_chat_on_new_prompt boolean?
101102
---@field contexts table<string, CopilotChat.config.context>?
102103
---@field prompts table<string, CopilotChat.config.prompt|string>?
103104
---@field mappings CopilotChat.config.mappings?
104105
return {
105-
debug = false, -- Enable debug logging (same as 'log_level = 'debug')
106-
log_level = 'info', -- Log level to use, 'trace', 'debug', 'info', 'warn', 'error', 'fatal'
107-
proxy = nil, -- [protocol://]host[:port] Use this proxy
108-
allow_insecure = false, -- Allow insecure server connections
106+
107+
-- Shared config starts here (can be passed to functions at runtime)
109108

110109
system_prompt = prompts.COPILOT_INSTRUCTIONS, -- System prompt to use (can be specified manually in prompt via /).
111110
model = 'gpt-4o', -- Default model to use, see ':CopilotChatModels' for available models (can be specified manually in prompt via $).
112111
agent = 'copilot', -- Default agent to use, see ':CopilotChatAgents' for available agents (can be specified manually in prompt via @).
113112
context = nil, -- Default context or array of contexts to use (can be specified manually in prompt via #).
114113
temperature = 0.1, -- GPT result temperature
115114

116-
question_header = '## User ', -- Header to use for user questions
117-
answer_header = '## Copilot ', -- Header to use for AI answers
118-
error_header = '## Error ', -- Header to use for errors
119-
separator = '───', -- Separator to use in chat
120-
121-
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)
122-
show_folds = true, -- Shows folds for sections in chat
123-
show_help = true, -- Shows help message as virtual lines when waiting for user input
124-
auto_follow_cursor = true, -- Auto-follow cursor in chat
125-
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
126-
insert_at_end = false, -- Move cursor to end of buffer when inserting text
127-
clear_chat_on_new_prompt = false, -- Clears chat on every new prompt
128-
highlight_selection = true, -- Highlight selection
129-
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
130-
131-
history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
132-
no_chat = false, -- Do not write to chat buffer and use history(useful for using callback for custom processing)
115+
headless = false, -- Do not write to chat buffer and use history(useful for using callback for custom processing)
133116
callback = nil, -- Callback to use when ask response is received
134117

135118
-- default selection
@@ -152,6 +135,30 @@ return {
152135
zindex = 1, -- determines if window is on top or below other floating windows
153136
},
154137

138+
-- Static config starts here (can be configured only via setup function)
139+
140+
debug = false, -- Enable debug logging (same as 'log_level = 'debug')
141+
log_level = 'info', -- Log level to use, 'trace', 'debug', 'info', 'warn', 'error', 'fatal'
142+
proxy = nil, -- [protocol://]host[:port] Use this proxy
143+
allow_insecure = false, -- Allow insecure server connections
144+
history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
145+
146+
question_header = '## User ', -- Header to use for user questions
147+
answer_header = '## Copilot ', -- Header to use for AI answers
148+
error_header = '## Error ', -- Header to use for errors
149+
separator = '───', -- Separator to use in chat
150+
151+
show_folds = true, -- Shows folds for sections in chat
152+
show_help = true, -- Shows help message as virtual lines when waiting for user input
153+
highlight_selection = true, -- Highlight selection
154+
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
155+
156+
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)
157+
auto_follow_cursor = true, -- Auto-follow cursor in chat
158+
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
159+
insert_at_end = false, -- Move cursor to end of buffer when inserting text
160+
clear_chat_on_new_prompt = false, -- Clears chat on every new prompt
161+
155162
-- default contexts
156163
contexts = {
157164
buffer = {

0 commit comments

Comments
 (0)