mirror of
https://github.com/neovim/neovim.git
synced 2026-01-08 04:18:49 +10:00
Problem: We want to encourage implementing core features in Lua instead of C, but it's clumsy because: - Core Lua code (built into `nvim` so it is available even if VIMRUNTIME is missing/invalid) requires manually updating CMakeLists.txt, or stuffing it into `_editor.lua`. - Core Lua modules are not organized similar to C modules, `_editor.lua` is getting too big. Solution: - Introduce `_core/` where core Lua code can live. All Lua modules added there will automatically be included as bytecode in the `nvim` binary. - Move these core modules into `_core/*`: ``` _defaults.lua _editor.lua _options.lua _system.lua shared.lua ``` TODO: - Move `_extui/ => _core/ui2/`
38 lines
1.2 KiB
Lua
38 lines
1.2 KiB
Lua
-- For "--listen" and related functionality.
|
|
|
|
local M = {}
|
|
|
|
--- 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[] # List of servers found on the current machine in stdpath("run").
|
|
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 = {} ---@type string[]
|
|
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(found, socket)
|
|
end
|
|
vim.fn.chanclose(chan)
|
|
end
|
|
end
|
|
end
|
|
|
|
return found
|
|
end
|
|
|
|
return M
|