Open topi314 opened 1 week ago
I also want to add that tree_sitter
is not exactly an ideal package name. Ideally it would be either treesitter
, sitter
or something else.
Resource: https://go.dev/blog/package-names
this is not really a problem, just an annoyance since you have to convert the type when you want to use it. I just saw there is a note on QueryCapture
with that this is a C-compatible struct
so ig it makes sense for it to be a uint32
then.
okay cool, in this case there are some functions/methods accepting or returning pointers where I wouldnt expect them to:
in general shouldn't the methods except Node.Edit
all have a value receiver instead of pointer receiver?
- this is not really a problem, just an annoyance since you have to convert the type when you want to use it. I just saw there is a note on
QueryCapture
withthat this is a C-compatible struct
so ig it makes sense for it to be auint32
then.
Ah that was it, I wanted the layout to remain the same as the C struct so casting from C pointers would be okay, like here
- okay cool, in this case there are some functions/methods accepting or returning pointers where I wouldnt expect them to:
Yeah, I agree. PR welcome :) none of these methods besides Edit
mutate the underlying node.
I was digging the C api, and if a node is not found they return an empty node, do you think it would make sense to do this in go too instead of returning pointers which could be nil
?
possibly with an added Valid() bool
/Empty() bool
method
returning a (Node, bool)
would work too but is often annoying to deal with
Ah right. I guess we could add an IsNull
method to mirror the C api. Does that work better?
After thinking about it a bit more, I think I personally would prefer a (Node, bool)
method signature, that would be the clostest to rusts Option<T>
and force people to handle absent nodes. It should also make it more clear that nodes can be absent compared to Node.IsNull()
This does limit the ability to chain methods returning childs, but how would the current api with nil
nodes handle that? probably just panicing?
yeah it would just panic, I'm not really a fan of returning a (Node, bool)
tbh
Hi, first of all I appreciate the effort to provide updated & maintained go bindings for tree-sitter. Previously I was using https://github.com/smacker/go-tree-sitter which I had to fork to get rid of all the included tree-sitter grammars & make major breaking changes to be able to work with it.
My objective is to have good looking syntax highlighting and for this I ported the
highlight
crate of the official tree-sitter rust bindings to go. I had major pain points with missing features with the old module which are now gone.While porting my highlighting code to this module I found 2 things I am wondering about:
github.com/smacker/go-tree-sitter
useduint32
in most places which seem to have been replaced withuint
in this module except for: https://github.com/tree-sitter/go-tree-sitter/blob/master/query.go#L113 Is this intended or just an oversight?From what I can tell the
Node
struct should be passed around as a pointer. There are 3 places where they are handled as values instead which makes dealing with nodes a little bit annoying in those cases:Besides this I haven't ran into any issues, thanks for this awesome work!