Skip to content

Commit 3953824

Browse files
rcarrigaRónán Carrigan
authored andcommitted
fix(repl): handle REPL buffer being deleted
See #218
1 parent e26fba0 commit 3953824

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lua/dapui/elements/repl.lua

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,36 @@ return function()
1010
--- The REPL provided by nvim-dap.
1111
dapui.elements.repl = {}
1212

13-
-- TODO: All of this is a hack because of an error with indentline when buffer
14-
-- is opened in a window so have to manually find the window that was opened.
15-
local all_wins = async.api.nvim_list_wins()
16-
local open_wins = {}
17-
for _, win in pairs(all_wins) do
18-
open_wins[win] = true
19-
end
20-
21-
pcall(dap.repl.open, {})
13+
local function get_buffer()
14+
-- TODO: All of this is a hack because of an error with indentline when buffer
15+
-- is opened in a window so have to manually find the window that was opened.
16+
local all_wins = async.api.nvim_list_wins()
17+
local open_wins = {}
18+
for _, win in pairs(all_wins) do
19+
open_wins[win] = true
20+
end
21+
pcall(dap.repl.open, {})
2222

23-
local buf = async.fn.bufnr("dap-repl")
23+
local buf = async.fn.bufnr("dap-repl")
2424

25-
for _, win in ipairs(async.api.nvim_list_wins()) do
26-
if not open_wins[win] then
27-
pcall(async.api.nvim_win_close, win, true)
28-
break
25+
for _, win in ipairs(async.api.nvim_list_wins()) do
26+
if not open_wins[win] then
27+
pcall(async.api.nvim_win_close, win, true)
28+
break
29+
end
2930
end
31+
return buf
3032
end
3133

34+
local buf
3235
---@nodoc
3336
function dapui.elements.repl.render() end
3437

3538
---@nodoc
3639
function dapui.elements.repl.buffer()
40+
if not async.api.nvim_buf_is_valid(buf or -1) then
41+
buf = get_buffer()
42+
end
3743
return buf
3844
end
3945

0 commit comments

Comments
 (0)