mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 11:18:26 +00:00
fix(debug.run): schedule only nvim_buf_set_extmark in on_print (#425)
## Description <!-- Describe the big picture of your changes to communicate to the maintainers why we should accept this pull request. --> Previously, `get_line` was called from a scheduled function, and would always return nil, placing the extmark for print output on the wrong line. ## Screenshots <!-- Add screenshots of the changes if applicable. --> Before:  After:  Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
parent
f904481439
commit
81572b5f97
1 changed files with 8 additions and 4 deletions
|
@ -131,9 +131,13 @@ function M.run(opts)
|
|||
for _, line in ipairs(vim.split(str, "\n", { plain = true })) do
|
||||
table.insert(virt_lines, { { " │ ", "SnacksDebugIndent" }, { line, "SnacksDebugPrint" } })
|
||||
end
|
||||
vim.api.nvim_buf_set_extmark(buf, ns, (get_line() or 1) - 1, 0, {
|
||||
virt_lines = virt_lines,
|
||||
})
|
||||
|
||||
local line = (get_line() or 1) - 1
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_buf_set_extmark(buf, ns, line, 0, {
|
||||
virt_lines = virt_lines,
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
-- Load the code
|
||||
|
@ -143,7 +147,7 @@ function M.run(opts)
|
|||
end
|
||||
|
||||
-- Setup the env
|
||||
local env = { print = opts.print and vim.schedule_wrap(on_print) or nil }
|
||||
local env = { print = opts.print and on_print or nil }
|
||||
package.seeall(env)
|
||||
setfenv(chunk, env)
|
||||
xpcall(chunk, function(e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue