Skip to content

Adding raise_form and raise_element support for fennel if_form - #112

Open
andysbolton wants to merge 1 commit into
julienvincent:masterfrom
andysbolton:feature/support-fennel-if-pair
Open

andysbolton wants to merge 1 commit into
julienvincent:masterfrom
andysbolton:feature/support-fennel-if-pair

Conversation

@andysbolton

@andysbolton andysbolton commented Jul 3, 2026 •

Copy link
Copy Markdown

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:

(if a |(b) c) → a (b)

Expected:

(if a |(b) c) → (b)

This happens because:

  1. The search stops at an if_pair node when searching for the current form or element under the cursor.
  2. When searching for the parent node to replace with the current node, the if_pair was returned, instead of the if_form.

This PR introduces matches for the form elements of an if_pair node as suggested in #83 and resolves this issue for raise_element and raise_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 be if_pair).

Some new or refactored functions:

  • Changes find_next_parent_form references to find_enclosing_form and removes find_next_parent_form. find_next_parent_form returned the current node if it was a form. find_enclosing_form will walk up from the node's parent using find_nearest_form. find_nearest_form currently largely does what find_next_parent_form did.
  • Adds new is_element_of function to determine if a node is an element of the given root node.

Another approach to solving this might be to mark the if_pair as a @transparent capture 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!

@NoahTheDuke

Copy link
Copy Markdown
Contributor

this is one of my biggest pain points when working with fennel. i'd love this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants