Skip to content

Commit

Permalink
merge #152
Browse files Browse the repository at this point in the history
feat(usercmds): Add `:Cord status`
  • Loading branch information
vyfor authored Dec 29, 2024
2 parents 618ce39 + 47c3d6a commit 2b0fc96
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lua/cord/api/usercmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ M.restart = function()
cord.tx:shutdown()
end)
end
M.status = function()
local cord = require 'cord.server'
if cord.status == 'ready' then
require('cord.plugin.log').info 'Status: Connected to Discord'
elseif cord.status == 'connecting' then
require('cord.plugin.log').info 'Status: Connecting to server'
elseif cord.status == 'connected' then
require('cord.plugin.log').info 'Status: Connecting to Discord'
else
require('cord.plugin.log').info 'Status: Disconnected'
end
end

M.handle = function(args)
local command = M[args[1]]
Expand Down
10 changes: 9 additions & 1 deletion lua/cord/server/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ function M:connect(path, retried)
return
end

self.status = 'connecting'
logger.debug 'Connecting...'

logger.debug('Pipe: ' .. path)
M.client = require('cord.core.uv.pipe').new()
local _, err = M.client:connect(path):get()

if not err then
self.status = 'connected'
logger.debug 'Connected to pipe'
return M:run():await()
end
Expand Down Expand Up @@ -59,6 +61,7 @@ function M:run()
M.rx:register(
'ready',
vim.schedule_wrap(function()
self.status = 'ready'
async.run(function()
logger.info 'Connected to Discord'
M.tx:initialize(self.config)
Expand All @@ -67,6 +70,7 @@ function M:run()
local manager, err =
ActivityManager.new({ tx = M.tx, config = self.config }):get()
if not manager or err then
self.status = 'disconnected'
self.client:close()
logger.error(err or 'Failed to initialize activity manager')
return
Expand All @@ -92,6 +96,7 @@ function M:run()
end

function M:initialize(config)
self.status = 'connecting'
self.config = config or self.config
async.run(function()
logger.debug 'Initializing server...'
Expand All @@ -100,7 +105,10 @@ function M:initialize(config)
or require('cord.plugin.constants').get_pipe_path()

local _, err = M:connect(path):get()
if err then logger.error(err) end
if err then
self.status = 'disconnected'
logger.error(err)
end
end)
end

Expand Down
2 changes: 1 addition & 1 deletion plugin/cord.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ augroup Cord
augroup END

function! CordCompleteList(ArgLead, CmdLine, CmdPos)
let completions = ['update', 'build', 'fetch', 'show_presence', 'hide_presence', 'toggle_presence', 'clear_presence', 'idle', 'unidle', 'toggle_idle', 'restart']
let completions = ['status', 'update', 'build', 'fetch', 'show_presence', 'hide_presence', 'toggle_presence', 'clear_presence', 'idle', 'unidle', 'toggle_idle', 'restart']

return filter(completions, 'v:val =~ "^" . a:ArgLead')
endfunction
Expand Down

0 comments on commit 2b0fc96

Please sign in to comment.