Something went wrong. Try again.
A neovim plugin for OpenCode
Something went wrong. Try again.
2.2 kB · 62 lines
Lua
at commit c8ba63ed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263local ui = require("brokencode.ui")local client = require("brokencode.client")
local source_win = vim.api.nvim_get_current_win()
ui.render({ { type = "user", text = "first line\nsecond line" },})
assert(vim.api.nvim_get_current_win() == source_win, "render changed the current window")
local lines = vim.api.nvim_buf_get_lines(ui.chat_buf, 0, -1, false)assert(vim.tbl_contains(lines, "first line"), vim.inspect(lines))assert(vim.tbl_contains(lines, "second line"), vim.inspect(lines))
local redraws = 0local cmd = vim.cmdvim.cmd = function(command) if command == "redraw" then redraws = redraws + 1 return end cmd(command)endui.render({ { type = "user", text = "redrawn" } })vim.cmd = cmdassert(redraws == 1, "render did not redraw the chat window")
local replacement = vim.api.nvim_create_buf(false, true)vim.api.nvim_win_set_buf(ui.chat_win, replacement)ui.render({ { type = "user", text = "restored" } })assert(vim.api.nvim_win_get_buf(ui.chat_win) == ui.chat_buf, "chat buffer was not restored")
ui.set_running("ses_test", true)lines = vim.api.nvim_buf_get_lines(ui.chat_buf, 0, -1, false)assert(vim.tbl_contains(lines, "> **Request running...**"), vim.inspect(lines))
ui.set_running("ses_test", false)lines = vim.api.nvim_buf_get_lines(ui.chat_buf, 0, -1, false)assert(not vim.tbl_contains(lines, "> **Request running...**"), vim.inspect(lines))
local callbacks = {}local messages = client.messagesclient.messages = function(_, callback) table.insert(callbacks, callback)end
ui.refresh("ses_test")ui.refresh("ses_test")callbacks[2](nil, { { type = "user", text = "new response" } })callbacks[1](nil, { { type = "user", text = "stale response" } })lines = vim.api.nvim_buf_get_lines(ui.chat_buf, 0, -1, false)assert(vim.tbl_contains(lines, "new response"), vim.inspect(lines))assert(not vim.tbl_contains(lines, "stale response"), vim.inspect(lines))
ui.set_running("ses_new", true)ui.set_running("ses_old", false)ui.refresh("ses_old")callbacks[3](nil, { { type = "user", text = "old session" } })assert(ui.current_session == "ses_new", "old polling replaced the active session")
client.messages = messages