mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
@@ -1,17 +1,18 @@
|
||||
local M = {}
|
||||
|
||||
--- Called by builtin serverlist(). Returns all running servers.
|
||||
--- in stdpath("run"). Does not include named pipes or TCP servers.
|
||||
--- Called by builtin serverlist(). Returns all running servers in stdpath("run").
|
||||
---
|
||||
--- - TODO: track TCP servers, somehow.
|
||||
--- - TODO: support Windows named pipes.
|
||||
---
|
||||
--- @param listed string[] Already listed servers
|
||||
--- @return string[] A list of currently running servers in stdpath("run")
|
||||
--- @return string[] # List of servers found on the current machine in stdpath("run").
|
||||
function M.serverlist(listed)
|
||||
-- TODO: also get named pipes on Windows
|
||||
local socket_paths = vim.fs.find(function(name, _)
|
||||
return name:match('nvim.*')
|
||||
end, { path = vim.fn.stdpath('run'), type = 'socket', limit = math.huge })
|
||||
|
||||
local running_sockets = {}
|
||||
local found = {} ---@type string[]
|
||||
for _, socket in ipairs(socket_paths) do
|
||||
-- Don't list servers twice
|
||||
if not vim.list_contains(listed, socket) then
|
||||
@@ -20,14 +21,14 @@ function M.serverlist(listed)
|
||||
-- Check that the server is responding
|
||||
-- TODO: do we need a timeout or error handling here?
|
||||
if vim.fn.rpcrequest(chan, 'nvim_get_chan_info', 0).id then
|
||||
table.insert(running_sockets, socket)
|
||||
table.insert(found, socket)
|
||||
end
|
||||
vim.fn.chanclose(chan)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return running_sockets
|
||||
return found
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user