Skip to content

Commit 28a33e7

Browse files
committed
fix: improve context clearing in new sessions and file mentions
- Clear attachments when starting a new session with /new command - Toggle file removal when selecting already-mentioned files with @ trigger - Fixes issue where context persisted across new sessions - Fixes issue where @ file selection only added files, never removed them
1 parent b4ad8c1 commit 28a33e7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lua/opencode/core.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ M.open = Promise.async(function(opts)
9393
if opts.new_session then
9494
state.active_session = nil
9595
state.last_sent_context = nil
96+
context.unload_attachments()
9697

9798
state.current_model = nil
9899
state.current_mode = nil

lua/opencode/ui/completion/files.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ local file_source = {
144144
local mention = require('opencode.ui.mention')
145145
mention.highlight_all_mentions(state.windows.input_buf)
146146

147-
context.add_file(item.data.full_path)
147+
local mentioned_files = context.context.mentioned_files or {}
148+
local is_already_mentioned = vim.tbl_contains(mentioned_files, item.data.full_path)
149+
150+
if is_already_mentioned then
151+
context.remove_file(item.data.full_path)
152+
mention.remove_mention(item.data.full_path)
153+
else
154+
context.add_file(item.data.full_path)
155+
end
148156
end,
149157
}
150158

0 commit comments

Comments
 (0)