nvim-dap-ui
nvim-dap-ui copied to clipboard
open dap-ui in a new buffer opposed to splits in the current tab
Dear Sir , I respect your effort in making this plugin
I feel it would be better if i can open the dap-ui elements in a new tab instead of the current tab
Thank you
You can do this manually, there's no need for nvim-dap-ui to control this. For example
local debug_win = nil
local function open_in_tab()
if debug_win and vim.api.nvim_win_is_valid(debug_win) then
vim.api.nvim_set_current_win(debug_win)
return
end
vim.cmd("tabedit %")
debug_win = vim.fn.win_getid()
require("dapui").open()
end
dap.listeners.after["event_thread"]["arctgx-dap-tab"] = function(_, body)
if body.reason == "started" then
open_in_tab()
end
end
I agree with this being the default behaviour, it makes sense to have debugging in a new workspace/tab and coming back to your developing workspace/tab after you are finished debugging. That being said, it's no big deal given we can just configure it as @rcarriga said 😃
Also, for any interested parties, I have a more complete solution here that seems to work:
local dap_ui = require("dapui")
local debug_win = nil
local debug_tab = nil
local function open_in_tab()
if debug_win and vim.api.nvim_win_is_valid(debug_win) then
vim.api.nvim_set_current_win(debug_win)
return
end
vim.cmd("tabedit %")
debug_win = vim.fn.win_getid()
debug_tab = vim.api.nvim_win_get_tabpage(debug_win)
dap_ui.open()
end
local function close_tab()
dap_ui.close()
if debug_tab and vim.api.nvim_tabpage_is_valid(debug_tab) then
vim.api.nvim_exec("tabclose " .. debug_tab, false)
end
debug_win = nil
debug_tab = nil
end
-- Attach DAP UI to DAP events
dap.listeners.after.event_initialized["dapui_config"] = function()
open_in_tab()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
close_tab()
end
dap.listeners.before.event_exited["dapui_config"] = function()
close_tab()
end
I was looking for this sort of functionality to prevent clutter and window resizing when activating dapui. Thanks @serhez, saved me some time setting this up myself but I've gotten some errors with your code.
I'm unsure if this is an oddity of my personal config or an oversight. Do you not experience the following error on subsequent launches of the debugger?
When first running the close_tab
function, everything is good but on subsequent runs tabclose
returning the following error.
Error executing vim.schedule lua callback: /home/daephx/.config/nvim/lua/plugins/dap/ui.lua:92: Vim(tabclose):E474: Invalid argument: tabclose 8
stack traceback:
[C]: in function 'nvim_exec'
/home/daephx/.config/nvim/lua/plugins/dap/ui.lua:92: in function 'close_tab'
/home/daephx/.config/nvim/lua/plugins/dap/ui.lua:107: in function 'c'
...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:857: in function <...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:853>
The tabpage value increments over time with multiple tab pages and tabclose
seems to require the tab number.
Shouldn't there be something like another variable to get the tab number to prevent this?:
local debug_win = nil
local debug_tab = nil
local debug_tabnr = nil
local function open_in_tab()
if debug_win and vim.api.nvim_win_is_valid(debug_win) then
vim.api.nvim_set_current_win(debug_win)
return
end
vim.cmd('tabedit %')
debug_win = vim.fn.win_getid()
debug_tab = vim.api.nvim_win_get_tabpage(debug_win)
debug_tabnr = vim.api.nvim_tabpage_get_number(debug_tab)
dapui.open()
end
local function close_tab()
dapui.close()
if debug_tab and vim.api.nvim_tabpage_is_valid(debug_tab) then
vim.api.nvim_exec('tabclose ' .. debug_tabnr, false)
end
debug_win = nil
debug_tab = nil
debug_tabnr = nil
end
-- Attach DAP UI to DAP events
dap.listeners.after.event_initialized['dapui_config'] = function()
open_in_tab()
end
dap.listeners.before.event_terminated['dapui_config'] = function()
close_tab()
end
dap.listeners.before.event_exited['dapui_config'] = function()
close_tab()
end
This works for me without any errors.