Implement syntactic fold for comments for JS, TS, and TSX
This PR implements the first five steps of #31395:
- Create
folds.scmfor JavaScript, TypeScript, TSX for comments only (for now) Although the comments are already queried byhighlights.scmandtext_objects.scm, they are semantically different from querying comments to make them foldable. In the future, we can easily add folds to other syntax structures with this new file. Related: nvim-treesitter uses afolds.scmfor each language. TypeScript example.
- Modify
language.rsto add new fields related to folds_query (e.g. addfolds_queryto theGrammarstruct).
- Create function in
multi_buffer.rsto query fold information according tofolds.scmon demand.
- Optimize fold actions to minimize number of folds queries done (e.g. when calling
fold_all).
- Also optimize the fold indicators in the UI.
The optimizations done were done by either:
i. Precomputing a map of fold starting row to fold range (done in fold actions in general).
ii. Minimizing the bytes parsed by the query (done in the UI).
Manual test:
https://github.com/user-attachments/assets/f744bcfd-2499-456c-ab24-d8a139d2a10f
Release Notes:
- Implemented syntactic fold for comments for JavaScript, TypeScript, and TSX.
Seems like we should add the implementation for how folds.scm will be used first before we go defining the folds queries themselves.
Hey, I appreciate that you're taking the time to do this. However, I'd much prefer it if you would implement syntax based folding as a single PR, rather than a bunch of small PR's. This will greatly reduce the review burden on us, and allow easy reverting/changing/reworking. My suggestion is that you mark this PR as a draft, and continue working on adding support for the folds.scm files. Thanks again!
Thanks for the quick feedback. I was uncertain about the best PR size in this case, so your comment helps a lot.
I will change the PR to draft while I work on it.
The PR is ready for review.
Sorry about closing it earlier, somehow I misclicked and did not notice.
I will close it as things start to conflict and it's been 3 weeks since the last feedback. Overall, looks like a nice idea though.