refactor(detach): eliminate nvim__ui_detach #40793

Problem:
`nvim__ui_detach` was added in 85e0559d46 in order to implement
`detach_others` from Lua. Using Lua in this case is doing more harm than
good.

Solution:
Extract `ui_detach_channel`, which also allows it to be used for the
"self detach" path from `ex_detach`.

Bonus: the old MSWIN path always called `os_swap_to_hidden_console()`;
now `ui_detach_channel` only does so for a stdio channel. For the common
stdio TUI this is identical; for a socket UI it's more correct (no
parent console to swap).
This commit is contained in:
Justin M. Keyes
2026-07-17 16:37:45 -04:00
committed by GitHub
parent 85e0559d46
commit e0e7f65b74
7 changed files with 68 additions and 103 deletions

View File

@@ -219,24 +219,4 @@ function M.ex_session_restart(eap, extra)
end
end
--- Disconnects every UI except `keep_chan`, keeping the server running.
---
--- @param keep_chan integer Channel ID of the UI to preserve.
--- @return integer # Number of UIs detached.
function M.detach_others(keep_chan)
local uicount = #vim.api.nvim_list_uis()
for _, ui in ipairs(vim.api.nvim_list_uis()) do
if ui.chan and ui.chan ~= keep_chan then
vim.api.nvim__ui_detach(ui.chan)
end
end
local n = uicount - #vim.api.nvim_list_uis()
if n == 0 then
vim.api.nvim_echo({ { 'No other UIs are attached' } }, true, {})
else
vim.api.nvim_echo({ { ('Detached %d non-current UIs'):format(n) } }, true, {})
end
return n
end
return M

View File

@@ -186,16 +186,6 @@ function vim.api.nvim__set_restart_on_crash(progpath, argv) end
--- @return table<string,any> # Map of various internal stats.
function vim.api.nvim__stats() end
--- WARNING: This feature is experimental/unstable.
---
--- Detaches the UI on channel `chan`.
---
--- Sets the channel's detach flag (so the server doesn't exit on stdio UIs),
--- sends an "error_exit" UI event, and closes the channel.
---
--- @param chan integer UI channel to disconnect.
function vim.api.nvim__ui_detach(chan) end
--- WARNING: This feature is experimental/unstable.
---
--- @param str string