Skip to content

Commit dce94bc

Browse files
committed
refactor(state): use std.RawGet and keyof OpencodeState in annotations
1 parent ff2bf75 commit dce94bc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lua/opencode/state/store.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ local _state = {
4949

5050
local _listeners = {}
5151

52-
---@param key string
52+
---@param key keyof OpencodeState
5353
---@param opts? OpencodeProtectedStateSetOptions
5454
local function error_on_raw_write(key, opts)
5555
if opts and opts.silent then
@@ -65,16 +65,16 @@ end
6565

6666
---@generic K extends keyof OpencodeState
6767
---@param key K
68-
---@return OpencodeState[K]
68+
---@return std.RawGet<OpencodeState, K>
6969
function M.get(key)
7070
return _state[key]
7171
end
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>
7878
function M.set(key, value, opts)
7979
local old = _state[key]
8080
opts = opts or { source = 'helper' }
@@ -93,19 +93,19 @@ end
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>
9999
function 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)
102102
end
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>
109109
function M.update(key, updater, opts)
110110
local next_value = updater(_state[key])
111111
M.set(key, next_value, opts)
@@ -114,7 +114,7 @@ end
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>)
118118
function M.subscribe(key, cb)
119119
if type(key) == 'table' then
120120
for _, current_key in ipairs(key) do
@@ -139,7 +139,7 @@ end
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>)
143143
function M.unsubscribe(key, cb)
144144
key = key or '*'
145145
local list = _listeners[key]
@@ -156,8 +156,8 @@ end
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>
161161
function M.emit(key, new_val, old_val)
162162
vim.schedule(function()
163163
if _listeners[key] then
@@ -179,7 +179,7 @@ end
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
183183
function M.append(key, value)
184184
if type(value) ~= 'table' then
185185
error('Value must be a table to append')

0 commit comments

Comments
 (0)