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

Unable to find definitions or declarations in many cases #990

Closed
johnkeates opened this issue Mar 13, 2022 · 10 comments
Closed

Unable to find definitions or declarations in many cases #990

johnkeates opened this issue Mar 13, 2022 · 10 comments
Labels

Comments

@johnkeates
Copy link

johnkeates commented Mar 13, 2022

Issue Description

Unable to find definition or declaration

Environment Information

Terraform Information

Version: 1.1.5
Platform: darwin_amd64
Outdated: true

.vscode/extensions/hashicorp.terraform-2.20.0/bin/terraform-ls version:
0.25.2
platform: darwin/amd64
go: go1.17.5
compiler: gc

Visual Studio Code

Name Version
Operating System Darwin x64 21.3.0
VSCode 1.65.2

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
aws-toolkit-vscode amazonwebservices 1.36.0
better-cpp-syntax jeff-hykin 1.15.13
cmake twxs 0.0.17
cmake-tools ms-vscode 1.9.2
code-groovy marlon407 0.1.2
cpptools ms-vscode 1.8.4
cpptools-extension-pack ms-vscode 1.1.0
cpptools-themes ms-vscode 1.0.0
csharp ms-dotnettools 1.24.1
doxdocgen cschlosser 1.4.0
go golang 0.32.0
gradle-language naco-siren 0.2.3
java redhat 1.4.0
jupyter ms-toolsai 2022.2.1030672458
jupyter-keymap ms-toolsai 1.0.0
jupyter-renderers ms-toolsai 1.0.6
opa tsandall 0.10.0
plantuml jebbs 2.17.2
python ms-python 2022.2.1924087327
remote-containers ms-vscode-remote 0.224.2
remote-ssh ms-vscode-remote 0.76.1
remote-ssh-edit ms-vscode-remote 0.76.1
remote-wsl ms-vscode-remote 0.64.2
saltstack korekontrol 0.0.9
shell-format foxundermoon 7.2.2
synthwave-vscode RobbOwen 0.1.11
terraform hashicorp 2.20.0
vscode-docker ms-azuretools 1.20.0
vscode-jetbrains-keybindings isudox 0.1.9
vscode-power-mode hoovercj 3.0.1
vscode-pylance ms-python 2022.3.1
vscode-yaml redhat 1.5.1
xml DotJoshJohnson 2.5.1

Extension Logs

Find this from the first few lines of the relevant Output pane:
View -> Output -> 'HashiCorp Terraform'

2022/03/13 23:32:59 hover.go:37: Looking for hover data at "vpc_peering.tf" -> hcl.Pos{Line:17, Column:70, Byte:499}
2022/03/13 23:32:59 hover.go:39: received hover data: (*lang.HoverData)(nil)
2022/03/13 23:32:59 rpc_logger.go:45: Error for "textDocument/hover" (ID 90): [-32098] vpc_peering.tf (17,70): unsupported expression (*hclsyntax.FunctionCallExpr)
2022/03/13 23:32:59 opts.go:254: Completed 1 requests [14.805875ms elapsed]
[Error - 11:32:59 PM] Request textDocument/hover failed.
  Message: vpc_peering.tf (17,70): unsupported expression (*hclsyntax.FunctionCallExpr)
  Code: -32098 
2022/03/13 23:32:59 hover.go:37: Looking for hover data at "vpc_peering.tf" -> hcl.Pos{Line:17, Column:70, Byte:499}
2022/03/13 23:32:59 hover.go:39: received hover data: (*lang.HoverData)(nil)
2022/03/13 23:32:59 rpc_logger.go:45: Error for "textDocument/hover" (ID 97): [-32098] vpc_peering.tf (17,70): unsupported expression (*hclsyntax.FunctionCallExpr)
2022/03/13 23:32:59 opts.go:254: Completed 1 requests [17.461433ms elapsed]
[Error - 11:32:59 PM] Request textDocument/hover failed.
  Message: vpc_peering.tf (17,70): unsupported expression (*hclsyntax.FunctionCallExpr)
  Code: -32098 

The HCL looks like this:

data "aws_availability_zones" "available" {
}

data "aws_subnet" "private" {
  count             = var.subnet_count
  availability_zone = element(data.aws_availability_zones.available.names, count.index)

  tags = {
    Type = "private"
  }

  vpc_id = var.vpc_id
}

Hovering or navigating to usage/definition/declaration doesn't work in most cases and simply reports that it cannot be found. It can find Data Source Type aws_availability_zones but hovering data.aws_availability_zones.available.names doesn't do anything, neither does navigating to the declaration of data.aws_availability_zones.available.

Typing data.aws_availability_zones.av doesn't yield autocompletion for data.aws_availability_zones.available either. It can do data.aws_avail and complete data.aws_availability_zones but beyond that it's no use.

Other things it can't find:

  • symlinked HCL
  • cross-module declarations
  • submodule declarations
  • Variables in TFVars

I've tried to find out if there is a list of known issues for finding usages/definitions but there doesn't seem to be a detailed "it does not cross this type of boundary" list of things it tries to resolve.

Example of a variable that is filled by tfvars:

variables.tf

variable "namespace" {
  description = "The group this environment belongs to. Not optional."
}

environment.auto.tfvars

namespace = "hyperion"

Can't navigate in either direction via references/declaration.

@radeksimko
Copy link
Member

Hi @johnkeates
It seems there is a number of different cases you described. I'll try to break them down based on what you shared.

It can find Data Source Type aws_availability_zones but hovering data.aws_availability_zones.available.names doesn't do anything, neither does navigating to the declaration of data.aws_availability_zones.available.

Nested expressions, such as element(data.aws_availability_zones.available.names, count.index) have a very limited support at this point. See #641 and hashicorp/terraform-ls#496, hashicorp/terraform-ls#37 or hashicorp/terraform-ls#495 in particular.

Typing data.aws_availability_zones.av doesn't yield autocompletion for data.aws_availability_zones.available either. It can do data.aws_avail and complete data.aws_availability_zones but beyond that it's no use.

Lack of completion items which require knowledge of state is a known issue described in #734 or #652 - this would affect case like this
Screenshot 2022-03-14 at 15 17 36

symlinked HCL

Can you be a bit more specific here about the setup? I am aware that we don't explicitly resolve symlinks in the language, as mentioned in hashicorp/terraform-ls#241 but I would be curious about the context in which this is causing you issues - i.e. where do you create a symlink in your hierarchy and where does it point to?

cross-module declarations

These should work as long as the modules are installed, i.e. you ran terraform get or terraform init in the directory where you have module blocks declared. Otherwise there is nowhere to "go-to" in "go-to-definition" locally, if the modules aren't installed. Here is an example of what that may look like

Screen.Recording.2022-03-14.at.15.37.42.mov

We generally can't provide go-to-definition for remote modules until these are installed since there's nowhere to "go" (no files available locally to point to). However we do plan to index local modules even when these are not installed and provide all relevant functionality you see above. See more at hashicorp/terraform-ls#724 and hashicorp/terraform-ls#598

Aside from that for remote modules hosted in the Registry we plan to provide input and output completion, which is described in hashicorp/terraform-ls#599

submodule declarations

Can you be more specific about what you mean here and how does it differ from "cross-module declarations"?

Variables in TFVars

We implemented this recently as part of hashicorp/terraform-ls#727 which will be available in the upcoming release of LS and extension planned to be released likely this week. You can also try it out early via our preview extension https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform-preview


It is unclear to me why this completion here doesn't bring all 4 documented attributes (group_names, id, names, zone_ids):
Screenshot 2022-03-14 at 15 15 37

That I would expect to work as there is no remote state involved, unlike in my example above.


A side note on your configuration, element() is a legacy way of accessing an array in Terraform language. You can use the following notation:

availability_zone = data.aws_availability_zones.available.names[count.index]

which has the exact same meaning as it had in older versions of the language.

@johnkeates
Copy link
Author

johnkeates commented Mar 14, 2022

Hi @radeksimko thank you for your extensive reply! I'll try to get some code anonymised and make screen recordings to show the effects I was writing about. Technically this is a bit of a compound issue which is not great form a ticket perspective, but if it turns out they are really separate issues it might be best to split it out (the ones you referred are indeed what I was looking for but couldn't find initially).

As for the initialisation, I do work on active environments so the modules are all available in .terraform, and navigation (which is broken in different ways) in IntelliJ does work.

@radeksimko
Copy link
Member

I have opened a separate issue for the problem I was confused about above: hashicorp/terraform-ls#830

@johnkeates Is there any other problem you ran into which we don't track yet? If not, I'd like to close this issue and recommend subscribing to the individual ones which are also more easily addressable for us from maintenance perspective.

@johnkeates
Copy link
Author

@radeksimko Yes, there are a few other issues but I'll have to check with the existing ones to see if they are tracked with different descriptions. Right now life and work are getting in the way a little but I think closing this one in favour of more specialised individual issues is the best way to keep moving.

@johnkeates
Copy link
Author

johnkeates commented Mar 17, 2022

Example of a rather simple "Go to definition/declaration" thing that is two nearly identical references where one works but the other doesn't. It's from an active environment that is applied so at the very least the HCL is correct.

goto declaration

@radeksimko
Copy link
Member

@johnkeates If you say it's valid syntax then I'm guessing this one may be covered under hashicorp/terraform-ls#583

Can you check what's the variable type of argocd_helm_release within the module? In order for it to work currently the variable being passed (as declared on the right) would need to have same/comparable default or the following type:

variable "argocd_helm_release" {
  type = object({
    namespace = string
  })
}

@radeksimko radeksimko closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2022
@AlbertoMonteiro
Copy link

I have faced some cases that happens too, for example

- app
  - main.tf
- module
  - main.tf
  - variables.tf

image

the tooling help me to see the structure of many_configs, but when I have already added some, it doesnt work anymore

image

no more smart auto complete =(

if I hover, it shows the definition, but would be nice the completion for the properties of the object

image

@radeksimko
Copy link
Member

@AlbertoMonteiro This is a known issue we generally track under #641 or more specifically under hashicorp/terraform-ls#496

@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 Aug 25, 2022
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

3 participants