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

Commits on Nov 6, 2024

  1. implement optional argnodes.

    In that case, there will be a `nil` at the place of the text of the
    node in the arg-list.
    They have to be explicitly marked as optional, since we currently have
    the behaviour of not updating nodes at all if an argnode is missing.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    3342a54 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8f82c73 View commit details
    Browse the repository at this point in the history
  3. make resolve_position work for static snippets.

    dynamicNode has to return .static_snip instead of .snip
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    c61d083 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    3f56b38 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    de8dd21 View commit details
    Browse the repository at this point in the history
  6. overhaul snippet-updates.

    Previously:
    InsertNodes trigger an update on input_leave.
    
    This works, but, if updates invalidate nodes that are currently involved
    in being jumped over, we'd have to abort and roll back the jump, or do
    some other recovery.
    
    To avoid this, update_dependents is done _before_ any jumping is
    performed (this is really more elegant now since we can keep track of
    which nodes are "above" some insertNode, and then just get all of them
    and their dependents (see
    node_util.find_node_dependents/collect_dependents))
    
    So, now `ls.jump` does essentially:
    * store position of cursor relative to active node
    * collect nodes that depend on the text of this node (so, all dependents
      of all parents of this node)
    * update them
    * try to find an equivalent node (node with the same key, or if a
      restoreNode is present, the exact same node :D) and perform the jump
      from it
    * if an equivalent node could not be found, just enter the first
      dynamicNode (starting from the previously active node) and enter it
    
    Obviously, this only really works well if an equivalent of the current
    node can be found in the new generated nodes.
    
    Similarly, active_update_dependents
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    20b61a2 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    db12345 View commit details
    Browse the repository at this point in the history
  8. make sure visible is set on -1-node.

    put_initial is not called on it, but since it's always visible we can
    set it when initializing.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    e80c049 View commit details
    Browse the repository at this point in the history
  9. propery remove child-snippets when :exiting.

    This is important to prevent an infinite loop when a snippet is
    remove_from_jumplist'd in node_util.snippettree_find_undamaged_node: if
    child_snippets is not modified, we just continue to remove it (or call
    :r_f_j but immediately nop because the snippet is not visible).
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    da3529b View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    9b5450f View commit details
    Browse the repository at this point in the history
  11. update after snip_expand.

    Has to happen because we modified text.
    I don't like using vim.schedule here, but it seems like this is the
    only way of getting the desired behaviour into all possible ways of
    expanding snippets (direct snip_expand is used by cmp_luasnip, so can't
    just handle `expand` and its variants in init.lua (or, we could do so
    and submit a PR to cmp_luasnip, but let's wait with that until this
    actually becomes problematic, which I don't think it will)).
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    3c0d125 View commit details
    Browse the repository at this point in the history
  12. Format with stylua

    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    7e26ca5 View commit details
    Browse the repository at this point in the history
  13. Make insertNode correctly handle static_text if it's a snippetString.

    This includes `put_initial`, so a restoreNode will now store snippets
    expanded inside of it!! (which is really cool :D)
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    ab84254 View commit details
    Browse the repository at this point in the history
  14. allow using snippet_string as dynamicNode-args.

    This allows us to duplicate snippets within argnodes into the
    dynamicNode.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    d08cf30 View commit details
    Browse the repository at this point in the history
  15. restoreNode,insertNode: propagate store.

    If store is triggered manually (for example in dynamicNode:update), it
    should also be performed for the entire snippetTree!
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    f8b7d1a View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    3a7c677 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    8bd88b2 View commit details
    Browse the repository at this point in the history
  18. dynamicNode.update: do update_restore instead of update.

    This enables restoring the dynamicNode content in snippetStrings.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    8c0bb59 View commit details
    Browse the repository at this point in the history
  19. restoreNode: don't store on exit, store should have been called before.

    exit is also called when a snippet should be deleted due to invalid
    extmarks, if we do something like store in there, we have to always
    check extmarks.
    
    For now, leave a pcall in get_snippetstring, get_text behaved the same.
    But log errors!
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    6f39702 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    fc94ef2 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    65b9e7e View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    4f52fd2 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    afa887c View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    a78be52 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    eb9cefd View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    1688ba3 View commit details
    Browse the repository at this point in the history
  27. get_args: store only when calling in static mode.

    weirdly that one test breaks, and only on nvim0.7.. I don't think it's
    an actual bug in luasnip. so just skipping that test for now.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    6fa5d02 View commit details
    Browse the repository at this point in the history
  28. snippetstring: store strings as \n-separated string.

    This should simplify applying string-operations.
    Also don't store the string of a snippet, just reconstruct it when
    needed.
    We do this because it is much easier than figuring out exactly how
    indent or expand affect a snippet (indentSnippetNode can affect them, so
    keeping them in sync manually seems infeasible.)
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    41b8811 View commit details
    Browse the repository at this point in the history
  29. small refactor.

    set parent_node in insert_into_jumplist, and rename reown to copy (so it
    can be used more generally and not just in the context of some
    insertNode receiving the snippetString as static_text).
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    81a1c9d View commit details
    Browse the repository at this point in the history
  30. implement a few simple string-operations on snippetString.

    lower, upper, and ..
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    9d0dfd6 View commit details
    Browse the repository at this point in the history
  31. fix flakiness in test.

    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    4f50d6c View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    78419f1 View commit details
    Browse the repository at this point in the history
  33. allow replacing parts of a snippetString with other text.

    If possible, snippets are preserved, and if they can't be preserved they
    will gracefully degrade to raw text.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    0213852 View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    83a2793 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    b14f25f View commit details
    Browse the repository at this point in the history
  36. fix switchup.

    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    bd58f4d View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    56b9e1a View commit details
    Browse the repository at this point in the history
  38. add :sub to snippetString.

    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    483656e View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    1d8aa65 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    de53515 View commit details
    Browse the repository at this point in the history
  41. fNode: always store result in static_text.

    :store only really makes sense for nodes where we can't store the text
    as its' being generated, which is exclusively insertNode.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    31f9740 View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    4244a88 View commit details
    Browse the repository at this point in the history
  43. move the jump_active-check into the autocommand.

    Whenever update_dependents is called by luasnip, we can be sure that
    it's safe to call currently.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    dfe82fb View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    be863e7 View commit details
    Browse the repository at this point in the history
  45. update_dependents: use update_restore by default.

    if we can restore a previously generated snippet, we should do so to not
    revert user input.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    2cb3fa1 View commit details
    Browse the repository at this point in the history
  46. choiceNode: call update_dependents after routine is done completely.

    safer, update_dependents could remove the entire choiceNode, not good!
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    9020719 View commit details
    Browse the repository at this point in the history
  47. Configuration menu
    Copy the full SHA
    1ee7430 View commit details
    Browse the repository at this point in the history
  48. dynamicNode/restoreNode: don't destroy snip on exit.

    And store generated snippet in .snip, not .snip_stored, which is not
    reached by subtree_do, which we would like to have apply to the stored
    snippet.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    155331f View commit details
    Browse the repository at this point in the history
  49. Configuration menu
    Copy the full SHA
    9c70626 View commit details
    Browse the repository at this point in the history
  50. Configuration menu
    Copy the full SHA
    bab5962 View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    90c2fc6 View commit details
    Browse the repository at this point in the history
  52. set jump_active=false ASAP.

    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    79b985e View commit details
    Browse the repository at this point in the history
  53. choiceNode: explicitly set parent and pos for choices.

    Previously, we used a metatable to refer to the choiceNode for some keys
    that are required, which are only .parent and .pos.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    583befe View commit details
    Browse the repository at this point in the history
  54. Configuration menu
    Copy the full SHA
    feeac25 View commit details
    Browse the repository at this point in the history
  55. dynamicNode: optionally use .snip to generate docstring.

    This may improve the accuracy of docstrings generated on an expanded
    snippet.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    733ccb2 View commit details
    Browse the repository at this point in the history
  56. enqueue cursor-movement due to update in typeahead.

    Otherwise the jump_into from change_choice may complete after the
    cursor-movement due to the subsequent update.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    211254b View commit details
    Browse the repository at this point in the history
  57. get_args: do (static_)visible-check in get_args, not get_static_text.

    Much more appropriate, also get_current_choices will work even if some
    insertNode is not visible.
    L3MON4D3 committed Nov 6, 2024
    Configuration menu
    Copy the full SHA
    ae8d95c View commit details
    Browse the repository at this point in the history
  58. Configuration menu
    Copy the full SHA
    3d8f8bd View commit details
    Browse the repository at this point in the history

Commits on Nov 7, 2024

  1. properly restore cursor-position in set_choice.

    * handle column-shifted begin-position (only shift cursor-column if it
      stays in the same line)
    * correctly enqueue cursor-movement via feedkeys.
    L3MON4D3 committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    14280e1 View commit details
    Browse the repository at this point in the history
  2. change_choice: use cursor-restore system from update_dependents.

    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.
    L3MON4D3 committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    1464b3f View commit details
    Browse the repository at this point in the history

Commits on Nov 13, 2024

  1. snippet_string: add metadata and marks.

    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.
    L3MON4D3 committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    f78bf74 View commit details
    Browse the repository at this point in the history

Commits on Nov 14, 2024

  1. store cursor-position in snippetString to more accurately restore it.

    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)
    L3MON4D3 committed Nov 14, 2024
    Configuration menu
    Copy the full SHA
    d553a79 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    fe21f49 View commit details
    Browse the repository at this point in the history
  3. feedkeys: ignore errors on asynchronous nvim_win_set_cursor.

    See extensive comment in commit.
    L3MON4D3 committed Nov 14, 2024
    Configuration menu
    Copy the full SHA
    f19ebbd View commit details
    Browse the repository at this point in the history
  4. correctly restore self-dependent dynamicNode.

    By inserting the stored snip into the buffer, `get_args` during
    `update_restore` can find the argnode inside the snippet.
    L3MON4D3 committed Nov 14, 2024
    Configuration menu
    Copy the full SHA
    f13c479 View commit details
    Browse the repository at this point in the history
  5. change/set/select_choice: update current node before modifying choice.

    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).
    L3MON4D3 committed Nov 14, 2024
    Configuration menu
    Copy the full SHA
    a76f573 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    d066147 View commit details
    Browse the repository at this point in the history
  7. Auto generate docs

    L3MON4D3 authored and github-actions[bot] committed Nov 14, 2024
    Configuration menu
    Copy the full SHA
    1aa841e View commit details
    Browse the repository at this point in the history
  8. Format with stylua

    L3MON4D3 authored and github-actions[bot] committed Nov 14, 2024
    Configuration menu
    Copy the full SHA
    cabdbfa View commit details
    Browse the repository at this point in the history