@@ -22,14 +22,10 @@ local toggleable_context_keys = {
2222--- @param context_key OpencodeToggleableContextKey
2323--- @return table
2424local function ensure_context_state (context_key )
25- local current_config = state .current_context_config or {}
26- local current = current_config [context_key ]
27- local new_config = vim .deepcopy (current_config )
2825 local defaults = vim .tbl_get (config , ' context' , context_key ) or {}
29-
30- new_config [context_key ] = vim .tbl_deep_extend (' force' , {}, defaults , current or {})
31- state .context .set_current_context_config (new_config )
32- return new_config [context_key ]
26+ return state .context .update_current_context_config (function (current_config )
27+ current_config [context_key ] = vim .tbl_deep_extend (' force' , {}, defaults , current_config [context_key ] or {})
28+ end )[context_key ]
3329end
3430
3531M .ChatContext = ChatContext
@@ -120,12 +116,10 @@ end
120116-- Delegate global state management to ChatContext
121117function M .add_selection (selection )
122118 ChatContext .add_selection (selection )
123- state .context .set_context_updated_at (vim .uv .now ())
124119end
125120
126121function M .remove_selection (selection )
127122 ChatContext .remove_selection (selection )
128- state .context .set_context_updated_at (vim .uv .now ())
129123end
130124
131125function M .clear_selections ()
@@ -200,12 +194,7 @@ function M.build_inline_selection_text(range)
200194 end
201195
202196 local filetype = vim .bo [buf ].filetype or ' '
203- local text = string.format (
204- ' **`%s`**\n\n ```%s\n %s\n ```' ,
205- file .path ,
206- filetype ,
207- current_selection .text
208- )
197+ local text = string.format (' **`%s`**\n\n ```%s\n %s\n ```' , file .path , filetype , current_selection .text )
209198
210199 return text
211200end
@@ -225,13 +214,11 @@ function M.add_file(file)
225214
226215 file = vim .fn .fnamemodify (file , ' :p' )
227216 ChatContext .add_file (file )
228- state .context .set_context_updated_at (vim .uv .now ())
229217end
230218
231219function M .remove_file (file )
232220 file = vim .fn .fnamemodify (file , ' :p' )
233221 ChatContext .remove_file (file )
234- state .context .set_context_updated_at (vim .uv .now ())
235222end
236223
237224function M .clear_files ()
@@ -240,12 +227,10 @@ end
240227
241228function M .add_subagent (subagent )
242229 ChatContext .add_subagent (subagent )
243- state .context .set_context_updated_at (vim .uv .now ())
244230end
245231
246232function M .remove_subagent (subagent )
247233 ChatContext .remove_subagent (subagent )
248- state .context .set_context_updated_at (vim .uv .now ())
249234end
250235
251236function M .clear_subagents ()
258243
259244function M .load ()
260245 ChatContext .load ()
261- state .context .set_context_updated_at (vim .uv .now ())
262246end
263247
264248-- Context creation with delta logic (delegates to ChatContext)
0 commit comments