Repository navigation
Adding raise_form and raise_element support for fennel if_form - #112
Open
andysbolton wants to merge 1 commit into
Open
andysbolton wants to merge 1 commit into
andysbolton wants to merge 1 commit into
Conversation
Contributor
|
this is one of my biggest pain points when working with fennel. i'd love this change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fennel's tree-sitter grammar has the concept of 'pair' nodes which are neither a form nor an element (related to #83).
Because of this, there's an issue when raising forms or elements in Fennel.
Current:
Expected:
This happens because:
if_pairnode when searching for the current form or element under the cursor.if_pairwas returned, instead of theif_form.This PR introduces matches for the form elements of an
if_pairnode as suggested in #83 and resolves this issue forraise_elementandraise_form.It makes two new behavior changes: when walking upwards to get the current node's root, it will stop on a
@form.element(in addition to its existing behavior of stopping on a direct child of the enclosing form). Also, when looking for the parent to operate on, it will keep walking up until it finds a node that is a@form(instead of returning the immediate parent, which may beif_pair).Some new or refactored functions:
find_next_parent_formreferences tofind_enclosing_formand removesfind_next_parent_form.find_next_parent_formreturned the current node if it was a form.find_enclosing_formwill walk up from the node's parent usingfind_nearest_form.find_nearest_formcurrently largely does whatfind_next_parent_formdid.is_element_offunction to determine if a node is an element of the given root node.Another approach to solving this might be to mark the
if_pairas a@transparentcapture or something similar, and skip it whenever traversing the tree.Let me know if there are any pitfalls to this approach and if this aligns with your vision for the plugin!