mirror of
https://github.com/neovim/neovim.git
synced 2026-08-08 09:01:37 +00:00
feat(vimfn): use Lua for more excmds/vimfns
Problem: Too much boilerplate needed to use Lua to impl an excmd or f_xx function. Solution: - Add `nlua_call_vimfn` which takes the args typval, executes Lua, and returns a typval. - refactor(excmd): lua impl for :log, :lsp
This commit is contained in:
@@ -2,36 +2,40 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
--- Called by builtin serverlist(). Returns all running servers in stdpath("run").
|
||||
--- Called by builtin serverlist(). Returns the combined server list (own + peers).
|
||||
---
|
||||
--- - TODO: track TCP servers, somehow.
|
||||
--- - TODO: support Windows named pipes.
|
||||
---
|
||||
--- @param listed string[] Already listed servers
|
||||
--- @return string[] # List of servers found on the current machine in stdpath("run").
|
||||
function M.serverlist(listed)
|
||||
--- @param opts? table Options:
|
||||
--- - opts.peer is true, also discover peer servers.
|
||||
--- @param addrs string[] Internal ("own") addresses, from `server_address_list`.
|
||||
--- @return string[] # Combined list of servers (own + peers).
|
||||
function M.serverlist(opts, addrs)
|
||||
if type(opts) ~= 'table' or not opts.peer then
|
||||
return addrs
|
||||
end
|
||||
|
||||
-- Discover peer servers in stdpath("run").
|
||||
-- TODO: track TCP servers, somehow.
|
||||
-- TODO: support Windows named pipes.
|
||||
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 = {} ---@type string[]
|
||||
for _, socket in ipairs(socket_paths) do
|
||||
-- Don't list servers twice
|
||||
if not vim.list_contains(listed, socket) then
|
||||
if not vim.list_contains(addrs, 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(found, socket)
|
||||
table.insert(addrs, socket)
|
||||
end
|
||||
vim.fn.chanclose(chan)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return found
|
||||
return addrs
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user