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

Fennel forms query issues #83

Open
NoahTheDuke opened this issue Nov 5, 2024 · 4 comments
Open

Fennel forms query issues #83

NoahTheDuke opened this issue Nov 5, 2024 · 4 comments

Comments

@NoahTheDuke
Copy link
Contributor

It seems the fennel queries aren't quite correct, leading to odd behavior:

{:foo 1
 |:bar 2
 :qux 3}

Given my cursor on the : of :bar, if I press W, my cursor will move to :qux, not 2. And if I press B, it'll move to :foo, not 1.

@julienvincent
Copy link
Owner

julienvincent commented Nov 5, 2024

Interesting. I wonder how this worked before..

Looking at the grammar it looks like the table elements are wrapped in a 'table_pair' node. See:

(program ; [0, 0] - [3, 0]
  (table ; [0, 0] - [2, 8]
    item: (table_pair ; [0, 1] - [0, 7]
      key: (string ; [0, 1] - [0, 5]
        content: (string_content)) ; [0, 2] - [0, 5]
      value: (number)) ; [0, 6] - [0, 7]
    item: (table_pair ; [1, 1] - [1, 7]
      key: (string ; [1, 1] - [1, 5]
        content: (string_content)) ; [1, 2] - [1, 5]
      value: (number)) ; [1, 6] - [1, 7]
    item: (table_pair ; [2, 1] - [2, 7]
      key: (string ; [2, 1] - [2, 5]
        content: (string_content)) ; [2, 2] - [2, 5]
      value: (number)))) ; [2, 6] - [2, 7]

So if this worked on the previous paredit version it was purely by chance.

I will need to think on how to solve this. I think this will almost certainly require introducing more capture groups.

@julienvincent
Copy link
Owner

julienvincent commented Nov 5, 2024

Ah, as per julienvincent/nvim-paredit-fennel#1 it looks like the fennel grammar changed earlier this year. So paredit pre-v1 would have been broken on the latest fennel grammar anyway.

Did you per-chance also update your fennel grammar recently?

@NoahTheDuke
Copy link
Contributor Author

NoahTheDuke commented Nov 5, 2024

Yeah, I have the latest edition of the fennel grammar. I tried to write my own custom nvim-paredit query according to the docs but wasn't able to get it. I wish the grammar was closer to how Clojure's grammar works. Ah well.

@julienvincent
Copy link
Owner

julienvincent commented Nov 5, 2024

Yea you wouldn't be able to with how paredit currently works.

Paredit tries to find the root node relative to the closest form, starting from the node at the cursor.

(program
  (form
   (outer_element
    |(inner_element))
   
   (sibling)))

In the above example the outer_element and sibling nodes are considered to be the 'elements' of the form. So it's structure dependent. The pre-v1 paredit worked the same in this regard.

The paredit grammars are only used to identify the nodes considered forms and the rest is inferred. So we would need to extend paredit to allow capturing the distinct 'elements' of a form in a way that is independent of the structure of the grammar.

This would mean supporting a query like:

(table
  (table_pair
    (_) @form.element)) @form

And then perhaps falling back to the existing implementation if no @form.element captures are found.

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

No branches or pull requests

2 participants