Skip to content

Commit

Permalink
Add DapEval command
Browse files Browse the repository at this point in the history
Creates a new window with a `dap-eval://` scratch buffer
Supports range mode to pre-fill it with the selected content.
Supports bang to immediately evaluate the content

This is a variant addressing #665
  • Loading branch information
mfussenegger committed Jun 1, 2024
1 parent fc1f795 commit 9d835d3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions plugin/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,41 @@ cmd("DapNew", dapnew, {
end
})

cmd("DapEval", function(params)
local oldbuf = api.nvim_get_current_buf()
local name = string.format("dap-eval://%s", vim.bo[oldbuf].filetype)
if params.smods.vertical then
vim.cmd.vsplit({name})
elseif params.smods.tab == 1 then
vim.cmd.tabedit(name)
else
vim.cmd.split({name, mods = params.smods})
end
local newbuf = api.nvim_get_current_buf()
if params.range ~= 0 then
local lines = api.nvim_buf_get_lines(oldbuf, params.line1 -1 , params.line2, true)
local indent = math.huge
for _, line in ipairs(lines) do
indent = math.min(line:find("[^ ]") or math.huge, indent)
end
if indent ~= math.huge and indent > 0 then
for i, line in ipairs(lines) do
lines[i] = line:sub(indent)
end
end
api.nvim_buf_set_lines(newbuf, 0, -1, true, lines)
vim.bo[newbuf].modified = false
end
if params.bang then
vim.cmd.w()
end
end, {
nargs = 0,
range = "%",
bang = true,
desc = "Create a new window & buffer to evaluate expressions",
})


if api.nvim_create_autocmd then
local launchjson_group = api.nvim_create_augroup('dap-launch.json', { clear = true })
Expand Down

0 comments on commit 9d835d3

Please sign in to comment.