mirror of
https://github.com/mfussenegger/nvim-dap
synced 2024-09-16 14:24:03 +02:00
Add DapEval command
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 https://github.com/mfussenegger/nvim-dap/issues/665
This commit is contained in:
parent
fc1f7950c5
commit
7122fd5848
1 changed files with 37 additions and 0 deletions
|
@ -68,6 +68,43 @@ 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
|
||||
local size = math.max(5, math.floor(vim.o.lines * 1/5))
|
||||
vim.cmd.split({name, mods = params.smods, range = { size }})
|
||||
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,
|
||||
bar = 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 })
|
||||
|
|
Loading…
Reference in a new issue