@@ -49,7 +49,7 @@ local _state = {
4949
5050local _listeners = {}
5151
52- --- @param key string
52+ --- @param key keyof OpencodeState
5353--- @param opts ? OpencodeProtectedStateSetOptions
5454local function error_on_raw_write (key , opts )
5555 if opts and opts .silent then
6565
6666--- @generic K extends keyof OpencodeState
6767--- @param key K
68- --- @return OpencodeState[K]
68+ --- @return std.RawGet< OpencodeState, K>
6969function M .get (key )
7070 return _state [key ]
7171end
7272
7373--- @generic K extends keyof OpencodeState
7474--- @param key K
75- --- @param value OpencodeState[K]
75+ --- @param value std.RawGet< OpencodeState, K>
7676--- @param opts ? OpencodeProtectedStateSetOptions
77- --- @return OpencodeState[K]
77+ --- @return std.RawGet< OpencodeState, K>
7878function M .set (key , value , opts )
7979 local old = _state [key ]
8080 opts = opts or { source = ' helper' }
9393
9494--- @generic K extends keyof OpencodeState
9595--- @param key K
96- --- @param value OpencodeState[K]
96+ --- @param value std.RawGet< OpencodeState, K>
9797--- @param opts ? OpencodeProtectedStateSetOptions
98- --- @return OpencodeState[K]
98+ --- @return std.RawGet< OpencodeState, K>
9999function M .set_raw (key , value , opts )
100100 local next_opts = vim .tbl_extend (' force' , { source = ' raw' }, opts or {})
101101 return M .set (key , value , next_opts )
102102end
103103
104104--- @generic K extends keyof OpencodeState
105105--- @param key K
106- --- @param updater fun ( current : OpencodeState[K] ): OpencodeState[K]
106+ --- @param updater fun ( current : std.RawGet< OpencodeState, K> ): std.RawGet< OpencodeState, K>
107107--- @param opts ? OpencodeProtectedStateSetOptions
108- --- @return OpencodeState[K]
108+ --- @return std.RawGet< OpencodeState, K>
109109function M .update (key , updater , opts )
110110 local next_value = updater (_state [key ])
111111 M .set (key , next_value , opts )
114114
115115--- @generic K extends keyof OpencodeState
116116--- @param key K | K[] | nil
117- --- @param cb fun ( key : K , new_val : OpencodeState[K] , old_val : OpencodeState[K] )
117+ --- @param cb fun ( key : K , new_val : std.RawGet< OpencodeState, K> , old_val : std.RawGet< OpencodeState, K> )
118118function M .subscribe (key , cb )
119119 if type (key ) == ' table' then
120120 for _ , current_key in ipairs (key ) do
139139
140140--- @generic K extends keyof OpencodeState
141141--- @param key K | nil
142- --- @param cb fun ( key : K , new_val : OpencodeState[K] , old_val : OpencodeState[K] )
142+ --- @param cb fun ( key : K , new_val : std.RawGet< OpencodeState, K> , old_val : std.RawGet< OpencodeState, K> )
143143function M .unsubscribe (key , cb )
144144 key = key or ' *'
145145 local list = _listeners [key ]
156156
157157--- @generic K extends keyof OpencodeState
158158--- @param key K
159- --- @param new_val OpencodeState[K]
160- --- @param old_val OpencodeState[K]
159+ --- @param new_val std.RawGet< OpencodeState, K>
160+ --- @param old_val std.RawGet< OpencodeState, K>
161161function M .emit (key , new_val , old_val )
162162 vim .schedule (function ()
163163 if _listeners [key ] then
179179
180180--- @generic K extends keyof OpencodeState
181181--- @param key K
182- --- @param value OpencodeState[K] extends any[] and OpencodeState[K] [integer] or never
182+ --- @param value std.RawGet< OpencodeState, K> extends any[] and std.RawGet< OpencodeState, K> [integer] or never
183183function M .append (key , value )
184184 if type (value ) ~= ' table' then
185185 error (' Value must be a table to append' )
0 commit comments