Open shmerl opened 1 month ago
I think it's due to this: https://github.com/rcarriga/nvim-dap-ui/blob/b7267003ba4dd860350be86f75b9d9ea287cedca/lua/dapui/util.lua#L41
local start = nio.fn.getpos("v")
local finish = nio.fn.getpos(".")
local lines = M.get_selection(start, finish)
i.e. finish is the cursor position, but with set selection=exclusive
, cursor is not included in the selection, so that creates a mismatch.
'selection' 'sel' string (default "inclusive")
global
This option defines the behavior of the selection. It is only used
in Visual and Select mode.
Possible values:
value past line inclusive
old no yes
inclusive yes yes
exclusive yes no
...
"inclusive" means that the last character of the selection is included
in an operation. For example, when "x" is used to delete the
selection.
Hmm. looks like there is a builtin for that now, that handles exclusive / inclusive logic automatically:
:help getregion
OK, we are getting somewhere:
vim.fn.getregion(vim.fn.getpos('v'), vim.fn.getpos('.'))[1]
That returns the first string in the list (it breaks up selection by lines I think?)
UPDATE:
This combines the result into a single string separated by endlines:
table.concat(vim.fn.getregion(vim.fn.getpos("v"), vim.fn.getpos(".")), "\n")
Final result for lua configuration that works around the bug:
vim.keymap.set('v', '<M-k>', function() require("dapui").eval(table.concat(vim.fn.getregion(vim.fn.getpos("v"), vim.fn.getpos(".")), "\n")) end)
I have such configuration for my selection:
So when I select some text for example
ab
fromabc
in the visual modenvim dap ui when calling eval with
<M-k>
(mapping enabled withvnoremap <M-k> <Cmd>lua require("dapui").eval()<CR>
), picks one extra symbol, i.e.abc
, instead ofab
. I think the issue is withget_current_expr
.