Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow self-dependent dynamicNode #1137

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
3342a54
implement optional argnodes.
L3MON4D3 Dec 28, 2023
8f82c73
implement subtree_do, invokes callbacks on tree of nodes (in a snippet).
L3MON4D3 Mar 4, 2024
c61d083
make resolve_position work for static snippets.
L3MON4D3 Mar 4, 2024
3f56b38
fix: make root_path work for snippets.
L3MON4D3 Mar 4, 2024
de8dd21
implement subtree_leave_entered, for leaving only entered nodes.
L3MON4D3 Mar 4, 2024
20b61a2
overhaul snippet-updates.
L3MON4D3 Mar 4, 2024
db12345
insertNode: exit all nested snippets, not just the first.
L3MON4D3 Mar 4, 2024
e80c049
make sure visible is set on -1-node.
L3MON4D3 Mar 10, 2024
da3529b
propery remove child-snippets when `:exit`ing.
L3MON4D3 Apr 23, 2024
9b5450f
exitNode: use same update_dependents as all other nodes.
L3MON4D3 Apr 23, 2024
3c0d125
update after snip_expand.
L3MON4D3 Apr 23, 2024
7e26ca5
Format with stylua
L3MON4D3 Oct 23, 2024
ab84254
Make insertNode correctly handle static_text if it's a snippetString.
L3MON4D3 Oct 28, 2024
d08cf30
allow using snippet_string as dynamicNode-args.
L3MON4D3 Oct 28, 2024
f8b7d1a
restoreNode,insertNode: propagate store.
L3MON4D3 Oct 29, 2024
3a7c677
dynamicNode.update: store snippet before evaluating fn.
L3MON4D3 Oct 29, 2024
8bd88b2
dynamicNode.update: copy extmarks after focusing.
L3MON4D3 Oct 29, 2024
8c0bb59
dynamicNode.update: do update_restore instead of update.
L3MON4D3 Oct 29, 2024
6f39702
restoreNode: don't store on exit, store should have been called before.
L3MON4D3 Oct 29, 2024
fc94ef2
add some tests for new restoreNode-behaviour.
L3MON4D3 Oct 29, 2024
65b9e7e
choiceNode: correctly refocus when current_node is in another snippet.
L3MON4D3 Oct 29, 2024
4f52fd2
we don't want to go into adjacent snippetNodes, but land between them.
L3MON4D3 Oct 29, 2024
afa887c
snippet: correctly propagate exit to child_snippets (and clear them).
L3MON4D3 Oct 29, 2024
a78be52
add another test for the new restoreNode.
L3MON4D3 Oct 29, 2024
eb9cefd
store content of nested snippets before capturing argnode.
L3MON4D3 Oct 29, 2024
1688ba3
make sure marks are invalidated even for nested snippets.
L3MON4D3 Oct 29, 2024
6fa5d02
get_args: `store` only when calling in static mode.
L3MON4D3 Oct 29, 2024
41b8811
snippetstring: store strings as \n-separated string.
L3MON4D3 Oct 30, 2024
81a1c9d
small refactor.
L3MON4D3 Oct 30, 2024
9d0dfd6
implement a few simple string-operations on snippetString.
L3MON4D3 Oct 30, 2024
4f50d6c
fix flakiness in test.
L3MON4D3 Oct 30, 2024
78419f1
update: try to find new active node in child-snippet.
L3MON4D3 Oct 30, 2024
0213852
allow replacing parts of a snippetString with other text.
L3MON4D3 Nov 2, 2024
83a2793
implement gsub on snippetString.
L3MON4D3 Nov 2, 2024
b14f25f
snippetstring.replace: fix substitution in textNode.
L3MON4D3 Nov 2, 2024
bd58f4d
fix switchup.
L3MON4D3 Nov 2, 2024
56b9e1a
make in-place modifying functions private.
L3MON4D3 Nov 2, 2024
483656e
add :sub to snippetString.
L3MON4D3 Nov 2, 2024
1d8aa65
add `opt` for the optional argument.
L3MON4D3 Nov 3, 2024
de53515
correctly store+restore visual selection during update.
L3MON4D3 Nov 3, 2024
31f9740
fNode: always store result in static_text.
L3MON4D3 Nov 4, 2024
4244a88
update_dependents: get cursor-position after queried movements.
L3MON4D3 Nov 4, 2024
dfe82fb
move the jump_active-check into the autocommand.
L3MON4D3 Nov 4, 2024
be863e7
optionally update a node differnt from the current node.
L3MON4D3 Nov 4, 2024
2cb3fa1
update_dependents: use update_restore by default.
L3MON4D3 Nov 4, 2024
9020719
choiceNode: call update_dependents after routine is done completely.
L3MON4D3 Nov 4, 2024
1ee7430
move no_region_wrap back into main-module.
L3MON4D3 Nov 4, 2024
155331f
dynamicNode/restoreNode: don't destroy snip on exit.
L3MON4D3 Nov 4, 2024
9c70626
handle selection on first line and column of buffer with `before`.
L3MON4D3 Nov 4, 2024
bab5962
document imperfect behaviour asserted by test.
L3MON4D3 Nov 4, 2024
90c2fc6
export optional_arg as opt for tests.
L3MON4D3 Nov 4, 2024
79b985e
set jump_active=false ASAP.
L3MON4D3 Nov 4, 2024
583befe
choiceNode: explicitly set parent and pos for choices.
L3MON4D3 Nov 6, 2024
feeac25
fix(dynamicNode): don't access .snip in update_static.
L3MON4D3 Nov 6, 2024
733ccb2
dynamicNode: optionally use .snip to generate docstring.
L3MON4D3 Nov 6, 2024
211254b
enqueue cursor-movement due to update in typeahead.
L3MON4D3 Nov 6, 2024
ae8d95c
get_args: do (static_)visible-check in get_args, not get_static_text.
L3MON4D3 Nov 6, 2024
3d8f8bd
test docstring-generation with self-dependent dynamicNode.
L3MON4D3 Nov 6, 2024
14280e1
properly restore cursor-position in set_choice.
L3MON4D3 Nov 7, 2024
1464b3f
change_choice: use cursor-restore system from update_dependents.
L3MON4D3 Nov 7, 2024
f78bf74
snippet_string: add metadata and marks.
L3MON4D3 Nov 13, 2024
d553a79
store cursor-position in snippetString to more accurately restore it.
L3MON4D3 Nov 13, 2024
fe21f49
api_enter: only log an error when called recursively.
L3MON4D3 Nov 14, 2024
f19ebbd
feedkeys: ignore errors on asynchronous nvim_win_set_cursor.
L3MON4D3 Nov 14, 2024
f13c479
correctly restore self-dependent dynamicNode.
L3MON4D3 Nov 14, 2024
a76f573
change/set/select_choice: update current node before modifying choice.
L3MON4D3 Nov 14, 2024
d066147
add a few tests for previous changes.
L3MON4D3 Nov 14, 2024
1aa841e
Auto generate docs
L3MON4D3 Nov 14, 2024
cabdbfa
Format with stylua
L3MON4D3 Nov 14, 2024
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
2 changes: 1 addition & 1 deletion doc/luasnip.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*luasnip.txt* For NVIM v0.8.0 Last change: 2024 November 05
*luasnip.txt* For NVIM v0.8.0 Last change: 2024 November 14

==============================================================================
Table of Contents *luasnip-table-of-contents*
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 @@ -51,6 +51,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