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

Completion of references of matching complex types #830

Open
radeksimko opened this issue Mar 15, 2022 · 0 comments
Open

Completion of references of matching complex types #830

radeksimko opened this issue Mar 15, 2022 · 0 comments
Labels

Comments

@radeksimko
Copy link
Member

Discovered originally in hashicorp/vscode-terraform#990 (comment)

Background

The language server currently only provides completion of references to targets which are "directly addressable" and have a matching type.

e.g.

data "aws_availability_zones" "available" {
}

data "aws_subnet" "private" {
  count             = var.subnet_count
  availability_zone = data.aws_availability_zones.available. # HERE
}

158209328-7748677b-e487-4ecd-a705-43ade3a2411e

availability_zone field is of type string and available references targets under data.aws_availability_zones.available are the following:

  • data.aws_availability_zones.available.all_availability_zones (ScopeId: "data", Type: "cty.Bool")
  • data.aws_availability_zones.available.exclude_names (ScopeId: "data", Type: "cty.Set(cty.String)")
  • data.aws_availability_zones.available.exclude_zone_ids (ScopeId: "data", Type: "cty.Set(cty.String)")
  • data.aws_availability_zones.available.group_names (ScopeId: "data", Type: "cty.Set(cty.String)")
  • data.aws_availability_zones.available.id (ScopeId: "data", Type: "cty.String")
  • data.aws_availability_zones.available.names (ScopeId: "data", Type: "cty.List(cty.String)")
  • data.aws_availability_zones.available.state (ScopeId: "data", Type: "cty.String")
  • data.aws_availability_zones.available.zone_ids (ScopeId: "data", Type: "cty.List(cty.String)")

Therefore we end up picking just exact type matches data.aws_availability_zones.available.id and data.aws_availability_zones.available.state as both are of string type.

However, we have no way of knowing whether this is a final completion or just beginning and there are other relevant reference targets we could still offer. Sets are not directly addressable and there's no point of making them until #530 or #527 We can however try "descending" into lists, i.e. additionally suggest the following:

  • data.aws_availability_zones.available.names (ScopeId: "data", Type: "cty.List(cty.String)")
  • data.aws_availability_zones.available.zone_ids (ScopeId: "data", Type: "cty.List(cty.String)")

Proposal

Update type matching within hcl-lang to descend into lists and possibly maps and tuples, all of which are directly addressable via [] syntax.

https://github.com/hashicorp/hcl-lang/blob/d770b425fb2288fdcbf223b6955485a989dd3221/reference/targets.go#L78-L79

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

No branches or pull requests

1 participant