Skip to content

Commit

Permalink
fix: schedule the callbacks to maintain compatibility with Neovim 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Dec 19, 2024
1 parent b784a74 commit 35428c0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 55 deletions.
91 changes: 47 additions & 44 deletions lua/cord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,62 @@ function M.initialize()

M.producer = Producer.new(client)
M.handler = Handler.new(client)
M.handler:register('initialize', function(pid)
local executable = file_manager.get_executable_name()
local target_path = file_manager.get_target_path(executable)
uv.fs_stat(target_path, function(err)
if not err then
client:on_close(function()
file_manager.get_executable(pid, function(_, err, moved)
if err then
logger.error(err)
return
end
M.handler:register(
'initialize',
vim.schedule_wrap(function(pid)
local executable = file_manager.get_executable_name()
local target_path = file_manager.get_target_path(executable)
uv.fs_stat(target_path, function(err)
if not err then
client:on_close(function()
file_manager.get_executable(pid, function(_, err, moved)
if err then
logger.error(err)
return
end

if moved then
client:close()
M.initialize()
end
if moved then
client:close()
M.initialize()
end
end)
end)
end)
M.producer:shutdown()
else
M.handler:register(
'ready',
vim.schedule_wrap(function()
logger.info 'Connected to Discord'
M.producer:shutdown()
else
M.handler:register(
'ready',
vim.schedule_wrap(function()
logger.info 'Connected to Discord'

local ActivityManager = require 'cord.activity.manager'
local ActivityManager = require 'cord.activity.manager'

if config.values.hooks.on_ready then
config.values.hooks.on_ready()
end
if config.values.hooks.on_ready then
config.values.hooks.on_ready()
end

M.producer:initialize(config.values)
M.producer:initialize(config.values)

ActivityManager.new(
{ tx = M.producer, config = config.values },
vim.schedule_wrap(function(manager)
M.manager = manager
ActivityManager.new(
{ tx = M.producer, config = config.values },
vim.schedule_wrap(function(manager)
M.manager = manager

client:on_close(vim.schedule_wrap(function()
if config.values.hooks.on_disconnect then
config.values.hooks.on_disconnect()
end
client:on_close(vim.schedule_wrap(function()
if config.values.hooks.on_disconnect then
config.values.hooks.on_disconnect()
end

manager:pause()
end))
manager:run()
end)
)
end)
)
end
manager:pause()
end))
manager:run()
end)
)
end)
)
end
end)
end)
end)
)

M.handler:run()
end)
Expand Down
25 changes: 14 additions & 11 deletions lua/cord/core/ipc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ function IPC:connect(callback)
local pipe = uv.new_pipe()
self.pipe = pipe

pipe:connect(self.path, function(err)
if err then
if err == 'ENOENT' then
spawn.spawn_server(self, function() self:connect(callback) end)
pipe:connect(
self.path,
vim.schedule_wrap(function(err)
if err then
if err == 'ENOENT' then
spawn.spawn_server(self, function() self:connect(callback) end)
return
else
logger.error('Failed to connect to pipe: ' .. err)
end
return
else
logger.error('Failed to connect to pipe: ' .. err)
end
return
end

logger.debug('Connected to pipe: ' .. self.path)
logger.debug('Connected to pipe: ' .. self.path)

if callback then callback() end
end)
if callback then callback() end
end)
)
end

function IPC:read_start(callback)
Expand Down

0 comments on commit 35428c0

Please sign in to comment.