-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add extra folding definitions for golang #42
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the interface_type
would work by doing the offset. If you add spaces, tabs, newline in front the curly bracket then the offset is simply wrong!
type Dog interface
{
Bark() (string, error)
Beg() (bool, error)
}
/* |
* V
*/
type Dog interface
...}
Others look good. 👍
That was made with go's standardized format in mind. Basically, no matter how someone tries to write go, it gets corrected to the format in my example. However, I think you bring up a good point that folding should still work regardless of standards so I think I'll write a parser that'll search for the first instance of a provided delimiter character and fold based on that. I think that would be helpful here and elsewhere too. |
dd4da1b
to
2df18e1
Compare
I've added the new parsing definition which takes two extra parameters (which means it'll need a lambda wrapper just like const_declarationIn golang, you can either declare consts as a single line or a block. In tree-sitter, these two cases are treated using the same const Hello = "world"
const (
a = "circle"
b = 1
c float = 4.65
)
/* |
* v
*/
const Hello = "world"
const (...) |
One other thing I'd like to note is that we could probably replace type (
Name = string
Age = int
) I chose not to do that for now since I don't have time to look into the edge cases this may run into and I don't know the efficiency impact that may occur by doing more regex searches. Anyways, just wanted to call that out as a possible future addition. I've added it to my own config for now to see how it performs and to see if there's anything I run into in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to use regex base solution, walk through AST is much more dedicated than regex search!
Sorry for being out for a while, had a lot of stuff suddenly happen 😅 I took the stuff you posted above and changed some things around. I see you've added some of it already so I'll rebase my branch onto master tomorrow 😊. |
a25eb5d
to
7ee8a54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for rebasing it! ❤️
I've tested and it works! Let me know if this is ready to merge! (I will be busy in next couple of days)
If it works for you and looks good to you, then it's ready to merge 😉. |
Thank you! |
This PR adds a couple of folding I personally have found quite useful as defaults for working with golang. Figured I'd add them to the general defaults so others can enjoy a better experience out of the box.
field_declaration_list
import_spec_list
interface_type
Needs to be offset quite a bit since the tree-sitter definition includes the word interface which should still be shown.