Skip to content

Commit a559306

Browse files
committed
refactor(command): simplify status notification logic
1 parent 0204735 commit a559306

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

lua/cord/api/command.lua

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,17 @@ M.shutdown = function()
106106
end
107107
M.status = function()
108108
local cord = require 'cord.server'
109-
if cord.status == 'disconnected' then
110-
require('cord.api.log').notify('Status: Disconnected', vim.log.levels.INFO)
111-
elseif cord.status == 'initializing' then
112-
require('cord.api.log').notify('Status: Connecting to server', vim.log.levels.INFO)
113-
elseif cord.status == 'initialized' then
114-
require('cord.api.log').notify('Status: Connected to server', vim.log.levels.INFO)
115-
elseif cord.status == 'connecting' then
116-
require('cord.api.log').notify('Status: Connecting to Discord', vim.log.levels.INFO)
117-
elseif cord.status == 'connected' then
118-
require('cord.api.log').notify('Status: Handshaking with Discord', vim.log.levels.INFO)
119-
elseif cord.status == 'ready' then
120-
require('cord.api.log').notify('Status: Connected to Discord', vim.log.levels.INFO)
121-
else
122-
require('cord.api.log').notify('Status: Unknown', vim.log.levels.INFO)
123-
end
109+
local status_map = {
110+
disconnected = 'Disconnected',
111+
initializing = 'Connecting to server',
112+
initialized = 'Connected to server',
113+
connecting = 'Connecting to Discord',
114+
connected = 'Handshaking with Discord',
115+
ready = 'Connected to Discord',
116+
}
117+
local msg = status_map[cord.status] or 'Unknown'
118+
require('cord.api.log').notify('Status: ' .. msg, vim.log.levels.INFO)
119+
return msg
124120
end
125121
M.check = function()
126122
require('cord.core.async').run(

lua/cord/api/config/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ M.check = function()
499499
)
500500
info('Neovim version: `' .. tostring(vim.version()) .. '`')
501501
info('Lua version: `' .. tostring(_VERSION) .. (jit and ' (with LuaJIT)`' or '`'))
502-
info('Cord connection status: `' .. tostring(require('cord.server').status) .. '`\n')
502+
info('Cord connection status: `' .. require('cord.api.command').status() .. '`\n')
503503

504504
if vim.fn.executable 'curl' == 1 then
505505
ok '`curl` is installed'

0 commit comments

Comments
 (0)