trouble.nvim icon indicating copy to clipboard operation
trouble.nvim copied to clipboard

:bd closes who neovim if Trouble window is toggled

Open xsteadfastx opened this issue 3 years ago • 18 comments

i dont know if this is a bug or just the right behavior. if at some point the trouble window is open and i want to close the current buffer :bd just closes the whole neovim process. i recorded a screencast with the behavior.

https://asciinema.org/a/h0wuxHkBqslXHiyl8gLVaJuSq

xsteadfastx avatar Dec 09 '21 13:12 xsteadfastx

I can't reproduce this?

folke avatar Dec 10 '21 09:12 folke

should i provide my init.lua?

https://gist.github.com/47b0f3c84ddcec88d288c174caefb9bb

else i have no idea how i should debug it.

xsteadfastx avatar Dec 10 '21 11:12 xsteadfastx

i disabled now every plugin except

  • neovim/nvim-lspconfig
  • williamboman/nvim-lsp-installer
  • mfussenegger/nvim-lint
  • folke/trouble.nvim

it still closes vim with :bd if trouble window is open

xsteadfastx avatar Dec 10 '21 13:12 xsteadfastx

i checked it with only quickfix open... it works as expected. only with the trouble window bd closes neovim itself.

xsteadfastx avatar Dec 10 '21 14:12 xsteadfastx

I see you have auto close enabled. Might be a bug with that. Will check once I'm home

folke avatar Dec 10 '21 14:12 folke

i have some new discoveries:

  • :BufferClose as expected (this is in barbar.nvim)
  • :bd# works and closes all buffers instead of the one you are on

i also googled around and found this thread: https://vi.stackexchange.com/questions/22695/how-can-i-ensure-vim-doesnt-quit-entirely-when-the-last-window-is-closed-unles

it describes :bd as

:bd This will delete a buffer, and in doing so, it will close any window that is currently displaying that buffer. But if you run it when you only have one window open, then Vim will not quit, and instead, one of your hidden buffers will be displayed. If you don't have any other buffers open, then a new, empty buffer will be displayed.

and i thought maybe thats the problem. because the buffer is visible on all windows. just some ideas :) do you close your buffers with :bd?

xsteadfastx avatar Dec 10 '21 19:12 xsteadfastx

FWIW I don't use :bd :bw to close buffers, 'cause it messes up my window layout, so I instead use vim-bbye to close buffers and keep my current window layout. It introduces :Bdelete and :Bwipeout , so you can map them

There are other alternatives (written in lua btw) but I just can't recall them atm.

Hope it helps

ch3st3r08 avatar Dec 31 '21 23:12 ch3st3r08

FWIW I don't use :bd :bw to close buffers, 'cause it messes up my window layout, so I instead use vim-bbye to close buffers and keep my current window layout. It introduces :Bdelete and :Bwipeout , so you can map them

There are other alternatives (written in lua btw) but I just can't recall them atm.

Hope it helps

thanks alot. that what im doing right now. im using barbar with that functionality.

xsteadfastx avatar Jan 11 '22 11:01 xsteadfastx

I have the same issue, as soon as the trouble window is toggled, :bd closes all my open buffers. I do not have auto_close on.

sledigabel avatar Jan 12 '22 14:01 sledigabel

i have the same issure here. i can reproduce it, so if you need more info let me know.

nvim.log

any update on this? attached you can find the verbose (level 20) log.

bd execution is tracked from line:

1328 Executing: bd

if i do :TroubleClose and then :bd, vim stays open. the issue seems to be related to Trouble plugin.

my Trouble configuration is:

require("trouble").setup {
    icons = false,
    auto_open = true,
    position = "right",
    mode = "document_diagnostics", -- "workspace_diagnostics", "", "quickfix", "lsp_references", "loclist"
  }

changing mode and auto_open does not solve the issue, so it might not be something lsp related.

francescop avatar Mar 25 '22 14:03 francescop

the problem appears to be that :bd closes the window. same thing appen if you :vsplit and then :bd. i don't think it's a plugin problem then.

showing the diagnostic messages in a floating window might be a workaround, but not sure that's an optimal solution / worth investigating.

francescop avatar Mar 29 '22 20:03 francescop

I seem to have this issue too and it ONLY happens when I have the trouble window open. closing a buffer with :bd under any other circumstances seems to work fine and Neovim stays alive, but if I have the trouble window open, it quits. I can't seem to figure out why. I really like this plugin and don't want to get rid of it, but might have to if i can find a solution. Has anyone else run into this and come up with a solution that works?

nerdo avatar Jan 10 '23 04:01 nerdo

btw, my full neovim setup: https://github.com/nerdo/personal-settings/tree/dcdd503d03fe65b2146ccbc08c588ff454fcea4d

nerdo avatar Jan 10 '23 05:01 nerdo

I forgot an important fact.

So I've got trouble set up to where it automatically goes back to the previous buffer when it's toggled open because I have mappings to navigate prev/next and rarely need to be focused in the Trouble window itself, so when I'm doing :bd it's not when Im in the Trouble buffer, always from a file buffer.

Side note: I undid that auto :bp behavior as a test and when I manually move back into the file buffer, I get the same behavior (:bd will result in neovim exiting), but if Trouble wasn't open, just that buffer closes, which is the expected behavior even when Trouble is open.

nerdo avatar Jan 10 '23 05:01 nerdo

Did anyone find a solution to this?

gilice avatar Mar 04 '23 14:03 gilice

had this issue but moved on. i solved it with some custom code that does more or less the same thing - or at least, does what i need.

this is what i did, just in case this could help someone.

i have this in my init.lua file.

-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
  ...

  -- custom toggle
  buf_set_keymap('n', ',b', '<cmd>lua toggle_lsp_quicklist()<CR>', opts)

  -- default enable lsp quickfix list
  vim.g['custom#lsp_show'] = true
end
function toggle_lsp_quicklist()
    vim.g['custom#lsp_show'] = not vim.g['custom#lsp_show']
    if vim.g['custom#lsp_show'] then
      vim.cmd([[copen]])
      vim.cmd([[wincmd p]])
    else
      vim.cmd([[cclose]])
    end
end

-- Enable diagnostics
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    virtual_text = true,
		underline = true,
    signs = true,
    update_in_insert = false,
  }
)

-- Send diagnostics to quickfix list
do
  local method = "textDocument/publishDiagnostics"
  local default_handler = vim.lsp.handlers[method]
  vim.lsp.handlers[method] = function(err, method, result, client_id, bufnr, config)
  default_handler(err, method, result, client_id, bufnr, config)
  local diagnostics = vim.diagnostic.get()
  local qflist = {}
    for bufnr, diagnostic in pairs(diagnostics) do
      for _, d in ipairs(diagnostic) do
        d.bufnr = bufnr
        d.lnum = d.range.start.line + 1
        d.col = d.range.start.character + 1
        d.text = d.message
        table.insert(qflist, d)
      end
    end
    if vim.g['custom#lsp_show'] then
      vim.diagnostic.setqflist(qflist)
      vim.cmd([[wincmd p]])
    end
  end
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright', 'tsserver', 'cssls', 'jsonls', 'bashls', 'yamlls', 'solargraph', 'svelte', 'gopls', 'zls', 'ocamllsp', 'nimls', "serve_d" }
for _, lsp in ipairs(servers) do
  nvim_lsp[lsp].setup(
  coq.lsp_ensure_capabilities{
  on_attach = on_attach,
  flags = {
    debounce_text_changes = 150,
    }
  })
end

francescop avatar Mar 04 '23 16:03 francescop

This is such a weird issue 🤔

My setup is very simple:

  {
    'folke/trouble.nvim',
    config = function()
      require('trouble').setup({
        icons = false,
      })
      vim.keymap.set('n', '<leader>xx', function() require('trouble').open() end)
      vim.keymap.set('n', '<leader>xw', function() require('trouble').open('workspace_diagnostics') end)
      vim.keymap.set('n', '<leader>xd', function() require('trouble').open('document_diagnostics') end)
    end,
  },

And this only happen with trouble.nvim as far as I can tell. It doesn't happen for me with :vsplit, as @francescop suggested.

In case it helps, this is my config: https://github.com/gil/dotfiles/blob/9b8a4b07f9e892de4141e58ec8cde67fafc1253e/vim/init.lua

gil avatar Aug 07 '23 15:08 gil

I have the same issue... I thought vim was crashing, but now I get that this is what happens to me. Any workaround?

diegodorado avatar Nov 28 '23 18:11 diegodorado

Development on the main branch is EOL.

Trouble has been rewritten and will be merged in main soon.

This issue/feature either no longer exists or has been implemented on dev.

For more info, see https://github.com/folke/trouble.nvim/tree/dev

folke avatar Mar 29 '24 07:03 folke