Skip to content

Commit

Permalink
repl: Avoid interleaved prompt in expression output
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Aug 5, 2022
1 parent 172d4b1 commit 4f63bda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
24 changes: 21 additions & 3 deletions lua/dap/repl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,28 @@ local function evaluate_handler(err, resp)
local layer = ui.layer(repl.buf)
local attributes = (resp.presentationHint or {}).attributes or {}
if resp.variablesReference > 0 or vim.tbl_contains(attributes, 'rawString') then
local tree = ui.new_tree(require('dap.entity').variable.tree_spec)
tree.render(layer, resp)
local spec = require('dap.entity').variable.tree_spec
local tree = ui.new_tree(spec)
-- tree.render would "append" twice, once for the top element and once for the children
-- Appending twice would result in a intermediate "dap> " prompt
-- To avoid that this eagerly fetches the children; pre-renders the region
-- and lets tree.render override it
if spec.has_children(resp) then
spec.fetch_children(resp, function()
local lnum = api.nvim_buf_line_count(repl.buf) - 1
local lines = {''}
for _ = 1, #resp.variables do
table.insert(lines, '')
end
api.nvim_buf_set_lines(repl.buf, -1, -1, true, lines)
tree.render(layer, resp, nil, lnum, -1)
end)
else
tree.render(layer, resp)
end
else
layer.render(vim.split(resp.result, '\n', { trimempty = true }))
local lines = vim.split(resp.result, '\n', { trimempty = true })
layer.render(lines)
end
end

Expand Down
7 changes: 5 additions & 2 deletions lua/dap/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ function M.new_tree(opts)
end
end,

render = function(layer, value, on_done)
layer.render({value}, opts.render_parent)
render = function(layer, value, on_done, lnum, end_)
layer.render({value}, opts.render_parent, nil, lnum, end_)
if not opts.has_children(value) then
if on_done then
on_done()
Expand Down Expand Up @@ -474,6 +474,9 @@ function M.layer(buf)
-- the loop below will add the actual values
local lines = vim.tbl_map(function() return '' end, xs)
api.nvim_buf_set_lines(buf, start, end_, true, lines)
if start == -1 then
start = api.nvim_buf_line_count(buf) - #lines
end

for i = start, start + #lines - 1 do
local item = xs[i + 1 - start]
Expand Down

0 comments on commit 4f63bda

Please sign in to comment.