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

Rewrite core on top of treesitter queries #71

Merged
merged 4 commits into from
Oct 13, 2024
Merged

Conversation

julienvincent
Copy link
Owner

@julienvincent julienvincent commented Oct 13, 2024

The current core implementation of nvim-paredit relies on a language extension api to ask questions about the AST.

This is not a very treesitter-like way of doing things and the extension API was pretty gnarly.

This is a complete reimplementation which relies entirely on treesitter queries with known capture groups. This drastically simplifies both the implementation and the task of extending to other languages.

Now, instead of having to understand and write a language API, you can just write a few treesitter queries to help nvim-paredit understand the grammar.


This also reworks some internals:

Currently the approach to checking if a node represents the document root is to check if its type is "source". While a lot of grammars do this by convension it's not part of any spec and some grammars call it something else - like "program".

This replaces all these assertions with a comparison to see if the node is :equal() to the tree :root() which is completely grammar agnostic.

@julienvincent julienvincent force-pushed the jv/ref-sxvwmvkxwxuq branch 3 times, most recently from 76c492e to fe90d1f Compare October 13, 2024 12:26
@julienvincent julienvincent marked this pull request as ready for review October 13, 2024 12:27
The current core implementation of nvim-paredit relies on a language
extension api to ask questions about the AST.

This is not a very treesitter-like way of doing things and the extension
API was pretty gnarly.

This is a complete reimplementation which relies entirely on treesitter
queries with known capture groups. This drastically simplifies both the
implementation and the task of extending to other languages.

Now, instead of having to understand and write a language API, you can
just write a few treesitter queries to help nvim-paredit understand the
grammar.
Currently the approach to checking if a node represents the document
root is to check if its `type` is `"source"`. While a lot of grammars do
this by convension it's not part of any spec and some grammars call it
something else - like `"program"`.

This replaces all these assertions with a comparison to see if the node
is :equal() to the tree :root() which is completely grammar agnostic.
@julienvincent julienvincent merged commit 31d91d3 into master Oct 13, 2024
3 checks passed
@julienvincent julienvincent deleted the jv/ref-sxvwmvkxwxuq branch October 13, 2024 13:16
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.

1 participant