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

Fill required fields for a new block #719

Closed
radeksimko opened this issue Aug 5, 2021 · 5 comments
Closed

Fill required fields for a new block #719

radeksimko opened this issue Aug 5, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request meta

Comments

@radeksimko
Copy link
Member

radeksimko commented Aug 5, 2021

Problem Statement

Users can today introduce a new block into their configuration via completion

2021-08-05 13 02 09

However the block is not considered complete/valid until it has all required attributes and blocks.
This means that users have to either scrolls over a potentially long list of attributes and blocks to add all required ones and/or consult documentation in a separate window.

It would be great if all required attributes and blocks were pre-filled for them.

Expected User Experience

New Block

Upon confirmation of label completion - such as resource type

Screenshot 2021-08-05 at 14 50 36

the editor would also pre-fill all required attributes and blocks

Screenshot 2021-08-05 at 14 54 06

Block with existing attributes/blocks

-> #801

Proposal

  • provide AdditionalTextEdits with required arguments and blocks for relevant label-based completion item (such as resource types, data source types and provider names)

See also hashicorp/terraform-ls#96

@jpogran
Copy link
Contributor

jpogran commented Aug 18, 2021

We were able to modify labelCandidatesFromDependentSchema to find all required attributes for the selected type and construct an AdditionalTextEdit array, however AddtionalTextEdit does not appear to support snippet completion syntax. This means that even though we can build the list of additional snippets, it won't be used for the main snippet completion

We abandoned that approach and instead moved to build a complete snippet with both the type selected and all required attributes and use that as the main TextEdit, in effect replacing the existing text the user just typed. This succeeded in the sense that the correct information was produced but failed in the sense that it was not displayed client side. Further investigation surmised that the additional content for the attributes exceeded the amount of data that could be received and displayed by the client.

This led us to the LSP resolve completion method. This would allow the user to received a list of types to select, then select the type, then receive only the required attributes for that type. This requires implementing a new request handler and parsing infrastructure, with some new design considerations, which is out of scope for this ticket. Once that work is complete, this ticket will be picked back up.

@radeksimko radeksimko assigned radeksimko and unassigned jpogran Aug 18, 2021
@770715
Copy link

770715 commented Aug 20, 2021

That would be a killer feature. It is implemented in the TF plugin for IntelliJ, and it's the only reason why I use IJ.

@radeksimko
Copy link
Member Author

radeksimko commented Oct 8, 2021

@jpogran implemented this as part of the following PRs which will be part of the upcoming LS / extension release:

As mentioned within these issues, the functionality will be (at least initially) opt-in via prefillRequiredFields config option under terraform-ls.experimentalFeatures.

We also plan to add code action that would provide comparable functionality for existing blocks, which is tracked under #801

@michal-kubicki
Copy link

That's great news. Thank you.

@github-actions
Copy link

github-actions bot commented Nov 8, 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 details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request meta
Projects
None yet
Development

No branches or pull requests

4 participants