Skip to content

Commit c9e0738

Browse files
phanenibhagwan
authored andcommitted
fix(actions): error message changed on nightly
Maybe something changed in upstream * fix(serverlist): ignore rpc error Also move the filter logic together * fix: convert vim.NIL to nil in rpc response
1 parent 46d8e5c commit c9e0738

3 files changed

Lines changed: 20 additions & 33 deletions

File tree

lua/fzf-lua/actions.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,10 @@ local parse_entry = function(e) return e and e:match("%((.-)%)") or nil end
13641364
M.serverlist_kill = function(sel)
13651365
vim.iter(sel):map(parse_entry):each(function(addr)
13661366
local ok, err = utils.rpcexec(addr, "nvim_exec2", "qa!", {})
1367-
assert(ok or tostring(err):match("Invalid channel"), err)
1367+
assert(ok
1368+
or tostring(err):match("Invalid channel")
1369+
or tostring(err):match("ch %d+ was closed by the peer"),
1370+
err)
13681371
end)
13691372
end
13701373

lua/fzf-lua/providers/nvim.lua

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -786,42 +786,25 @@ M.serverlist = function(opts)
786786
local socket_paths = vim.fs.find(function(name, _)
787787
return name:match("nvim.*")
788788
end, { path = root, type = "socket", limit = math.huge })
789-
790-
local found = {} ---@type string[]
791-
for _, socket in ipairs(socket_paths) do
792-
-- Don't list servers twice
793-
if not vim.list_contains(listed, socket) then
794-
local ok, chan = pcall(vim.fn.sockconnect, "pipe", socket, { rpc = true })
795-
if ok and chan then ---@cast chan integer
796-
-- Check that the server is responding
797-
if vim.fn.rpcrequest(chan, "nvim_get_chan_info", 0).id then
798-
table.insert(found, socket)
799-
end
800-
vim.fn.chanclose(chan)
801-
end
802-
end
789+
local found = utils.list_to_map(listed or vim.fn.serverlist())
790+
local filter = function(socket)
791+
if found[socket] or socket:match("fzf%-lua") then return false end
792+
found[socket] = true
793+
local ok, info = utils.rpcexec(socket, "nvim_get_chan_info", 0)
794+
return ok and info.id
803795
end
804-
return found
796+
return vim.iter(socket_paths):filter(filter)
805797
end
806798

807799
opts = require("fzf-lua.config").normalize_opts(opts or {}, "serverlist")
808-
local list = vim.fn.serverlist()
800+
809801
local f = function(cb)
810-
vim
811-
.iter(serverlist(list))
812-
:filter(
813-
function(p)
814-
return not p:match("fzf%-lua") and not vim.tbl_contains(list, p)
815-
end
816-
)
817-
:map(function(p)
818-
---@type boolean, string?
819-
local ok, cwd = utils.rpcexec(p, "nvim_exec_lua", "return vim.uv.cwd()", {})
820-
if not ok or not cwd then return end
821-
cwd = FzfLua.path.normalize(cwd)
822-
return ("%s (%s)"):format(cwd, p)
823-
end)
824-
:each(cb)
802+
serverlist():each(function(p) ---@type boolean, string?
803+
local ok, cwd = utils.rpcexec(p, "nvim_exec_lua", "return vim.uv.cwd()", {})
804+
if not ok or not cwd then return end
805+
cwd = FzfLua.path.normalize(cwd)
806+
cb(("%s (%s)"):format(cwd, p))
807+
end)
825808
cb(nil)
826809
end
827810
core.fzf_exec(function(cb)

lua/fzf-lua/utils.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,8 @@ function M.rpcexec(addr, method, ...)
15081508
---@cast chan integer
15091509
local ret = { pcall(vim.rpcrequest, chan, method, ...) }
15101510
vim.fn.chanclose(chan)
1511-
return unpack(ret)
1511+
local tonil = function(v) if v == vim.NIL then return nil else return v end end
1512+
return unpack(vim.tbl_map(tonil, ret))
15121513
end
15131514

15141515
--- Checks if treesitter parser for language is installed

0 commit comments

Comments
 (0)