Open
Conversation
Author
|
I'm not sure about the tests here, there's probably a better way to test IterCaptures |
topi314
reviewed
May 29, 2025
Author
|
I tried something similar in a project i'm working on and got some super weird errors func allMatches(qc *ts.QueryCursor, q *ts.Query, node *ts.Node, text []byte) iter.Seq2[*ts.QueryMatch, *ts.Query] {
qm := qc.Matches(q, node, text)
return func(yield func (qm *ts.QueryMatch, q *ts.Query) bool) {
for {
m := qm.Next()
if m == nil {
break
}
if !yield(m, q) {
return
}
}
}
}in the yield call i got a panic: edit: ok i need to learn more about go resource management. for now I'm doing this so i can close the resources when finished at the call site func QueryMatches(queryName string,
language *ts.Language,
text []byte,
node *ts.Node) (*ts.Query, *ts.QueryCursor, iter.Seq2[*ts.QueryMatch, *ts.Query]) {
queryText, err := loadQueryFile(queryName)
if err != nil {
log.Fatal(nil)
}
q, qerr := ts.NewQuery(language, queryText)
if qerr != nil {
log.Fatal(qerr)
}
qc := ts.NewQueryCursor()
qm := qc.Matches(q, node, text)
return q, qc, func(yield func (qm *ts.QueryMatch, q *ts.Query) bool) {
for {
m := qm.Next()
if m == nil {
break
}
if !yield(m, q) {
return
}
}
}
}I'm demoting this back to draft until i grok this better. |
Author
|
Ok having played around with this, it was pebcak. I believe this code does what it says it does, I was just not properly managing the treesitter c object lifetimes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #30