Skip to content

Commit 75a94b8

Browse files
authored
Fix lines in scope widget appearing under wrong group (#889)
When dap.ui.Layer.render is called with start == nil and end_ == nil, assign start = 0 only when the buffer contains a single, empty line. For all other cases, assign start == line-count instead of start == line-count - 1, which appears to be causing the line swapping issue. Add a simple test case where the buffer already contains non-empty lines, and a new line is added with start == nil and end_ == nil, which should now be appended to the end.
1 parent c1bfcd8 commit 75a94b8

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lua/dap/ui.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,13 @@ function M.layer(buf)
466466
local modifiable = api.nvim_buf_get_option(buf, 'modifiable')
467467
api.nvim_buf_set_option(buf, 'modifiable', true)
468468
if not start and not end_ then
469-
start = api.nvim_buf_line_count(buf) - 1
469+
start = api.nvim_buf_line_count(buf)
470470
-- Avoid inserting a new line at the end of the buffer
471471
-- The case of no lines and one empty line are ambiguous;
472472
-- set_lines(buf, 0, 0) would "preserve" the "empty buffer line" while set_lines(buf, 0, -1) replaces it
473473
-- Need to use regular end_ = start in other cases to support injecting lines in all other cases
474-
if start == 0 and (api.nvim_buf_get_lines(buf, 0, -1, true))[1] == "" then
474+
if start == 1 and (api.nvim_buf_get_lines(buf, 0, -1, true))[1] == "" then
475+
start = 0
475476
end_ = -1
476477
else
477478
end_ = start

tests/ui_spec.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ describe('ui', function()
6262
assert.are.same('bbbb', layer.get(2).item.label)
6363
assert.are.same('', layer.get(3).item.label)
6464
end)
65+
66+
it('can append at the end', function()
67+
layer.render({{ label = "e" }}, render_item, nil, nil, nil)
68+
local lines = api.nvim_buf_get_lines(buf, 0, -1, true)
69+
assert.are.same({
70+
'aa',
71+
'bbb',
72+
'bbbb',
73+
'',
74+
'dd',
75+
'e',
76+
}, lines)
77+
assert.are.same('dd', layer.get(4).item.label)
78+
assert.are.same('e', layer.get(5).item.label)
79+
end)
6580
end)
6681

6782
local opts = {

0 commit comments

Comments
 (0)