diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2026-04-17 18:14:14 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2026-04-18 16:57:37 +0200 |
| commit | 3ebfa2a3cbbed848667fe26c16973ce7e43a04e4 (patch) | |
| tree | 8026deb4b85a46be16eb32bbe85f3b9c24c5e4c7 /runtime/lua/vim/_core/server.lua | |
| parent | 48d11681c2c108e34be088cf2f6ce6cc753fa57f (diff) | |
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
Diffstat (limited to 'runtime/lua/vim/_core/server.lua')
| -rw-r--r-- | runtime/lua/vim/_core/server.lua | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/runtime/lua/vim/_core/server.lua b/runtime/lua/vim/_core/server.lua index 14f942459d..54d8d104f0 100644 --- a/runtime/lua/vim/_core/server.lua +++ b/runtime/lua/vim/_core/server.lua @@ -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 |
