Skip to content

Commit fa31457

Browse files
committed
feat: restore mentions when navigating history
1 parent 123d62b commit fa31457

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

lua/opencode/api.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,15 @@ function M.prev_history()
216216
local prev_prompt = history.prev()
217217
if prev_prompt then
218218
input_window.set_content(prev_prompt)
219+
require('opencode.ui.mention').restore_mentions(state.windows.input_buf)
219220
end
220221
end
221222

222223
function M.next_history()
223224
local next_prompt = history.next()
224225
if next_prompt then
225226
input_window.set_content(next_prompt)
227+
require('opencode.ui.mention').restore_mentions(state.windows.input_buf)
226228
end
227229
end
228230

lua/opencode/context.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ function M.add_file(file)
108108
end
109109
end
110110

111+
M.clear_files = function()
112+
M.context.mentioned_files = nil
113+
M.context.mentioned_files_content = nil
114+
end
115+
111116
function M.add_subagent(subagent)
112117
if not M.context.mentioned_subagents then
113118
M.context.mentioned_subagents = {}
@@ -118,6 +123,10 @@ function M.add_subagent(subagent)
118123
end
119124
end
120125

126+
M.clear_subagents = function()
127+
M.context.mentioned_subagents = nil
128+
end
129+
121130
---@param opts OpencodeContextConfig
122131
function M.delta_context(opts)
123132
opts = opts or config.context

lua/opencode/ui/mention.lua

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local M = {}
22

33
local mentions_namespace = vim.api.nvim_create_namespace('OpencodeMentions')
44

5-
function M.highlight_all_mentions(buf)
5+
function M.highlight_all_mentions(buf, callback)
66
-- Pattern for mentions
77
local mention_pattern = '@[%w_%-%./][%w_%-%./]*'
88

@@ -24,6 +24,10 @@ function M.highlight_all_mentions(buf)
2424
break
2525
end
2626

27+
if callback then
28+
callback(line:sub(mention_start + 1, mention_end), row, mention_start, mention_end)
29+
end
30+
2731
-- Add extmark for this mention
2832
vim.api.nvim_buf_set_extmark(buf, mentions_namespace, row - 1, mention_start - 1, {
2933
end_col = mention_end,
@@ -66,4 +70,25 @@ function M.mention(get_name)
6670
end)
6771
end
6872

73+
function M.restore_mentions(buf)
74+
local context = require('opencode.context')
75+
76+
context.clear_subagents()
77+
context.clear_files()
78+
79+
M.highlight_all_mentions(buf, function(name)
80+
local agents = require('opencode.config_file').get_subagents()
81+
82+
if vim.tbl_contains(agents, name) then
83+
require('opencode.context').add_subagent(name)
84+
return
85+
end
86+
87+
if vim.fn.filereadable(name) == 1 then
88+
require('opencode.context').add_file(name)
89+
return
90+
end
91+
end)
92+
end
93+
6994
return M

0 commit comments

Comments
 (0)