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

fix(treesitter): add opts to iter_captures #29133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Danielkonge
Copy link
Contributor

This is a minor change which makes iter_captures work more like iter_matches. Since both iter_captures and iter_matches uses vim._create_ts_querycursor in a similar way, I don't see why iter_captures wouldn't also allow the opts table. In particular, match_limit also affects iter_captures, and this change would basically fix #26325.

As a side note: While editing the iter_captures code, I noticed that iter_matches doesn't use memoize like iter_captures, is this on purpose? I don't really see the reason for this distinction?

@lewis6991
Copy link
Member

As a side note: While editing the iter_captures code, I noticed that iter_matches doesn't use memoize like iter_captures, is this on purpose? I don't really see the reason for this distinction?

iter_captures can flip between different matches so memoize is used to avoid recalculating whether or not the predicates passed. This isn't needed for iter_matches since you will only process a match once.

@Danielkonge
Copy link
Contributor Author

Danielkonge commented Jun 2, 2024

iter_captures can flip between different matches so memoize is used to avoid recalculating whether or not the predicates passed. This isn't needed for iter_matches since you will only process a match once.

Ah, that makes sense then.

Also, I was considering adding more descriptive types to the opts for both iter_captures and iter_matches, but I have just kept the layout like iter_matches for now.

Wouldn't it be better with something like opts? { max_start_depth?: integer, match_limit?: integer}? Or maybe a named type (though for now there is a difference between iter_captures and iter_matches, since all is not relevant to iter_captures).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Treesitter: ts_match_limit of 256 is not always enough
2 participants