Skip to content

textDocument/references always returns [] #127

@fullykubed

Description

@fullykubed

Community note

Tip

👋 Hi there, OpenTofu community! The OpenTofu team prioritizes issues based on upvotes. Please make sure to upvote (👍) this issue and describe how it affects you in detail in the comments to show your support.

Language Server Version

0.1.1

OpenTofu Version

OpenTofu v1.10.6 on linux_amd64

Client Version

NVIM v0.11.4 interacting with nvim.lsp.config

OpenTofu Configuration

terraform {
  required_providers {
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = "2.34.0"
    }
    helm = {
      source  = "hashicorp/helm"
      version = "2.12.1"
    }
  }
}

variable "test" {

}

locals {
  test = var.test
}

Steps to Reproduce

  1. Create a module with a main.tf with the above contents.
  2. Observe that go-to-definition on var.test works as expected.
  3. Attempt to show the references for test.

Expected Behavior

It should return one reference, the usage in the locals block.

Actual Behavior

tofu-ls returns an empty array.

Example logs:

[ERROR][2025-10-07 20:23:11] ...p/_transport.lua:36     "rpc"   "tofu-ls"       "stderr"        '2025/10/07 20:23:11 opts.go:215: Received request batch of size 1 (qlen=0)\n2025/10/07 20:23:11 opts.go:215: Dequeued request batch of length 1 (qlen=0)\n2025/10/07 20:23:11 rpc_logger.go:34: Incoming request for "textDocument/references" (ID 44): {"textDocument":{"uri":"file:///home/jack/repos/nixos-config/test/main.tf"},"position":{"line":12,"character":11}}\n2025/10/07 20:23:11 rpc_logger.go:55: Response to "textDocument/references" (ID 44): []\n2025/10/07 20:23:11 opts.go:215: Completed 1 requests [3.02154ms elapsed]\n'
[ERROR][2025-10-07 20:23:38] ...p/_transport.lua:36     "rpc"   "tofu-ls"       "stderr"        '2025/10/07 20:23:38 opts.go:215: Received request batch of size 1 (qlen=0)\n2025/10/07 20:23:38 opts.go:215: Dequeued request batch of length 1 (qlen=0)\n2025/10/07 20:23:38 rpc_logger.go:34: Incoming request for "textDocument/references" (ID 45): {"textDocument":{"uri":"file:///home/jack/repos/nixos-config/test/main.tf"},"position":{"line":12,"character":11}}\n2025/10/07 20:23:38 rpc_logger.go:55: Response to "textDocument/references" (ID 45): []\n2025/10/07 20:23:38 opts.go:215: Completed 1 requests [2.115459ms elapsed]\n'

It appears there is some sort of silent error in building the reference index:

 OpTypeDecodeReferenceTargets ... (err = %!s(<nil>), deferredJobs: [])
  OpTypeDecodeReferenceOrigins ... (err = %!s(<nil>), deferredJobs: [])

The :LSPInfo:

- tofu_ls (id: 2)
  - Version: 0.1.1
  - Root directory: ~/repos/nixos-config/test
  - Command: { "tofu-ls", "serve" }
  - Settings: vim.empty_dict()
  - Attached buffers: 67

Gist

No response

Workarounds

No.

I also tried to use terraform-ls and ran into the same issue.

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions