Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
176420f
implement optional argnodes.
L3MON4D3 Dec 28, 2023
bd09791
implement subtree_do, invokes callbacks on tree of nodes (in a snippet).
L3MON4D3 Mar 4, 2024
5fdf9d8
make resolve_position work for static snippets.
L3MON4D3 Mar 4, 2024
aa1b233
fix: make root_path work for snippets.
L3MON4D3 Mar 4, 2024
b5d2a34
implement subtree_leave_entered, for leaving only entered nodes.
L3MON4D3 May 5, 2025
b1f3492
overhaul snippet-updates.
L3MON4D3 Nov 3, 2025
b419d9a
make sure visible is set on -1-node.
L3MON4D3 Mar 10, 2024
83c7649
propery remove child-snippets when `:exit`ing.
L3MON4D3 Apr 23, 2024
61bf611
exitNode: use same update_dependents as all other nodes.
L3MON4D3 Apr 23, 2024
c295b3f
update after snip_expand.
L3MON4D3 Oct 14, 2025
719d55c
Format with stylua
L3MON4D3 Oct 14, 2025
09217d6
Make insertNode correctly handle static_text if it's a snippetString.
L3MON4D3 Oct 28, 2024
3be6031
allow using snippet_string as dynamicNode-args.
L3MON4D3 Oct 28, 2024
a35adb8
restoreNode,insertNode: propagate store.
L3MON4D3 Oct 29, 2024
d4abde8
dynamicNode.update: store snippet before evaluating fn.
L3MON4D3 Oct 29, 2024
4ca232e
dynamicNode.update: copy extmarks after focusing.
L3MON4D3 Oct 29, 2024
3225dd1
dynamicNode.update: do update_restore instead of update.
L3MON4D3 Oct 29, 2024
45df41e
restoreNode: don't store on exit, store should have been called before.
L3MON4D3 Oct 29, 2024
888ac5e
add some tests for new restoreNode-behaviour.
L3MON4D3 Oct 29, 2024
722251d
choiceNode: correctly refocus when current_node is in another snippet.
L3MON4D3 Oct 29, 2024
7d8140c
we don't want to go into adjacent snippetNodes, but land between them.
L3MON4D3 Oct 29, 2024
5441143
snippet: correctly propagate exit to child_snippets (and clear them).
L3MON4D3 Oct 29, 2024
b63fb1f
add another test for the new restoreNode.
L3MON4D3 Oct 29, 2024
d4b8110
store content of nested snippets before capturing argnode.
L3MON4D3 Oct 29, 2024
508cc3f
make sure marks are invalidated even for nested snippets.
L3MON4D3 Oct 29, 2024
d40fc8a
get_args: `store` only when calling in static mode.
L3MON4D3 Oct 29, 2024
5192bf9
snippetstring: store strings as \n-separated string.
L3MON4D3 Oct 14, 2025
87ad057
small refactor.
L3MON4D3 Oct 30, 2024
fc7e586
implement a few simple string-operations on snippetString.
L3MON4D3 Oct 30, 2024
c5cfc00
fix flakiness in test.
L3MON4D3 Oct 30, 2024
3f7ce76
update: try to find new active node in child-snippet.
L3MON4D3 Oct 30, 2024
befdc53
allow replacing parts of a snippetString with other text.
L3MON4D3 Nov 2, 2024
6ee05ef
implement gsub on snippetString.
L3MON4D3 Nov 2, 2024
de371f5
snippetstring.replace: fix substitution in textNode.
L3MON4D3 Nov 2, 2024
7c34402
fix switchup.
L3MON4D3 Nov 2, 2024
b9313e2
make in-place modifying functions private.
L3MON4D3 Nov 2, 2024
80be0c4
add :sub to snippetString.
L3MON4D3 Nov 2, 2024
bea1bb7
add `opt` for the optional argument.
L3MON4D3 Nov 3, 2024
5f476e4
correctly store+restore visual selection during update.
L3MON4D3 Nov 3, 2024
24edd78
fNode: always store result in static_text.
L3MON4D3 Nov 4, 2024
4d25da0
update_dependents: get cursor-position after queried movements.
L3MON4D3 Nov 4, 2024
25ef218
move the jump_active-check into the autocommand.
L3MON4D3 Oct 14, 2025
79b336c
optionally update a node differnt from the current node.
L3MON4D3 Oct 14, 2025
e0ee698
update_dependents: use update_restore by default.
L3MON4D3 Nov 4, 2024
79722c5
choiceNode: call update_dependents after routine is done completely.
L3MON4D3 Nov 4, 2024
67b99dc
move no_region_wrap back into main-module.
L3MON4D3 Oct 14, 2025
fcfb058
dynamicNode/restoreNode: don't destroy snip on exit.
L3MON4D3 Nov 4, 2024
5123fde
handle selection on first line and column of buffer with `before`.
L3MON4D3 Nov 4, 2024
ad85601
document imperfect behaviour asserted by test.
L3MON4D3 Nov 4, 2024
482f0bf
export optional_arg as opt for tests.
L3MON4D3 Nov 4, 2024
d96028f
set jump_active=false ASAP.
L3MON4D3 Nov 4, 2024
28c1300
choiceNode: explicitly set parent and pos for choices.
L3MON4D3 Nov 6, 2024
a8e340c
fix(dynamicNode): don't access .snip in update_static.
L3MON4D3 Nov 6, 2024
98ed158
dynamicNode: optionally use .snip to generate docstring.
L3MON4D3 Nov 6, 2024
acec69f
enqueue cursor-movement due to update in typeahead.
L3MON4D3 Nov 6, 2024
2c5300f
get_args: do (static_)visible-check in get_args, not get_static_text.
L3MON4D3 Nov 6, 2024
d69df12
test docstring-generation with self-dependent dynamicNode.
L3MON4D3 Nov 6, 2024
24b925e
properly restore cursor-position in set_choice.
L3MON4D3 Nov 7, 2024
d3a7709
change_choice: use cursor-restore system from update_dependents.
L3MON4D3 Oct 14, 2025
37b963a
snippet_string: add metadata and marks.
L3MON4D3 Nov 13, 2024
eed721c
store cursor-position in snippetString to more accurately restore it.
L3MON4D3 Oct 14, 2025
6bef3b3
api_enter: only log an error when called recursively.
L3MON4D3 Nov 14, 2024
77c5de4
feedkeys: ignore errors on asynchronous nvim_win_set_cursor.
L3MON4D3 Nov 14, 2024
4be52be
correctly restore self-dependent dynamicNode.
L3MON4D3 Nov 14, 2024
26d21ae
change/set/select_choice: update current node before modifying choice.
L3MON4D3 Oct 14, 2025
29c1ee2
add a few tests for previous changes.
L3MON4D3 Nov 14, 2024
a4dd915
Format with stylua
L3MON4D3 Oct 14, 2025
dcdf2ae
fix: pass correct arguments to str_byteindex.
L3MON4D3 May 5, 2025
02fd641
fix: handle unicode->snippetstring->unicode conversion correctly.
L3MON4D3 May 5, 2025
38c55fe
add a few annotations.
L3MON4D3 Oct 14, 2025
9e1d258
feedkeys: only clear action after its confirm is called.
L3MON4D3 May 16, 2025
b525bd3
store: check that child-snip has valid extmarks before storing.
L3MON4D3 Jun 3, 2025
ab81681
improve logging of dynamicNode.
L3MON4D3 Oct 19, 2025
5c2225e
dynamicNode: limit number of nested updates.
L3MON4D3 Oct 19, 2025
42fdd36
rip out update_depth again.
L3MON4D3 Oct 19, 2025
f5bd74d
add brief documentation for new features.
L3MON4D3 Nov 2, 2025
31c9e2b
Format with stylua
L3MON4D3 Nov 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve logging of dynamicNode.
  • Loading branch information
L3MON4D3 committed Nov 3, 2025
commit ab816819d9dfd5655f16fc7370178150a87280f5
16 changes: 16 additions & 0 deletions lua/luasnip/nodes/dynamicNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local FunctionNode = require("luasnip.nodes.functionNode").FunctionNode
local SnippetNode = require("luasnip.nodes.snippet").SN
local extend_decorator = require("luasnip.util.extend_decorator")
local mark = require("luasnip.util.mark").mark
local log = require("luasnip.util.log").new("dynamicNode")
local describe = require("luasnip.util.log").describe

local function D(pos, fn, args, opts)
opts = opts or {}
Expand Down Expand Up @@ -152,6 +154,11 @@ function DynamicNode:update()

if vim.deep_equal(self.last_args, str_args) then
-- no update, the args still match.
log.debug(
"skipping update of %s due to unchanged args (old: %s, new: %s)",
describe.node(self),
describe.inspect(self.last_args),
describe.inspect(str_args))
return
end

Expand Down Expand Up @@ -185,6 +192,7 @@ function DynamicNode:update()
self.snip:exit()
self.snip = nil

log.debug("content of %s before update: %s.", describe.node(self), describe.node_buftext(self))
-- focuses node.
self:set_text_raw({ "" })
else
Expand Down Expand Up @@ -246,6 +254,7 @@ function DynamicNode:update()
local from, to = self.mark:pos_begin_end_raw()
-- inserts nodes with extmarks false,false
tmp:put_initial(from)
log.debug("content of %s after update: %s.", describe.node(self), describe.node_buftext(self))
-- adjust gravity in left side of snippet, such that it matches the current
-- gravity of self.
tmp:subtree_set_pos_rgrav(to, -1, true)
Expand Down Expand Up @@ -434,6 +443,13 @@ function DynamicNode:update_restore()

tmp:update_restore()
else
log.debug(
"update_restore: rejecting stored data of %s (has snip: %s, snip is visible: %s, old args: %s, new args: %s)",
describe.node(self),
self.snip ~= nil,
self.snip and self.snip.visible,
describe.inspect(self.last_args),
describe.inspect(str_args))
self:update()
end
end
Expand Down
5 changes: 5 additions & 0 deletions lua/luasnip/nodes/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ local key_indexer = require("luasnip.nodes.key_indexer")
local types = require("luasnip.util.types")
local opt_args = require("luasnip.nodes.optional_arg")
local snippet_string = require("luasnip.nodes.util.snippet_string")
local log = require("luasnip.util.log").new("node")
local describe = require("luasnip.util.log").describe

---@class LuaSnip.Node
---@field key? any Key to identify the node with.
Expand Down Expand Up @@ -624,11 +626,14 @@ end
-- self has to be visible/in the buffer.
-- none of the node's ancestors may contain self.
function Node:update_dependents(which)
log.debug("updating dependents of %s, selected %s", describe.node(self), describe.inspect(which, {newline =" ", indent = ""}))
-- false: don't set static
local dependents = node_util.collect_dependents(self, which, false)
for _, node in ipairs(dependents) do
if node.visible then
node:update_restore()
else
log.debug("skipping update of %s, it is not visible.", describe.node(node))
end
end
end
Expand Down
74 changes: 73 additions & 1 deletion lua/luasnip/util/log.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local util = require("luasnip.util.util")
local tbl = require("luasnip.util.table")

-- older neovim-versions (even 0.7.2) do not have stdpath("log").
local logpath_ok, logpath = pcall(vim.fn.stdpath, "log")
Expand Down Expand Up @@ -108,13 +109,84 @@ function M.set_loglevel(target_level)
end
end

local describe_key = {}

local function mk_describe(f)
local wrapped_f = function(self)
return f(unpack(self.args))
end
return function(...)
return {
args = {...},
get = wrapped_f,
-- we want to be able to uniquely identify describe-objects, and the
-- simplest way (I think) is to set a unique key that is not known,
-- or even better, accessible by other modules.
[describe_key] = true
}
end
end
local function is_describe(t)
return type(t) == "table" and t[describe_key] ~= nil
end

M.describe = {
node_buftext = mk_describe(function(node)
local from, to = node:get_buf_position()
return vim.inspect(vim.api.nvim_buf_get_text(0, from[1], from[2], to[1], to[2], {}))
end),
node = mk_describe(function(node)
if not node.parent then
return ("snippet[trig: %s]"):format(node.trigger)
else
local snip_id = node.parent.snippet.trigger
-- render node readably.
local node_id = ""
if node.key then
node_id = "key: " .. node.key
elseif node.absolute_insert_position then
node_id = "insert_pos: " .. vim.inspect(node.absolute_insert_position)
else
node_id = "pos: " .. vim.inspect(node.absolute_position)
end
return ("node[%s, snippet: `%s`]"):format(node_id, snip_id)
end
end),
inspect = mk_describe(function(t, inspect_opts)
return vim.inspect(t, inspect_opts or {})
end),
traceback = mk_describe(function()
-- get position where log.debug is called with describe-object.
return debug.traceback("", 3)
end)
}


local function readable_format(msg, ...)
local args = tbl.pack(...)
for i, arg in ipairs(args) do
if is_describe(arg) then
args[i] = arg:get()
end
end
return msg:format(tbl.unpack(args))
end

function M.new(module_name)
local module_log = {}
for name, _ in pairs(log) do
module_log[name] = function(msg, ...)
-- don't immediately get the referenced function, we'd like to
-- allow changing the loglevel on-the-fly.
effective_log[name](module_name .. ": " .. msg:format(...))

-- also: make sure that whatever code called for logging does not
-- cause an error.
local ok, fmt_msg = pcall(readable_format, msg, ...)
if not ok then
effective_log.error(("log: error while formatting or writing message \"%s\": %s"):format(msg, fmt_msg))
end

effective_log[name](module_name .. ": " .. fmt_msg)
end
end
return module_log
Expand Down
6 changes: 6 additions & 0 deletions lua/luasnip/util/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ local function list_to_set(values)
return list
end

-- http://lua-users.org/wiki/VarargTheSecondClassCitizen
local function pack2(...) return {n=select('#', ...), ...} end
local function unpack2(t) return unpack(t, 1, t.n) end

return {
list_to_set = list_to_set,
set_to_list = set_to_list,
pack = pack2,
unpack = unpack2
}