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

feat(roc): add roc queries #593

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

Conversation

nat-418
Copy link

@nat-418 nat-418 commented Apr 3, 2024

@clason I made a new clean PR

@clason clason requested a review from ribru17 April 3, 2024 09:24
) @function.outer

(argument_patterns
((_) @parameter.inner . ","? @parameter.outer) @parameter.outer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query makes it so that @parameter.outer only matches the comma sometimes (maybe every time?). Can you change this to only have the second outer query which captures everything? Or if that doesn't work you may need #make-range!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what the problem is here. A Roc function looks like this:

\x -> x

or with multiple params:

\x, y -> x

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; if you try it yourself, you'll find that operating on @parameter.outer selects only the comma itself, when it should be the entirety of, say, x, (with or without trailing whitespace). This is why you may need #make-range!. You can see some examples of other textobject files doing this if you need, this type of query is pretty common across different languages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for explaining. this is my first foreay into tree-sitter

)

(function_type
((_) @parameter.inner . ","? @parameter.outer) @parameter.outer(#not-eq? @parameter.inner "->")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above I believe. Also we don't enforce style (yet?) on this repo but would you mind putting the predicate on a new line, just some easier reading?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the query linter from nvim-treesitter; I don't think we should support a different style here. (You can just download/copy the file from that repo; it's a standalone script.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the query linter and ran it. I am still not sure what the issue is with this query though. If someone can explain to me in more detail I will make whatever change necessary.

#593 (comment)

Copy link
Collaborator

@ribru17 ribru17 Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thank you for doing that! Sorry I should have mentioned this was done by me a few days ago; but I think your issue is that the linter expects the output to match the main branch formatter: I am guessing the one you added is from master? (I also did this at first!) You can just remove that file from this PR and then run your original queries through the main branch's formatter if you get any CI complaints :) (if it doesn't complain, then it doesn't even matter)

queries/roc/textobjects.scm Outdated Show resolved Hide resolved
queries/roc/textobjects.scm Outdated Show resolved Hide resolved
queries/roc/textobjects.scm Outdated Show resolved Hide resolved
@nat-418 nat-418 force-pushed the master branch 2 times, most recently from 32cdbb1 to e2e1e88 Compare April 6, 2024 09:18

(apply_type_arg) @parameter.inner

((#offset! line_comment 0 1 0 -1)) @comment.inner
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This results in an error: try looking here for an example of how this should be done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you happen to be using lazy, you can just put your textobject queries in ~/.local/share/nvim/lazy/nvim-treesitter-textobjects/queries/roc/textobjects.scm and restart your neovim instance and they should apply locally, if you'd like to be able to do some quick debugging.

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

3 participants