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

textDocument/complete: Complete references to named values #38

Closed
radeksimko opened this issue Mar 24, 2020 · 3 comments
Closed

textDocument/complete: Complete references to named values #38

radeksimko opened this issue Mar 24, 2020 · 3 comments
Assignees
Labels

Comments

@radeksimko
Copy link
Member

radeksimko commented Mar 24, 2020

Context

Currently the LS completes block's known attributes and nested blocks per schema and naively assumes values are static.

Terraform language supports references to named values which are generally formatted as dot-based addresses, e.g.

variable "example" {
  default = "example-value"
}
data "aws_availability_zones" "names" {
}

can be referenced as var.example or data.aws_availability_zones.names respectively elsewhere in the configuration.

Requirements

Completing the references requires LS understanding a couple of things it doesn't understand today:

  • relationship between address format and block type
    • e.g. knowing that var.<name> belongs to variable block and evaluates to variable's value (which may come from its default)
  • context in which references are evaluated, for example
    • local values can be referenced between each other, but variables can not
    • backend blocks do not support any kind of interpolation
    • provider blocks have limited interpolation capabilities (e.g. via alias)
    • values have types and it would be suboptimal to suggest references that do not match the destination type (e.g. var.number for a string attribute)
  • whether the value is available locally within the configuration or from the state, e.g.
    • variable values would generally be local
    • data source and resource attributes would generally come from state, unless these attributes are referencing static values (such as variables)

How could we tackle this

This will likely require extensive design work to ensure stability and maintainability over time. There is a number of factors to consider, e.g.

For reasons above I would encourage discussing the design of the possible solution(s) here before attempting to raise a PR.

@Liquidmantis
Copy link

Liquidmantis commented Jul 10, 2020

Since this is the issue being referenced in the issues on autocomplete, I just wanted to say that All Autocomplete has been a good workaround for me in the interim. You have to load your project files so that it's aware of variables but it's transparent otherwise.

https://marketplace.visualstudio.com/items?itemName=Atishay-Jain.All-Autocomplete

@radeksimko
Copy link
Member Author

Initial support for references was added in (now merged) #485 which will be released in coming days. The same PR also includes some description of features added and links to follow-up issues covering features which were omitted from that initial PR.

With that in mind I'm going to close this issue but keep an eye out for the upcoming update (0.17.0).

@github-actions
Copy link

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 Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants