mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2025-04-07 19:21:32 +02:00
fix: namespace ops must happen on main loop
this plugin is becoming a bit of vim.schedule hell... maybe the :and_then() callback should make sure it runs on the main loop? maybe offer an :and_then(), which runs on main loop, and a :and_then_soon(), which runs in the callback thread itself
This commit is contained in:
parent
91bc8f8dba
commit
214f7db24b
1 changed files with 30 additions and 24 deletions
|
@ -155,6 +155,7 @@ local function join(workspace)
|
|||
register_cursor_callback(ws:cursor(), ws:id())
|
||||
register_cursor_handler(ws:cursor())
|
||||
CODEMP.workspace = ws
|
||||
vim.schedule(function ()
|
||||
for _, user in pairs(CODEMP.workspace:user_list()) do
|
||||
buffers.users[user.name] = ""
|
||||
user_hl[user.name] = {
|
||||
|
@ -165,12 +166,14 @@ local function join(workspace)
|
|||
}
|
||||
end
|
||||
require('codemp.window').update()
|
||||
end)
|
||||
local async = vim.uv.new_async(function ()
|
||||
while true do
|
||||
local event = ws:try_recv():await()
|
||||
if event == nil then break end
|
||||
if event.type == "UserLeave" then
|
||||
if buffers.users[event.name] ~= nil then
|
||||
vim.schedule(function()
|
||||
local buf_name = buffers.users[event.name]
|
||||
local buf_id = buffers.map_rev[buf_name]
|
||||
if buf_id ~= nil then
|
||||
|
@ -178,8 +181,10 @@ local function join(workspace)
|
|||
end
|
||||
buffers.users[event.name] = nil
|
||||
user_hl[event.name] = nil
|
||||
end)
|
||||
end
|
||||
elseif event.type == "UserJoin" then
|
||||
vim.schedule(function()
|
||||
buffers.users[event.name] = ""
|
||||
user_hl[event.name] = {
|
||||
ns = vim.api.nvim_create_namespace("codemp-cursor-" .. event.name),
|
||||
|
@ -187,6 +192,7 @@ local function join(workspace)
|
|||
pos = { 0, 0 },
|
||||
mark = nil,
|
||||
}
|
||||
end)
|
||||
end
|
||||
end
|
||||
vim.schedule(function () require('codemp.window').update() end)
|
||||
|
|
Loading…
Add table
Reference in a new issue