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
feat: Terraform 0.12 support (was hcl2 support) #157
Comments
+1, this feature would be exceedingly useful |
HCL support is currently implemented by taking the HCL Go-library and feeding it through GopherJS to get a (very raw) JavaScript library (refer https://github.com/mauve/vscode-terraform/tree/master/hcl-hil) and then made into something useable in this part of the codebase: build.ts. I do not have time myself to look into this right now but if somebody wants to give it a try, that is where you need to change stuff. |
+1 I think this feature would really be helpful. |
+1 |
I really would like to add this feature but I cannot do it myself as I do not have time, I can help somebody if they want to do it. I have tried to get Hashicorp to take over the project but they are not interested. |
This does seem somewhat of an easy transition to hcl2. The API is different, but overall I think still embeddable in the same way. @mauve I will take a stab at it and let you know if I have questions; |
@jnicholls Thanks for tackling this. If the hcl2 library is capable of parsing hcl1 then I recommend just replacing it. in the meantime you might also want to replace the syntax-highlighting tmLanguage files with the official files from the hcl2 repo. The data flow right now is The only reason why I added However I recommend that you might save yourself a lot of time if you make the Go-code emit something much closer to what |
Well, it looks like the AST is 100% different, haha. But, I think it is actually friendlier, and it's much more strongly typed. See https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md. I think we can walk this AST and provide a good result from |
In the old HCL library a section refers to any top-level entity, for example: The references were never part of the AST directly but they are extracted by Currently The current code assumes that |
If the HCL2 library is also able to recover from parse-errors and continue parsing we can also start using it more in the auto-completion provider. If you can find a HCL2 go function which (given a position in the text-document, or a position in the AST) gives us a list of possible next-tokens, that would be really awesome. |
HCL2 will not continue parsing unfortunately. As evidenced by:
output:
Note that it did not parse the second Block, which would have looked like this:
I haven't looked closely at HCL1; are you saying that the |
Thank you for the explanation on the FileIndex parts, and the expectation of Sections vs Properties! In HCL2, we'll have inner |
Feel free to change HCL1 is not able to recover from any parse errors (to my knowledge), I was kinda hoping that HCL2 would be better at parsing here, maybe your example is just too hard to recover from. That means, to clarify, that
At least Thanks for giving it a try. |
Ok, well it does seem that HCL2 is an improvement, and it does return multiple diagnostics (even though sometimes it'll complain about the same root issue multiple times, which means the parser isn't really "undoing" any state internally after encountering a syntax or grammar error in order to continue forward to the next expression/attr/block/etc. as if nothing bad happened). I don't think it could be used for auto-complete. There are functions for identifying a node by position, but not any to suggest next tokens. It does however have functions, given an execution context, to evaluate expressions...which could be useful. From
|
@mauve Hi, I created a LSP for terraform and maybe it will help with adding more HCL2 support to the extension? (since I did also do a client extension for vscode but is lacking syntax and indentation and etc) Edit: I will try to add every possible LSP feature in the plugin, the most difficult one is going to be in-scope completion in for each loop |
@juliosueiras That is great, a language server for Terraform is definitely a needed thing in the community. I'd imagine once it matures more that we'd simply plug into that. Short term I see a fairly clear path for integrating HCL2 into this extension that should only take a couple of hours of development time after it's well-understood how to integrate it without breaking too many interfaces on the first-order pass. I'd rather save a lot of refactoring and cleanup for a second pass. But ultimately yes, having LSP integration makes a lot of sense; if not entirely, as an option at least. |
@jnicholls just want to ask, what do you consider the most require feature for the lsp to have? (since I want to get a general ideal of what to target next) right now the LSP support:
I am expecting to the following implemented within this/next week:
after the above implemented, then I will be working on other LSP features(symbols, codelens, codeactions, etc) Any feedback is greatly appreciated Edit: also the reason I did the LSP is because I created the vim terraform plugin but is mostly regex solution, and with HCL2 allowing very very very nested variable structure, I decided to do a LSP instead for HCL2 |
@juliosueiras You are (and within a week or two, even more so) further than I expected! I think your to-do list is 100% aligned with what I’d suggest, prioritizing error checking and completions. Next I’d say symbols and anything else necessary for good hover and goto support. I’ll admit, I am not 100% familiar with the LSP specification and where the line is drawn between it and the features it powers in editors. |
@juliosueiras @jnicholls I am fine with using an external language-server but then I think it needs to be either automatically downloaded and updated or bundled with the plugin, I used to have an external tool a while back and most users didn't figure out that they needed to install the tool which led to many support-requests. |
the lsp is a single binary, so either option work |
@jnicholls added Basic Dynamic Block completion https://asciinema.org/a/XhGFudMZ5mNCb6dndGbgc5iSu , right now will try to implement inferred type completion in for each |
now there is also for each completion https://asciinema.org/a/245663 |
@juliosueiras @jnicholls what is the plan? are you guys working on integrating the language-server? |
@mauve I am all for integrating the lsp into this plugin, right now I am mostly focus on making the lsp itself feature complete, so if there is anything that you guys need as high priority then I can do those first instead |
@juliosueiras I use this extension every day, and I feel like it would greatly benefit from the LSP and HCL2 support (even if it isn't 100% complete yet). Seems like the official Terraform 0.12 release is imminent. Completely up to you what you prioritize of course. EDIT: 0.12 was released minutes after commenting. |
FYI 0.12 just came out so this is going to be pressing... |
I agree that this is a required feature and getting more urgent all the time. Sadly due to a new job and role I have no time at all to focus on this project except reviewing PR and doing releases. It saddens me to say that I have for a few months now unsuccessfully tried to engage Hashicorp in the project which is why these new features are lagging. I would love if the community could pull together here and help ship a better autocompletion and 0.12 support based on @juliosuerias language server. I am very proud that we have a rather large user base (around 70k monthly actives, top 40 in downloads 🎉🎉) and it feels bad that I cannot devote more time. Therefore I would really love to see this (rather big) change being shipped without my involvement as I fear without it the plugin will end up being rather useless. Thanks everybody for using my plug-in it makes me proud to have you as users. 🎉 |
Thanks for all your hard work and the explanation, your plugin is well done
and appreciated by the terraform community.
|
@musicislife08 @juliosueiras I can confirm this is working in VSCodium. Thank you for the hint! |
I've enabled the language server version Also, I have hundreds of TF projects in my workspace. The Language server should only parse the ones I actively work on. Just like the Git extension does.
|
Was able to upgrade locally but on a Remote-SSH session I get: Has anyone faced this and come up with a workaround? |
@madpipeline i will take a look |
@madpipeline are you able to join the gitter channel so I can have more details about the issue? |
Sure, if someone gives me the gitter link. |
I had the same problem. I managed to upgrade/downgrade by following these steps:
It's also worth mentioning that I needed to be in a directory containing some Thank you for supporting this extension. |
Is it the terraform extension or |
@06kellyjac this extension put the providers binary, since lsp pick up any provider after ‘terraform init’, this extension predownload a set of common providers binary first to allow lsp work without doing ‘terraform init’ |
I am unable to get most of the features that are documented as supported working. Opened above issue. My settings are as shown above and I am running latest beta release of the lsp. Certain code completion works. For example most resources. But anything outside that doesn’t. |
I got this message after I upgraded to the latest language server: The extension just stopped working. |
👋 Hey everyone, we just posted an update about the extension on our blog: https://www.hashicorp.com/blog/supporting-the-hashicorp-terraform-extension-for-visual-studio-code We are working internally on a new version that will have 0.12 support and handle installing and using our new language server by default. For now I'm going to start cleaning up the issues / PRs on the repo in preparation for the new version. |
The end of an era! |
Exciting! |
Wow I am going to miss getting updates on this issue 💯 |
@mauve has submitted a claim to the BountySource funds. Let's give him a 👍 |
We just released v2.0.0-rc.1 of the extension. The main features include:
You can find additional information and specifics in the release notes and CHANGELOG. With this release we expect that many of the prior issues and PRs are no longer relevant or have been addressed, and are therefore being closed. If you feel the action taken on an issue or PR is in error, please comment as such and we can figure out the appropriate way to address it. We plan to add the final 2.0.0 release to the marketplace soon, but are actively seeking your feedback now on the release candidates. You can download the .vsix from the releases page and manually install it in VS Code to try it out. |
My VScode no longer auto-format for .tf file ? How i bring my features back ?? |
@hungdhm-0574 simply download mauve.terraform-v1.4.0.vsix file from https://github.com/hashicorp/vscode-terraform/releases/tag/v1.4.0, then in VSCode go to View -> Command Palette... -> type "VSIX" (there will be Extensions: Install from VSIX - click it) and select the file you downloaded. I also disabled 2.0.1 version of extension in "Show Installed Extension" for my workspace, but for me it started to work again even with both versions active. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Hi!
Is there any plans to implement hcl2 support?
The text was updated successfully, but these errors were encountered: