Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions queries/roc/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(anon_fun_expr
(expr_body) @function.inner
) @function.outer

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

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
Member

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
Member

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
Member

@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)

)

(function_call_expr
.
(_)
(parenthesized_expr (expr_body) @parameter.inner) @parameter.outer
)

(function_call_expr
.
(_) ((_) @parameter.inner) @parameter.outer
)

[
(annotation_type_def ) @class.inner
(alias_type_def ) @class.inner
(opaque_type_def ) @class.inner
] @class.outer

(apply_type_arg) @parameter.inner

(line_comment) @comment.outer
(doc_comment) @comment.outer