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

Use new parser form types #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

datwaft
Copy link

@datwaft datwaft commented Mar 16, 2024

As the default parser for Fennel has changed the form_types are different now.

See alexmozaidze/tree-sitter-fennel for the new default parser for Fennel.

I tested these changes with the following test file:

(+ 1 2)

(+ (+ 1 2) 3 4 (- 5 6) (/ 10 (+ 20 3)))

[1 2 [3] [4 5] 6]

(fn salute []
  (print "Hello, World!"))

(macro some-macro []
  (let [v "Hello, World!"]
    `(print ,v)))

#(print "Hello, World")

(macrodebug '(print "Hello, World!"))

I applied all the operations and they seem to work perfectly.

A fun fact is that the reader macros are moved with the slurp and barf operations, which in my opinion is desirable:

#(print "Hello, World!")
; '>('
print #("Hello, World!")

The only issues I am having right now are with the ( and ) movement operations, which if used after reaching the end show the following error:

E5108: Error executing lua: ...vim-paredit-fennel/lua/nvim-paredit-fennel/extension.lua:15: attempt to index local 'current_node' (a nil value)
stack traceback:
        ...vim-paredit-fennel/lua/nvim-paredit-fennel/extension.lua:15: in function 'find_next_parent_form'
        ...vim-paredit-fennel/lua/nvim-paredit-fennel/extension.lua:33: in function 'get_node_root'
        .../nvim/lazy/nvim-paredit/lua/nvim-paredit/api/motions.lua:195: in function 'move_to_parent_form_edge'
        .../nvim/lazy/nvim-paredit/lua/nvim-paredit/api/motions.lua:231: in function <.../nvim/lazy/nvim-paredit/lua/nvim-paredit/api/motions.lua:230

And also with the paredit.api.raise_form operation, which fails every time with the following error:

E5108: Error executing lua: ...vim-paredit-fennel/lua/nvim-paredit-fennel/extension.lua:15: attempt to index local 'current_node' (a nil value)
stack traceback:
        ...vim-paredit-fennel/lua/nvim-paredit-fennel/extension.lua:15: in function 'find_next_parent_form'
        ...vim-paredit-fennel/lua/nvim-paredit-fennel/extension.lua:33: in function 'get_node_root'
        .../nvim/lazy/nvim-paredit/lua/nvim-paredit/api/motions.lua:195: in function 'move_to_parent_form_edge'
        .../nvim/lazy/nvim-paredit/lua/nvim-paredit/api/motions.lua:231: in function <.../nvim/lazy/nvim-paredit/lua/nvim-paredit/api/motions.lua:230

Do you know how this could be fixed? I don't know enough about your plugin to fix it confidently.

@datwaft
Copy link
Author

datwaft commented Mar 16, 2024

BTW, here are the test results:

image

We can now do this because the `open` and `close` fields are now in the tree-sitter grammar for Fennel
@datwaft
Copy link
Author

datwaft commented Mar 16, 2024

I added a commit using the get_form_edges from the Clojure implementation.

As you can see in the following snippet (from here) the Fennel grammar now includes the open and close fields so we can use the same implementation.

list: $ => seq(
  field('open', '('),
  optional($._list_content),
  field('close', ')'),
),

Note

BTW, this doesn't fix the errors I told you about.

@julienvincent
Copy link
Owner

Thanks I'll try take a look at this as soon as I get a chance.

datwaft added a commit to datwaft/nvim.conf that referenced this pull request Apr 10, 2024
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.

None yet

2 participants