Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e98b6c3
implement optional argnodes.
L3MON4D3 Dec 28, 2023
7c71180
implement subtree_do, invokes callbacks on tree of nodes (in a snippet).
L3MON4D3 Mar 4, 2024
e2c6493
make resolve_position work for static snippets.
L3MON4D3 Mar 4, 2024
696e013
fix: make root_path work for snippets.
L3MON4D3 Mar 4, 2024
700c85b
implement subtree_leave_entered, for leaving only entered nodes.
L3MON4D3 May 5, 2025
e14ad4e
overhaul snippet-updates.
L3MON4D3 Mar 4, 2024
e3b455c
make sure visible is set on -1-node.
L3MON4D3 Mar 10, 2024
db22421
propery remove child-snippets when `:exit`ing.
L3MON4D3 Apr 23, 2024
40009de
exitNode: use same update_dependents as all other nodes.
L3MON4D3 Apr 23, 2024
c447bfe
update after snip_expand.
L3MON4D3 Oct 14, 2025
2b6faa8
Format with stylua
L3MON4D3 Oct 14, 2025
93e6a6d
Make insertNode correctly handle static_text if it's a snippetString.
L3MON4D3 Oct 28, 2024
64749d8
allow using snippet_string as dynamicNode-args.
L3MON4D3 Oct 28, 2024
9ab5c8f
restoreNode,insertNode: propagate store.
L3MON4D3 Oct 29, 2024
0cc1b1d
dynamicNode.update: store snippet before evaluating fn.
L3MON4D3 Oct 29, 2024
222be26
dynamicNode.update: copy extmarks after focusing.
L3MON4D3 Oct 29, 2024
8ac94b0
dynamicNode.update: do update_restore instead of update.
L3MON4D3 Oct 29, 2024
d86a464
restoreNode: don't store on exit, store should have been called before.
L3MON4D3 Oct 29, 2024
1f78d4d
add some tests for new restoreNode-behaviour.
L3MON4D3 Oct 29, 2024
088479d
choiceNode: correctly refocus when current_node is in another snippet.
L3MON4D3 Oct 29, 2024
ba74f0c
we don't want to go into adjacent snippetNodes, but land between them.
L3MON4D3 Oct 29, 2024
d72b952
snippet: correctly propagate exit to child_snippets (and clear them).
L3MON4D3 Oct 29, 2024
e7997a7
add another test for the new restoreNode.
L3MON4D3 Oct 29, 2024
ea2a104
store content of nested snippets before capturing argnode.
L3MON4D3 Oct 29, 2024
4d13edd
make sure marks are invalidated even for nested snippets.
L3MON4D3 Oct 29, 2024
e3a7848
get_args: `store` only when calling in static mode.
L3MON4D3 Oct 29, 2024
a3e7f6d
snippetstring: store strings as \n-separated string.
L3MON4D3 Oct 14, 2025
6201643
small refactor.
L3MON4D3 Oct 30, 2024
89ab103
implement a few simple string-operations on snippetString.
L3MON4D3 Oct 30, 2024
38cbae7
fix flakiness in test.
L3MON4D3 Oct 30, 2024
801be9f
update: try to find new active node in child-snippet.
L3MON4D3 Oct 30, 2024
6927494
allow replacing parts of a snippetString with other text.
L3MON4D3 Nov 2, 2024
a7ad748
implement gsub on snippetString.
L3MON4D3 Nov 2, 2024
d286685
snippetstring.replace: fix substitution in textNode.
L3MON4D3 Nov 2, 2024
d046836
fix switchup.
L3MON4D3 Nov 2, 2024
3bef40e
make in-place modifying functions private.
L3MON4D3 Nov 2, 2024
eb90fe3
add :sub to snippetString.
L3MON4D3 Nov 2, 2024
7ec34e8
add `opt` for the optional argument.
L3MON4D3 Nov 3, 2024
bc50117
correctly store+restore visual selection during update.
L3MON4D3 Nov 3, 2024
313590e
fNode: always store result in static_text.
L3MON4D3 Nov 4, 2024
595fdb8
update_dependents: get cursor-position after queried movements.
L3MON4D3 Nov 4, 2024
e01440c
move the jump_active-check into the autocommand.
L3MON4D3 Oct 14, 2025
1401fcd
optionally update a node differnt from the current node.
L3MON4D3 Oct 14, 2025
df2b809
update_dependents: use update_restore by default.
L3MON4D3 Nov 4, 2024
76e13e0
choiceNode: call update_dependents after routine is done completely.
L3MON4D3 Nov 4, 2024
abc429d
move no_region_wrap back into main-module.
L3MON4D3 Oct 14, 2025
f7e64d3
dynamicNode/restoreNode: don't destroy snip on exit.
L3MON4D3 Nov 4, 2024
96db16a
handle selection on first line and column of buffer with `before`.
L3MON4D3 Nov 4, 2024
092fad2
document imperfect behaviour asserted by test.
L3MON4D3 Nov 4, 2024
e8cf583
export optional_arg as opt for tests.
L3MON4D3 Nov 4, 2024
669fbd6
set jump_active=false ASAP.
L3MON4D3 Nov 4, 2024
d807109
choiceNode: explicitly set parent and pos for choices.
L3MON4D3 Nov 6, 2024
7801f5e
fix(dynamicNode): don't access .snip in update_static.
L3MON4D3 Nov 6, 2024
2c5f641
dynamicNode: optionally use .snip to generate docstring.
L3MON4D3 Nov 6, 2024
7dc2830
enqueue cursor-movement due to update in typeahead.
L3MON4D3 Nov 6, 2024
ef5d904
get_args: do (static_)visible-check in get_args, not get_static_text.
L3MON4D3 Nov 6, 2024
0319df9
test docstring-generation with self-dependent dynamicNode.
L3MON4D3 Nov 6, 2024
a9fde83
properly restore cursor-position in set_choice.
L3MON4D3 Nov 7, 2024
8be84b4
change_choice: use cursor-restore system from update_dependents.
L3MON4D3 Oct 14, 2025
cd78df8
snippet_string: add metadata and marks.
L3MON4D3 Nov 13, 2024
687973b
store cursor-position in snippetString to more accurately restore it.
L3MON4D3 Oct 14, 2025
0e5642e
api_enter: only log an error when called recursively.
L3MON4D3 Nov 14, 2024
8a02e0d
feedkeys: ignore errors on asynchronous nvim_win_set_cursor.
L3MON4D3 Nov 14, 2024
f7a902a
correctly restore self-dependent dynamicNode.
L3MON4D3 Nov 14, 2024
176ea23
change/set/select_choice: update current node before modifying choice.
L3MON4D3 Oct 14, 2025
02492d8
add a few tests for previous changes.
L3MON4D3 Nov 14, 2024
75b1cca
Format with stylua
L3MON4D3 Oct 14, 2025
9e705d1
fix: pass correct arguments to str_byteindex.
L3MON4D3 May 5, 2025
32f97e8
fix: handle unicode->snippetstring->unicode conversion correctly.
L3MON4D3 May 5, 2025
142f77f
add a few annotations.
L3MON4D3 Oct 14, 2025
a9bdc62
feedkeys: only clear action after its confirm is called.
L3MON4D3 May 16, 2025
7be764f
store: check that child-snip has valid extmarks before storing.
L3MON4D3 Jun 3, 2025
4a17769
Format with stylua
L3MON4D3 Oct 14, 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
3 changes: 1 addition & 2 deletions lua/luasnip/_types.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---@alias LuaSnip.Cursor {[1]: number, [2]: number}

--- 0-based region within a single line
---@class LuaSnip.MatchRegion
---@class LuaSnip.MatchRegion 0-based region within a single line
---@field row integer 0-based row
---@field col_range { [1]: integer, [2]: integer } 0-based column range, from-in, to-exclusive

Expand Down
12 changes: 8 additions & 4 deletions lua/luasnip/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ c = {
require("luasnip").unlink_current_if_deleted
)
end
ls_autocmd(
session.config.update_events,
require("luasnip").active_update_dependents
)
ls_autocmd(session.config.update_events, function()
-- don't update due to events if an update due to luasnip is pending anyway.
-- (Also, this would be bad because luasnip may not be in an
-- consistent state whenever an autocommand is triggered)
if not session.jump_active then
require("luasnip").active_update_dependents()
end
end)
if session.config.region_check_events ~= nil then
ls_autocmd(session.config.region_check_events, function()
require("luasnip").exit_out_of_region(
Expand Down
3 changes: 3 additions & 0 deletions lua/luasnip/default_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ local lazy_snip_env = {
k = function()
return require("luasnip.nodes.key_indexer").new_key
end,
opt = function()
return require("luasnip.nodes.optional_arg").new_opt
end,
ai = function()
return require("luasnip.nodes.absolute_indexer")
end,
Expand Down
47 changes: 37 additions & 10 deletions lua/luasnip/extras/select_choice.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
local session = require("luasnip.session")
local ls = require("luasnip")
local node_util = require("luasnip.nodes.util")
local feedkeys = require("luasnip.util.feedkeys")

local function set_choice_callback(_, indx)
if not indx then
return
-- in this procedure, make sure that api_leave is called before
-- set_choice_callback exits.
local function set_choice_callback(data)
return function(_, indx)
if not indx then
ls._api_leave()
return
end
-- set_choice restores cursor from before.
ls._set_choice(indx, { cursor_restore_data = data, skip_update = true })
ls._api_leave()
end
-- feed+immediately execute i to enter INSERT after vim.ui.input closes.
vim.api.nvim_feedkeys("i", "x", false)
ls.set_choice(indx)
end

local function select_choice()
assert(
session.active_choice_nodes[vim.api.nvim_get_current_buf()],
"No active choiceNode"
)
vim.ui.select(
ls.get_current_choices(),
{ kind = "luasnip" },
set_choice_callback
local active = session.current_nodes[vim.api.nvim_get_current_buf()]

ls._api_enter()

ls._active_update_dependents()

if not session.active_choice_nodes[vim.api.nvim_get_current_buf()] then
print("Active choice was removed while updating a dynamicNode.")
return
end

local restore_data = node_util.store_cursor_node_relative(
active,
{ place_cursor_mark = true }
)

-- make sure all movements are done, otherwise the movements may be put into
-- the select-dialog.
feedkeys.enqueue_action(function()
vim.ui.select(
ls.get_current_choices(),
{ kind = "luasnip" },
set_choice_callback(restore_data)
)
end)
end

return select_choice
Loading