Skip to content

Commit b94ed42

Browse files
authored
fix(DapViewWatch): switch to Watcher view when repl active (#8)
* fix: when using DapViewWatch on current position with repl showing, switch to Watcher view * ref: use nvim_set_current_buf to set buffer for winnr * ref(watcher): when adding watcher expression check if window is valid before switching view * ref: add window id checks when switching views * ref: removes redundant function wraps for callback argument
1 parent 73e2ecf commit b94ed42

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

lua/dap-view/actions.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ end
8282

8383
M.add_expr = function()
8484
local expression = expr.eval_expression()
85-
8685
require("dap-view.watches.actions").add_watch_expr(expression)
8786

88-
require("dap-view.watches.view").show()
87+
require("dap-view.views").switch(require("dap-view.watches.view").show)
8988
end
9089

9190
return M

lua/dap-view/breakpoints/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ M._jump_to_breakpoint = function()
5858
if bufnr == -1 then
5959
vim.cmd("buffer " .. abs_path)
6060
else
61-
vim.cmd("buffer " .. bufnr)
61+
api.nvim_set_current_buf(bufnr)
6262
end
6363
end)
6464

lua/dap-view/options/winbar.lua

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ local winbar_info = {
99
keymap = "B",
1010
action = function()
1111
if vim.tbl_contains(setup.config.winbar.sections, "breakpoints") then
12-
require("dap-view.views").switch(function()
13-
require("dap-view.breakpoints.view").show()
14-
end)
12+
require("dap-view.views").switch(require("dap-view.breakpoints.view").show)
1513
end
1614
end,
1715
},
@@ -20,9 +18,7 @@ local winbar_info = {
2018
keymap = "E",
2119
action = function()
2220
if vim.tbl_contains(setup.config.winbar.sections, "exceptions") then
23-
require("dap-view.views").switch(function()
24-
require("dap-view.exceptions.view").show()
25-
end)
21+
require("dap-view.views").switch(require("dap-view.exceptions.view").show)
2622
end
2723
end,
2824
},
@@ -31,9 +27,7 @@ local winbar_info = {
3127
keymap = "W",
3228
action = function()
3329
if vim.tbl_contains(setup.config.winbar.sections, "watches") then
34-
require("dap-view.views").switch(function()
35-
require("dap-view.watches.view").show()
36-
end)
30+
require("dap-view.views").switch(require("dap-view.watches.view").show)
3731
end
3832
end,
3933
},

lua/dap-view/views/init.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ M.cleanup_view = function(cond, message)
2727
end
2828

2929
local switch_to_dapview_buf = function()
30+
if not (state.winnr and api.nvim_win_is_valid(state.winnr)) then
31+
return
32+
end
3033
-- The REPL is actually another buffer
3134
if state.current_section == "repl" then
32-
vim.cmd("buffer " .. state.bufnr)
35+
api.nvim_win_call(state.winnr, function()
36+
api.nvim_set_current_buf(state.bufnr)
37+
end)
3338
end
3439
end
3540

0 commit comments

Comments
 (0)