local M = {}
function M.serverlist(listed)
local root = vim.fs.normalize(vim.fn.stdpath('run') .. '/..')
local socket_paths = vim.fs.find(function(name, _)
return name:match('nvim.*')
end, { path = root, type = 'socket', limit = math.huge })
local found = {}
for _, socket in ipairs(socket_paths) do
if not vim.list_contains(listed, socket) then
local ok, chan = pcall(vim.fn.sockconnect, 'pipe', socket, { rpc = true })
if ok and chan then
if vim.fn.rpcrequest(chan, 'nvim_get_chan_info', 0).id then
table.insert(found, socket)
end
vim.fn.chanclose(chan)
end
end
end
return found
end
return M