Skip to content

Commit 73fb30e

Browse files
committed
feat: add remember_as_sticky config option
Add configuration option to control whether model/agent/context are remembered as sticky prompts when asking questions. This provides more control over the persistence behavior. Also added a 'grx' shortcut to clear all sticky prompts and changed the toggle sticky keymap from 'gr' to 'grr' to avoid conflicts.
1 parent 71790ff commit 73fb30e

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ Below are all available configuration options with their default values:
452452
temperature = 0.1, -- GPT result temperature
453453
headless = false, -- Do not write to chat buffer and use history(useful for using callback for custom processing)
454454
callback = nil, -- Callback to use when ask response is received
455+
remember_as_sticky = true, -- Remember model/agent/context as sticky prompts when asking questions
455456

456457
-- default window options
457458
window = {

lua/CopilotChat/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ local select = require('CopilotChat.select')
2222
---@field temperature number?
2323
---@field headless boolean?
2424
---@field callback fun(response: string, source: CopilotChat.source)?
25+
---@field remember_as_sticky boolean?
2526
---@field window CopilotChat.config.window?
2627
---@field show_help boolean?
2728
---@field show_folds boolean?
@@ -65,6 +66,7 @@ return {
6566
temperature = 0.1, -- GPT result temperature
6667
headless = false, -- Do not write to chat buffer and use history(useful for using callback for custom processing)
6768
callback = nil, -- Callback to use when ask response is received
69+
remember_as_sticky = true, -- Remember model/agent/context as sticky prompts when asking questions
6870

6971
-- default window options
7072
window = {

lua/CopilotChat/config/mappings.lua

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ return {
173173
},
174174

175175
toggle_sticky = {
176-
normal = 'gr',
176+
normal = 'grr',
177177
callback = function()
178178
local section = copilot.chat:get_closest_section()
179179
if not section or section.answer then
@@ -225,6 +225,38 @@ return {
225225
end,
226226
},
227227

228+
clear_stickies = {
229+
normal = 'grx',
230+
callback = function()
231+
local section = copilot.chat:get_closest_section()
232+
if not section or section.answer then
233+
return
234+
end
235+
236+
local lines = vim.split(section.content, '\n')
237+
local new_lines = {}
238+
local changed = false
239+
240+
for _, line in ipairs(lines) do
241+
if not vim.startswith(vim.trim(line), '> ') then
242+
table.insert(new_lines, line)
243+
else
244+
changed = true
245+
end
246+
end
247+
248+
if changed then
249+
vim.api.nvim_buf_set_lines(
250+
copilot.chat.bufnr,
251+
section.start_line,
252+
section.end_line - 1,
253+
false,
254+
new_lines
255+
)
256+
end
257+
end,
258+
},
259+
228260
accept_diff = {
229261
normal = '<C-y>',
230262
insert = '<C-y>',

lua/CopilotChat/init.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ local function insert_sticky(prompt, config, override_sticky)
5353

5454
lines = vim.split(vim.trim(table.concat(lines, '\n')), '\n')
5555

56-
if config.model and config.model ~= M.config.model then
56+
if config.remember_as_sticky and config.model and config.model ~= M.config.model then
5757
stickies:set('$' .. config.model, true)
5858
end
5959

60-
if config.agent and config.agent ~= M.config.agent then
60+
if config.remember_as_sticky and config.agent and config.agent ~= M.config.agent then
6161
stickies:set('@' .. config.agent, true)
6262
end
6363

64-
if config.context and not vim.deep_equal(config.context, M.config.context) then
64+
if
65+
config.remember_as_sticky
66+
and config.context
67+
and not vim.deep_equal(config.context, M.config.context)
68+
then
6569
if type(config.context) == 'table' then
6670
---@diagnostic disable-next-line: param-type-mismatch
6771
for _, context in ipairs(config.context) do

0 commit comments

Comments
 (0)