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

Provide single-step completion for resources, data sources and providers #743

Open
radeksimko opened this issue Aug 24, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@radeksimko
Copy link
Member

radeksimko commented Aug 24, 2021

Problem Statement

Users can today complete a whole block in two steps.

In the first step they complete the block type

Screenshot 2021-08-24 at 17 43 48

In the second step they complete the labels for the block

Screenshot 2021-08-24 at 17 44 03

However, many users, especially those who don't know the Terraform language and conventions as well don't necessarily think "I need a resource/data source" at first. They think "I need an EC2 instance" or similar.

Expected User Experience

Users will be presented with "composed" items such as

  • resource "aws_instance"
  • data "aws_ami"
  • provider "aws"

in addition to the existing "plain" resource, data and provider, when they request completion outside of any block.

Additionally we would also pre-fill any required fields for the block, assuming #719 is already implemented by the time we get to this.

Proposal

All of the work would likely take place on the language server side, more specifically within the https://github.com/hashicorp/hcl-lang library.

There we could modify the behaviour of CandidatesAtPos so that for positions where it would typically return top-level blocks, such as resource, data, or provider, it would additionally return "composed" items such as resource "aws_instance", data "aws_ami", provider "aws" etc.

It is likely we'd want this behaviour to be opt-in, at least initially.

It is likely that we won't need to modify the Terraform schema as the existing schema should allow us to make informed decisions about which blocks are eligible for this kind of "composing", specifically combination of IsDepKey && Completable in LabelSchema may be sufficient.

TBD: filtering and sorting of completion items

@radeksimko radeksimko added the enhancement New feature or request label Aug 24, 2021
@radeksimko
Copy link
Member Author

radeksimko commented Jan 4, 2023

One more idea which came up while working on hashicorp/hcl-lang#177 is that we could reduce the completion steps in cases where there is exactly one candidate - e.g. attribute accepts string typed references and there's exactly one string typed reference.

Semi-relatedly we also could avoid TriggerSuggest: true in cases where we know there are no candidates but one possible downside with this is that number of suitable candidates may change at any time between offering completion and submitting it - so probably better to avoid this for the false negatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant