mirror of
https://github.com/neovim/neovim.git
synced 2026-04-20 14:25:32 +00:00
feat: serverlist({peer=true}) returns peer addresses #34806
Problem:
serverlist() only lists servers that were started by the current Nvim.
Solution:
Look for other Nvim servers in stdpath("run").
This commit is contained in:
33
runtime/lua/vim/_core/server.lua
Normal file
33
runtime/lua/vim/_core/server.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
local M = {}
|
||||
|
||||
--- Called by builtin serverlist(). Returns all running servers.
|
||||
--- in stdpath("run"). Does not include named pipes or TCP servers.
|
||||
---
|
||||
--- @param listed string[] Already listed servers
|
||||
--- @return string[] A list of currently running servers 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 = {}
|
||||
for _, socket in ipairs(socket_paths) do
|
||||
-- Don't list servers twice
|
||||
if not vim.list_contains(listed, socket) then
|
||||
local ok, chan = pcall(vim.fn.sockconnect, 'pipe', socket, { rpc = true })
|
||||
if ok and chan then
|
||||
-- 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)
|
||||
end
|
||||
vim.fn.chanclose(chan)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return running_sockets
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user