-
Notifications
You must be signed in to change notification settings - Fork 13
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 support for syntax based folding #7
base: main
Are you sure you want to change the base?
Add support for syntax based folding #7
Conversation
I was just about to implement and submit my own MR for block names and variables, awesome to see you beat me to it @droustchev! It looks good. @jvirtanen Any ideas when you will have some time to review and merge this? |
Hi @droustchev and @mbillow! My apologies, I missed this pull request when it was initially opened. I will take a look at this today. |
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.
Thank you for the contribution, @droustchev! I think the folding itself looks good, especially is it is by default off as I believe it is. 👍
I have some comments below regarding the syntax highlighting changes as well as the indentation settings. I feel that as-is, they actually slightly degrade the user experience, and I would prefer to see a patch that only implements the folding with minimal changes, keeping the existing syntax highlighting intact. 🙂
set softtabstop=2 | ||
set shiftwidth=2 | ||
set expandtab | ||
set smarttab |
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.
Aren't these more of a personal preference than part of Vim runtime files for a language? 🤔
One could argue that HCL has a canonical form at least in Terraform with terraform fmt
, but so does Go with go fmt
yet the Vim runtime files for Go, I just checked, do not specify tabstop
etc.
syn match hclBlock /^[^=]\+{/ contains=hclBlockName,hclString | ||
syn match hclBlockName /\<[A-Za-z0-9_.\[\]*]\+\>/ nextgroup=hclString,hclBlock | ||
syn region hclBlock start="{" end="}" fold transparent contains=hclBlock,hclVariable,hclString,hclInterpolation,hclComment | ||
syn region hclBlock start="\[" end="\]" fold transparent contains=hclBlock,hclVariable,hclString,hclInterpolation,hclComment |
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 think the change in hclBlock
breaks the highlighting of hclAttributeName
, which used to be unadorned (i.e. light gray) but after this change is highlighted the same way as hclVariable
(i.e. yellow). This, I feel, makes the syntax highlighting worse, as a typical attribute name as well as a typical attribute value end up both being highlighted the same way.
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 think this change also breaks the highlighting of hclNumber
, which is not included in hclBlock
.
@@ -32,7 +32,7 @@ syn match hclNumber /\<0[xX]\x\+\>/ | |||
|
|||
syn keyword hclConstant true false null | |||
|
|||
syn region hclInterpolation start=/\${/ end=/}/ contained contains=hclInterpolation | |||
syn region hclInterpolation start=/\${/ end=/}/ contained contains=hclString,hclInterpolation,hclAttribute,hclAttributeName |
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.
Do you have an example that has a string inside an interpolation? I admit I work almost exclusively with Terraform, but I have never seen such a construct in the wild. 🙂
In similar vein, is there a use case, which utilizes an hclAttribute
(/^.*=/
) inside an interpolation? 🤔
Finally, I think possibly the addition of hclAttributeName
here breaks highlighting of variables (i.e. identifiers) inside interpolations, as they now become unadorned (i.e. light gray) instead of being highlighted the same way hclVariable
(i.e. yellow). I think this is confusing, because it changes how variables are highlighted inside and outside interpolations.
Thanks for the feedback @jvirtanen. I have been a bit swamped at work lately, so haven't gotten around to look into making the requested changes. I hope to get around to them this weekend. |
I just stumbled upon this and would also be interested in seeing syntax-based folding land in this plugin. @droustchev do you think you could push the requested changes? |
I could possibly try to look into this myself as well. This was my first real Vim plugin, and I just released another, which forced me to up my Vimscript game. 🙂 |
Hi there,
Thanks for this great plugin. I've been working in long Nomad HCLs and missed being able to fold sections based on syntax highlighting. I took the liberty to add this to your syntax file, and also made some other minor changes. Let me know if you'd be interested to incorporate them. I've tested my changes manually against a few of the fixtures in the official hcl repo. Here are some screenshots of the folding in action as well as the changes to the highlighting, albeit with my colorscheme: