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

Responding to request for more feedback on code completion #528

Closed
mattwelke opened this issue Dec 10, 2020 · 3 comments
Closed

Responding to request for more feedback on code completion #528

mattwelke opened this issue Dec 10, 2020 · 3 comments

Comments

@mattwelke
Copy link

mattwelke commented Dec 10, 2020

I'm creating this issue in response to this response to a review I left on the Visual Studio Marketplace:

With regards to completion - I believe we fixed some of these issues in recent releases of the language server, but I'd be interested to talk through any other completion related feedback in more detail to fully understand it. Can you reach us at [email protected] or via an issue in the repo (https://github.com/hashicorp/vscode-terraform)?

Here is my original feedback:

If I type resource "aws, I don't get code completion telling me what the possible resources are from my AWS provider. It also doesn't fill in the required attributes with placeholder values for me after I finish typing the name of a resource. I can trigger this kind of help manually with ctrl-space, and scrolling down the suggested attributes looking for which ones are marked "Required" though. But, it would be more discoverable if it filled in more things for me based on the providers and modules.

To expand on what I said further, here are examples of things that would be helpful for the extension to do:

  1. Emmets

If I'm working in a file detected as HTML, I can type html and then get a dropdown of emmets:

image

I choose html:5 and press enter:

image

It would be neat if, upon loading the AWS provider, I had some AWS emmets available to me. For example, for the VPC module (https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest), I could type something like tf_aws_vpc and the text put onto the screen would be a basic VPC with all the required properties filled in, where I could tab through the places I need to put input (name, required properties, etc) like other emmets.

  1. Code completion for required properties

The VS Code docs for Intellisense say:

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.) in JavaScript).

It would also be nice if, upon starting to write a resource block (as described in https://learn.hashicorp.com/tutorials/terraform/aws-build?in=terraform/aws-get-started#resources), when I create the open brace, that acts as the trigger character and results in the extension filling in all the required properties, like the emmet described above. I could see this being more feasible to implement if the emmets aren't. At least all I have to remember is the resource type, and then the rest is filled in for me.

For example, the aws_instance resource from the AWS provider (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) has the following arguments marked as required:

  • ami
  • instance_type

Therefore, if typed the following:

resource "aws_instance" "web" 

and then typed a { character, the block would become:

resource "aws_instance" "web" {
  ami           = <empty, but used for tabbing>
  instance_type = <empty, but used for tabbing>
}

Let me know if you need any more feedback.

@radeksimko
Copy link
Member

radeksimko commented Dec 10, 2020

Firstly thank you again @mattwelke for providing the detailed feedback in the Marketplace and for further explaining it here!
We need more of such diligent and helpful community members like you. 😃

It would be neat if, upon loading the AWS provider, I had some AWS emmets available to me. For example, for the VPC module (https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest), I could type something like tf_aws_vpc and the text put onto the screen would be a basic VPC with all the required properties filled in, where I could tab through the places I need to put input (name, required properties, etc) like other emmets.

We do plan to support module completion beyond the static arguments such as source we support (through LS 0.9.0+). The UX you are describing mostly makes sense. I reckon we would probably start with completion of source URLs first, as opposed to looking up module names based on the module reference name (module "ref_name"), but it is something we could certainly consider.

FYI we track module completion on the LS side here: hashicorp/terraform-ls#93 so feel free to add anything more there and feel free to subscribe to that issue to get notified about progress.

It would also be nice if, upon starting to write a resource block (as described in https://learn.hashicorp.com/tutorials/terraform/aws-build?in=terraform/aws-get-started#resources), when I create the open brace, that acts as the trigger character and results in the extension filling in all the required properties, like the emmet described above. I could see this being more feasible to implement if the emmets aren't. At least all I have to remember is the resource type, and then the rest is filled in for me.

Pre-filling required arguments is a functionality we want to provide. There was an attempt and a fruitful discussion about UX and some implementation details in hashicorp/terraform-ls#147 So while we don't support this today, I think we have a way forward and we have most of the data available.

With that in mind I'm not sure whether pre-filling the block on { is the best way to implement this, at least such UX doesn't seem very common in other language servers and extensions I have seen, so I would be more inclined to pre-fill on confirmation of e.g. aws_instance from the list. Relatedly the braces may already be pre-filled by the time you get to completion of the label - you can type just res and confirm.

Either way I'd welcome you to discuss this particular topic further or subscribe to hashicorp/terraform-ls#96

@mattwelke
Copy link
Author

@radeksimko Looks like you folks have already recognized the need for these features. I followed those issues, thanks.

@ghost
Copy link

ghost commented Jan 14, 2021

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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the context necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants