Skip to content

Commit 70cd169

Browse files
committed
Freeze expr provided to preview widget
Closes #1163
1 parent 95913f0 commit 70cd169

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lua/dap/ui.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ local if_nil = utils.if_nil
44
local M = {}
55

66

7+
---@param win integer
8+
---@param opts table<string, any>?
79
function M.apply_winopts(win, opts)
8-
if not opts then return end
10+
if not opts then
11+
return
12+
end
913
assert(
1014
type(opts) == 'table',
1115
'winopts must be a table, not ' .. type(opts) .. ': ' .. vim.inspect(opts)

lua/dap/ui/widgets.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ function M.builder(widget)
515515
end
516516

517517

518+
---@param expr nil|string|fun():string
519+
---@return string
518520
local function eval_expression(expr)
519521
local mode = api.nvim_get_mode()
520522
if mode.mode == 'v' then
@@ -544,12 +546,14 @@ local function eval_expression(expr)
544546
expr = expr or '<cexpr>'
545547
if type(expr) == "function" then
546548
return expr()
547-
elseif type(expr) == "string" then
549+
else
548550
return vim.fn.expand(expr)
549551
end
550552
end
551553

552554

555+
---@param expr nil|string|fun():string
556+
---@param winopts table<string, any>?
553557
function M.hover(expr, winopts)
554558
local value = eval_expression(expr)
555559
local view = M.builder(M.expression)
@@ -623,6 +627,7 @@ function M.preview(expr, opts)
623627
.new_win(new_preview_win)
624628
.build()
625629
view.open(value)
630+
view.__expression = value
626631
return view
627632
end
628633

0 commit comments

Comments
 (0)