@@ -381,6 +381,41 @@ describe('LSP', function()
381381 }
382382end )
383383
384+ it (' should detach buffer on bufwipe' ,function ()
385+ local result = exec_lua ([[
386+ local server = function(dispatchers)
387+ local closing = false
388+ return {
389+ request = function(method, params, callback)
390+ if method == 'initialize' then
391+ callback(nil, { capabilities = {} })
392+ end
393+ end,
394+ notify = function(...)
395+ end,
396+ is_closing = function() return closing end,
397+ terminate = function() closing = true end
398+ }
399+ end
400+ local bufnr = vim.api.nvim_create_buf(false, true)
401+ vim.api.nvim_set_current_buf(bufnr)
402+ local client_id = vim.lsp.start({ name = 'detach-dummy', cmd = server })
403+ assert(client_id, "lsp.start must return client_id")
404+ return { bufnr = bufnr, client_id = client_id }
405+ ]] )
406+ eq (true ,result ~= nil ," exec_lua must return result with client_id and bufnr" )
407+ local is_attached ,num_attached_before ,num_attached_after = unpack (exec_lua ([[
408+ local bufnr, client_id = ...
409+ local client = lsp.get_client_by_id(client_id)
410+ local count_before = vim.tbl_count(client.attached_buffers)
411+ vim.api.nvim_buf_delete(bufnr, { force = true })
412+ return { lsp.buf_is_attached(bufnr, client_id), count_before, vim.tbl_count(client.attached_buffers) }
413+ ]] ,result .bufnr ,result .client_id ))
414+ eq (false ,is_attached )
415+ eq (1 ,num_attached_before )
416+ eq (0 ,num_attached_after )
417+ end )
418+
384419it (' should fire autocommands on attach and detach' ,function ()
385420local client
386421test_rpc_server {