Skip to content

Commit 90ebb50

Browse files
authored
feat(config): support multiple custom instruction files (#1510)
Add `instruction_files` option to configuration, allowing users to specify multiple custom instruction files to be loaded from the current working directory. The prompt resolution logic now iterates over all configured instruction files and includes their contents if present. This makes it easier to manage and extend custom Copilot instructions across different projects.
1 parent 21bdecb commit 90ebb50

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lua/CopilotChat/config.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
---@field log_level 'trace'|'debug'|'info'|'warn'|'error'|'fatal'?
4444
---@field proxy string?
4545
---@field allow_insecure boolean?
46+
---@field instruction_files table<int, string>?
4647
---@field selection 'visual'|'unnamed'|nil
4748
---@field chat_autocomplete boolean?
4849
---@field log_path string?
@@ -105,6 +106,12 @@ return {
105106
proxy = nil, -- [protocol://]host[:port] Use this proxy
106107
allow_insecure = false, -- Allow insecure server connections
107108

109+
-- Instruction files to look for in current working directory
110+
instruction_files = {
111+
'.github/copilot-instructions.md',
112+
'AGENTS.MD',
113+
},
114+
108115
selection = 'visual', -- Selection source
109116
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)
110117

lua/CopilotChat/prompts.lua

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ local WORD_WITH_INPUT_UNQUOTED = WORD .. ':?([^%s`]*)'
1212

1313
--- Find custom instructions in the current working directory.
1414
---@param cwd string
15+
---@param config CopilotChat.config.Config
1516
---@return table
16-
local function find_custom_instructions(cwd)
17+
local function find_custom_instructions(cwd, config)
1718
local out = {}
18-
local copilot_instructions_path = vim.fs.joinpath(cwd, '.github', 'copilot-instructions.md')
19-
local copilot_instructions = files.read_file(copilot_instructions_path)
20-
if copilot_instructions then
21-
table.insert(out, {
22-
filename = copilot_instructions_path,
23-
content = vim.trim(copilot_instructions),
24-
})
19+
local files_to_check = {}
20+
for _, relpath in ipairs(config.instruction_files or {}) do
21+
table.insert(files_to_check, vim.fs.joinpath(cwd, relpath))
22+
end
23+
for _, path in ipairs(files_to_check) do
24+
local content = files.read_file(path)
25+
if content then
26+
table.insert(out, {
27+
filename = path,
28+
content = vim.trim(content),
29+
})
30+
end
2531
end
2632
return out
2733
end
@@ -314,7 +320,7 @@ function M.resolve_prompt(prompt, config)
314320
end
315321

316322
local custom_instructions = vim.trim(require('CopilotChat.instructions.custom_instructions'))
317-
for _, instruction in ipairs(find_custom_instructions(source.cwd())) do
323+
for _, instruction in ipairs(find_custom_instructions(source.cwd(), config)) do
318324
config.system_prompt = vim.trim(config.system_prompt)
319325
.. '\n'
320326
.. custom_instructions:gsub('{FILENAME}', instruction.filename):gsub('{CONTENT}', instruction.content)

0 commit comments

Comments
 (0)