Skip to content

Commit

Permalink
Freeze expr provided to preview widget
Browse files Browse the repository at this point in the history
Closes #1163
  • Loading branch information
mfussenegger committed Dec 6, 2024
1 parent cc8787d commit 580d6e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lua/dap/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ local if_nil = utils.if_nil
local M = {}


---@param win integer
---@param opts table<string, any>?
function M.apply_winopts(win, opts)
if not opts then return end
if not opts then
return
end
assert(
type(opts) == 'table',
'winopts must be a table, not ' .. type(opts) .. ': ' .. vim.inspect(opts)
Expand Down
8 changes: 7 additions & 1 deletion lua/dap/ui/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ function M.builder(widget)
end


---@param expr nil|string|fun():string
---@return string
local function eval_expression(expr)
local mode = api.nvim_get_mode()
if mode.mode == 'v' then
Expand Down Expand Up @@ -544,12 +546,14 @@ local function eval_expression(expr)
expr = expr or '<cexpr>'
if type(expr) == "function" then
return expr()
elseif type(expr) == "string" then
else
return vim.fn.expand(expr)
end
end


---@param expr nil|string|fun():string
---@param winopts table<string, any>?
function M.hover(expr, winopts)
local value = eval_expression(expr)
local view = M.builder(M.expression)
Expand Down Expand Up @@ -582,6 +586,7 @@ end

--- View the value of the expression under the cursor in a preview window
---
---@param expr nil|string|fun():string
---@param opts? {listener?: string[]}
function M.preview(expr, opts)
opts = opts or {}
Expand Down Expand Up @@ -623,6 +628,7 @@ function M.preview(expr, opts)
.new_win(new_preview_win)
.build()
view.open(value)
view.__expression = value
return view
end

Expand Down

0 comments on commit 580d6e5

Please sign in to comment.