forked from nickjvandyke/opencode.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.lua
More file actions
63 lines (57 loc) · 1.55 KB
/
status.lua
File metadata and controls
63 lines (57 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
local M = {}
---@alias opencode.status.Status
---| "idle"
---| "error"
---| "responding"
---| "requesting_permission"
---@alias opencode.status.Icon
---| ""
---| ""
---| ""
---| ""
---| ""
---@type opencode.status.Status|nil
M.status = nil
---@return opencode.status.Icon
function M.statusline()
if M.status == "idle" then
return ""
elseif M.status == "responding" then
return ""
elseif M.status == "requesting_permission" then
return ""
elseif M.status == "error" then
return ""
else
return ""
end
end
---@param event opencode.cli.client.Event
function M.update(event)
if
event.type == "server.connected"
or event.type == "session.idle"
-- `session.idle` seems frequently followed by a few `message.updated`s...
-- but `session.diff` seems to be a more definitive idle signal.
-- It's sometimes also emitted in the middle of a response, but NBD.
or event.type == "session.diff"
-- Pretty good fallback
or event.type == "session.heartbeat"
then
M.status = "idle"
elseif
event.type == "message.updated"
or event.type == "message.part.updated"
or event.type == "permission.replied"
then
M.status = "responding"
elseif event.type == "permission.updated" then
M.status = "requesting_permission"
elseif event.type == "session.error" then
M.status = "error"
elseif event.type == "server.disconnected" then
-- NOTE: *we* send server.disconnected when unsubscribing or `opencode`'s heartbeat disappears
M.status = nil
end
end
return M