-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive_query.lua
More file actions
56 lines (53 loc) · 2.13 KB
/
Copy pathlive_query.lua
File metadata and controls
56 lines (53 loc) · 2.13 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
local host = rawget(_G, "vim")
local adapter = require(host and "libtmux.runtime.nvim" or "libtmux.runtime.luv")
local function must(value, err)
if err then
error(err, 0)
end
return value
end
local function work(runtime)
local server = must(runtime
:connect({
binary = assert(os.getenv("TMUX_BIN")),
socket_path = assert(os.getenv("TMUX_SOCKET")),
})
:await())
local where = {
active = false,
window = { is = { panes = { some = { active = true } } } },
}
local options =
{ where = where, snapshot = { fields = { panes = { "id" }, windows = { "id" } } } }
local explained = must(server:explain_panes(options):await())
assert(not explained.exact and explained.filter == "#{==:#{pane_active},0}")
assert(#explained.commands == 7 and explained.commands[7].role == "candidates")
local result = must(server:query_panes(options):await())
local expected = result.snapshot.panes:where(where)
assert(result.complete and #result.rows == 2 and #expected == 2)
assert(#result.snapshot.raw.panes == 6 and #result.snapshot.panes == 3)
for index, row in ipairs(result.rows) do
assert(row == expected[index] and row.active == false and #row.window.panes == 3)
assert(row.title == nil)
end
local unsupported, err = server:query_panes({ where = where, pushdown = "require" }):await()
assert(not unsupported and err.code == "unsupported_pushdown" and err.effect == "not_sent")
local native = must(server:query_panes({ native_filter = "#{pane_active}" }):await())
assert(#native.rows == 1 and native.rows[1].active and native.plan.native_filter)
assert(native.complete and native.plan.exact == false)
must(server:close():await())
return "public live query PASS"
end
if host then
adapter.start(work, function(value, err)
if err then
io.stderr:write(tostring(err), "\n")
host.cmd("cquit 1")
else
io.stdout:write(value, "\n")
host.cmd("qa!")
end
end, { max_active = 1 })
else
print(must(adapter.run(work, { max_active = 1 })))
end