rcarriga / nvim-dap-ui

A UI for nvim-dap
MIT License
2.67k stars 99 forks source link

Closing dap-ui while repl is in insert mode breaks vim #208

Closed jaghaimo closed 1 year ago

jaghaimo commented 1 year ago

https://github.com/rcarriga/nvim-dap-ui/issues/188#issuecomment-1354291183 mentioned this is caused by setting console to integratedTerminal, which nvim-dap-python does.

Steps to reproduce:

rcarriga commented 1 year ago

Afraid I can't reproduce. Can you create a minimal init.lua?

Here's a starter one nvim --clean -u min.lua

-- ignore default config and plugins
vim.opt.runtimepath:remove(vim.fn.stdpath("config"))
vim.opt.packpath:remove(vim.fn.stdpath("data") .. "/site")
vim.opt.termguicolors = true
vim.opt.laststatus = 0

-- append test directory
local test_dir = "/tmp/nvim-config"
vim.opt.runtimepath:append(vim.fn.expand(test_dir))
vim.opt.packpath:append(vim.fn.expand(test_dir))

-- install packer
local install_path = test_dir .. "/pack/packer/start/packer.nvim"
local install_plugins = false

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.cmd("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
  vim.cmd("packadd packer.nvim")
  install_plugins = true
end

local packer = require("packer")

packer.init({
  package_root = test_dir .. "/pack",
  compile_path = test_dir .. "/plugin/packer_compiled.lua",
})

packer.startup(function(use)
  -- Packer can manage itself
  use("wbthomason/packer.nvim")

  use({ "mfussenegger/nvim-dap" })

  use({
    "rcarriga/nvim-dap-ui",
    requires = "mfussenegger/nvim-dap",
    config = function()
      require("dapui").setup({})
    end,
  })

  if install_plugins then
    packer.sync()
  end
end)

vim.cmd([[
command! DapUIToggle lua require("dapui").toggle()
]])
jaghaimo commented 1 year ago

I tried adding nvim-dap-python to the minimal config, but couldn't make it working. The problem occurs for adapters that set console to intergratedTerminal (https://github.com/mfussenegger/nvim-dap/blob/master/doc/dap.txt#L526) and won't happen without starting a debug session first. Afterwards, no active debug session is needed to trigger it.

I'll try expanding your config a bit more and see if I can make it work.

Edit: I give up. I have removed neotest from my LunarVim config, and now I no longer have this issue. It is some odd conflict between multiple plugins - happy to close...

siraphobk commented 1 year ago

I'm having the same issue. I believe it's the conflict between the plugins that causes this problem.

To work around on this, I force dapui.setup() every time I close the debug session.

local dap = require("dap")
local dapui = require("dapui")

local config = {
  layouts = {
    {
      elements = {
        { id = "scopes", size = 0.25 },
        "breakpoints",
        "stacks",
        "watches",
      },
      size = 40,
      position = "left",
    },
    {
      elements = { "repl" },
      size = 0.25, -- 25% of total lines
      position = "bottom",
    },
  },
}

dapui.setup(config)

dap.listeners.after.event_initialized["dapui_config"] = function()
  dapui.open({
    reset = true,
  })
end

dap.listeners.before.event_terminated["dapui_config"] = function()
  dapui.close({})
  dapui.setup(config)
end

dap.listeners.before.event_exited["dapui_config"] = function()
  dapui.close({})
  dapui.setup(config)
end

My investigation

I use 'kevinhwang91/nvim-ufo' which requires 'kevinhwang91/promise-async'. By disabling both plugins, the problem seems to disappear. So I believe these plugins might cause the conflict.

Moreover, I tried disabling dapui.close on terminated/exited and the problem still persisted.

rcarriga commented 1 year ago

Interesting that it seems to be a conflict between plugins. nvim-dap-ui an neotest both use an async framework that should be compatible (but also should never need to interact) whereas promise-async is a completely different style.

I am using all of these plugins without issue so unfortunately I can't debug further. @siraphobk are you able to reproduce using a minimal init.lua?

siraphobk commented 1 year ago

@rcarriga I might be wrong about those plugin conflicts tho. However, I'll try to setup using a minimal init.lua and will post it here.

rcarriga commented 1 year ago

I believe this was due to a neovim core bug, and has been fixed in nightly (possibly 9.1). Closing this but let me know if it's still an issue