fix: catch attach error for dupe name early

This commit is contained in:
əlemi 2024-09-25 23:32:51 +02:00
parent 33c08653fa
commit 9ea2827277
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -13,6 +13,10 @@ local ticks = {}
---@param content? string if provided, set this content after attaching ---@param content? string if provided, set this content after attaching
---@param nowait? boolean skip waiting for initial content sync ---@param nowait? boolean skip waiting for initial content sync
local function attach(name, buffer, content, nowait) local function attach(name, buffer, content, nowait)
if vim.fn.bufexists(name) then
error("buffer '" .. name .. "' already exists!")
end
if buffer_id_map[name] ~= nil then if buffer_id_map[name] ~= nil then
error("already attached to buffer " .. name) error("already attached to buffer " .. name)
end end
@ -24,6 +28,7 @@ local function attach(name, buffer, content, nowait)
vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer }) vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer })
vim.api.nvim_buf_set_name(buffer, name) vim.api.nvim_buf_set_name(buffer, name)
CODEMP.workspace:attach(name):and_then(function (controller) CODEMP.workspace:attach(name):and_then(function (controller)
-- TODO disgusting! but poll blocks forever on empty buffers...
if not nowait then if not nowait then
local promise = controller:poll() local promise = controller:poll()
for i=1, 20, 1 do for i=1, 20, 1 do