Skip to content

Commit 40e36bf

Browse files
committed
feat: only add expr if not present
1 parent 7d1daf0 commit 40e36bf

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lua/dap-view/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ end
7373
M.add_expr = function()
7474
local expression = expr.eval_expression()
7575

76-
table.insert(state.watched_expressions, expression)
76+
require("dap-view.watches.actions").add_watch_expr(expression)
7777

7878
require("dap-view.watches.view").show()
7979
end

lua/dap-view/options/settings.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ M.set_keymaps = function()
3232
vim.keymap.set("n", "i", function()
3333
if state.current_section == "watches" then
3434
vim.ui.input({ prompt = "Expression: " }, function(input)
35-
if input and #input > 0 then
36-
table.insert(state.watched_expressions, input)
35+
if input then
36+
require("dap-view.watches.actions").add_watch_expr(input)
3737

3838
require("dap-view.watches.view").show()
3939
end

lua/dap-view/watches/actions.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local state = require("dap-view.state")
2+
3+
local M = {}
4+
5+
---@param expr string
6+
M.add_watch_expr = function(expr)
7+
-- Avoid duplicate expressions
8+
local can_add = #expr > 0 and not vim.tbl_contains(state.watched_expressions, expr)
9+
if can_add then
10+
table.insert(state.watched_expressions, expr)
11+
end
12+
return can_add
13+
end
14+
15+
return M

0 commit comments

Comments
 (0)