mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2025-04-10 20:41:31 +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_callback(ws:cursor(), ws:id())
|
||||||
register_cursor_handler(ws:cursor())
|
register_cursor_handler(ws:cursor())
|
||||||
CODEMP.workspace = ws
|
CODEMP.workspace = ws
|
||||||
|
vim.schedule(function ()
|
||||||
for _, user in pairs(CODEMP.workspace:user_list()) do
|
for _, user in pairs(CODEMP.workspace:user_list()) do
|
||||||
buffers.users[user.name] = ""
|
buffers.users[user.name] = ""
|
||||||
user_hl[user.name] = {
|
user_hl[user.name] = {
|
||||||
|
@ -165,12 +166,14 @@ local function join(workspace)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
require('codemp.window').update()
|
require('codemp.window').update()
|
||||||
|
end)
|
||||||
local async = vim.uv.new_async(function ()
|
local async = vim.uv.new_async(function ()
|
||||||
while true do
|
while true do
|
||||||
local event = ws:try_recv():await()
|
local event = ws:try_recv():await()
|
||||||
if event == nil then break end
|
if event == nil then break end
|
||||||
if event.type == "UserLeave" then
|
if event.type == "UserLeave" then
|
||||||
if buffers.users[event.name] ~= nil then
|
if buffers.users[event.name] ~= nil then
|
||||||
|
vim.schedule(function()
|
||||||
local buf_name = buffers.users[event.name]
|
local buf_name = buffers.users[event.name]
|
||||||
local buf_id = buffers.map_rev[buf_name]
|
local buf_id = buffers.map_rev[buf_name]
|
||||||
if buf_id ~= nil then
|
if buf_id ~= nil then
|
||||||
|
@ -178,8 +181,10 @@ local function join(workspace)
|
||||||
end
|
end
|
||||||
buffers.users[event.name] = nil
|
buffers.users[event.name] = nil
|
||||||
user_hl[event.name] = nil
|
user_hl[event.name] = nil
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
elseif event.type == "UserJoin" then
|
elseif event.type == "UserJoin" then
|
||||||
|
vim.schedule(function()
|
||||||
buffers.users[event.name] = ""
|
buffers.users[event.name] = ""
|
||||||
user_hl[event.name] = {
|
user_hl[event.name] = {
|
||||||
ns = vim.api.nvim_create_namespace("codemp-cursor-" .. event.name),
|
ns = vim.api.nvim_create_namespace("codemp-cursor-" .. event.name),
|
||||||
|
@ -187,6 +192,7 @@ local function join(workspace)
|
||||||
pos = { 0, 0 },
|
pos = { 0, 0 },
|
||||||
mark = nil,
|
mark = nil,
|
||||||
}
|
}
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
vim.schedule(function () require('codemp.window').update() end)
|
vim.schedule(function () require('codemp.window').update() end)
|
||||||
|
|
Loading…
Add table
Reference in a new issue