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

Add more folding definitions #51

Merged
merged 1 commit into from
Feb 21, 2023
Merged

Conversation

samrjack
Copy link
Contributor

Adding some folding definitions for bash, java, javascript, python, and yaml.

When working with some code recently, I found a couple of folds that I wanted but weren't available in the ts-fold defaults yet. I figured I'd add them in so others could use them as well. If any of the folds added below seem odd or not useful to a general user, please let me know and we'll figure out how to proceed!

TODO: add more details about what exactly was added and why when I have time.

Adding some folding definitions for bash, java, javascript, python, and
yaml.
@jcs090218
Copy link
Member

No, I think all of them are very useful. ❤️ I should have add them early on, but I was being busy with something else.

(The CI seems to be a bit too aggressive; let me ignore the package-lint test.)

@samrjack
Copy link
Contributor Author

Explanations

Bash

  • I removed the expansion group since I believe most people use the expansion as an in-line item so folding it can be annoying. If you or others often have expansions that you would want folded, I'm happy to un-delete this.
  • do_group covers the do ... done pattern. It needs the the range shifting to make sure the do and done keywords are cleanly visible.

Java

  • I changed comment to block_comment since comment isn't a node type in the grammar that I have and therefore was giving an error when I would use fold all. I think I'm using a pretty standard grammar and assumed this was just a simple oversight, but let me know if your grammar differs.

Javascript

  • Added object folding since javascript often has enormous objects defined that are great to just fold away.
  • Added array folding for the same reason as above.

Python

  • Added ability to fold python dictionaries for the same reason as javascript objects.

Yaml

Added a yaml folding definition since I deal with a lot of yaml files. It only has 2 definitions:

  • Comments that start with '#' can be folded nicely
  • block_mapping_pair corresponds to any pair of key: value. I will add this may be a bit broad since it will fold things that are one line such as key: value -> key:... but more usefully it will fold long chains of values up into a single line. I think ideally we would want to eventually add the ability to only fold the really long block nodes while not folding the single line key to string pairs but, at least in my usage, it wasn't particularly a problem yet.

summary

So if all those sound good to you, feel free to merge them in.

@jcs090218
Copy link
Member

jcs090218 commented Feb 21, 2023

Can you rebase it? I've removed the package-lint test. ;)

Java

  • I changed comment to block_comment since comment isn't a node type in the grammar that I have and therefore was giving an error when I would use fold all. I think I'm using a pretty standard grammar and assumed this was just a simple oversight, but let me know if your grammar differs.

I think the grammar has changed upstream. 🤔

Yaml

Added a yaml folding definition since I deal with a lot of yaml files. It only has 2 definitions:

Yah! We finally have the yaml support! 🎉


Others sound good to me. Great job! 🚀 👍

I've tested manually, it should be good! Thank you very much! ❤️

@jcs090218 jcs090218 merged commit 9d9e0c5 into emacs-tree-sitter:master Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants