-
-
Notifications
You must be signed in to change notification settings - Fork 256
Allow self-dependent dynamicNode #1137
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
base: master
Are you sure you want to change the base?
Conversation
326779d
to
595996e
Compare
edf1dd4
to
f513f60
Compare
339fb3f
to
e89d49d
Compare
A quick update: I've somwhat widened the scope of this PR, besides simply allowing self-dependent dynamicNodes, I'd like to make those more practical by addressing this usecase where a snippet that was active inside an insertNode remains active even after it was modified by the dynamicNode-function! A preliminary example: 1730232750.mp4This required some larger changes (and enabled some other nice things, for example a restoreNode also restoring entire snippets that were expanded inside the restoreNode), so I'm happy with any user that is open to test-running this branch in their usual setup for a while, even without using these new features :D |
eb85cac
to
15ebd05
Compare
4af90c0
to
1464b3f
Compare
ea82903
to
d066147
Compare
Previously, we used a metatable to refer to the choiceNode for some keys that are required, which are only .parent and .pos.
This may improve the accuracy of docstrings generated on an expanded snippet.
Otherwise the jump_into from change_choice may complete after the cursor-movement due to the subsequent update.
Much more appropriate, also get_current_choices will work even if some insertNode is not visible.
* handle column-shifted begin-position (only shift cursor-column if it stays in the same line) * correctly enqueue cursor-movement via feedkeys.
Code is essentially the same thing. Also allow passing the current cursor to ls.set/change_choice, which is useful for extras.select_choice, where the cursor-state is "destroyed" due to vim.input, and should be saved before that is even opened.
metadata can store eg. when a snippetString was created, marks are a bit like extmarks, they can mark a position in a snippetString and are shifted by text-insertions.
Cache `static_text` (for insertNodes) and don't query it anew while luasnip is operating. This is valid under the assumption that all changes to the buffer are due to luasnip while an api-function (jump, expand, etc.) is running. This is enabled by session.luasnip_changedtick which is set as soon as an api-function is called, and prevents re-fetching snippetStrings from the buffer (which in turn allows us to set the cursor-position once, and then have it propagate through all updates that are triggered subsequently). This commit also replaces no_region_check_wrap with api_do, which is more general (handles both jump_active, which prevents recursive api-calls and luasnip_changedtick)
See extensive comment in commit.
By inserting the stored snip into the buffer, `get_args` during `update_restore` can find the argnode inside the snippet.
If we don't do this, the content of a choiceNode may not be restored correctly. (or, it will be restored correctly, but it won't be what the user saw before they called change/set/select_choice, which seems suboptimal).
Helps track invariants.
c7bdd9f
to
f19b713
Compare
Deal with/Explicitly allow dynamicNodes being updated due to a change inside of them.
This is to enable stuff like #1096 and #1102, where the text of an insertNode should be updated while typing.
One important limitation this has (for now??) is that the updates have to reach some equilibrium (text is unchanged after a second update), otherwise we just keep updating.
One example:
Note the other new addition,
opt_arg
(optional argnodes, we currently don't run the dynamicNode-function if an argnode is missing), for allowing the initial creation of thesn
when the"asd"
-node does not yet exist.This is missing tests and doc for now, and I'm not certain it handles all cases correctly, but I'd like to show this since I think it should work for simple ones.