Empowering OpenTofu Developers with LSP – Smart Text Editor Integration

OpenTofu Language Server Protocol delivers IDE-quality features—auto-completion, diagnostics, schema validation—directly in your text editor.

Published: November 24, 2025

Coverage of OpenTofu Day North America 2025 presentation (November 10, 2025)

At OpenTofu Day North America 2025, Diógenes Fernandes, an OpenTofu Core Engineer at Gruntwork, demonstrated how the Language Server Protocol (LSP) is revolutionizing the way developers work with Infrastructure as Code (IaC) in their favorite text editors. Rather than being locked into heavyweight IDEs, developers can now get IDE-like capabilities directly in VS Code, Neovim, Emacs, and other editors through the power of Tofu-LS, the OpenTofu Language Server.

What is the Language Server Protocol?

The Language Server Protocol represents a major shift in how language tooling works. Created by Microsoft in 2015 and open-sourced in 2016 (with contributions from CodeEnvy and RedHat), LSP provides a standardized communication protocol between text editors and language servers.

Before LSP, supporting multiple editors meant solving what's known as the M × N problem: if you had M different editors and N language servers, you'd need to write M × N integrations. LSP elegantly transforms this into an M + N problem – each editor only needs to understand LSP, and each language server only needs to implement LSP. This means one language server can power features across all editors.

How LSP Works

LSP operates through a simple JSON-RPC protocol. When a developer hovers over code, for example, the editor sends a request like:

{
  "jsonrpc": "2.0",
  "method": "textDocument/hover",
  "params": {
    "textDocument": "file:///~/tofu-project/main.tf",
    "position": { "line": 1, "character": 2 }
  },
  "id": 1
}

The language server processes this and returns relevant information:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "contents": {
      "kind": "markdown",
      "value": "**value** _required, any type_\n\nValue, typically a reference to an attribute of a resource or a data source"
    }
  }
}

This simple, stateless protocol enables rich developer experiences without the overhead of full IDE installations.

Introducing Tofu-LS: OpenTofu's Language Server

Tofu-LS is OpenTofu's implementation of the Language Server Protocol, created as a fork of the Terraform Language Server. It brings OpenTofu's powerful Infrastructure as Code capabilities to developers working in their preferred text editors.

Supported Editors:

  • VS Code (through the vscode-opentofu extension)
  • Neovim
  • Emacs
  • And any editor that supports LSP

Core Features:

  1. Auto-completion – Complete HCL (HashiCorp Configuration Language) syntax with intelligent suggestions for variables, resources, and outputs
  2. Hover Documentation – Hover over any attribute to see its schema, required/optional status, and description
  3. Go-to-Definition – Jump directly to resource and variable definitions
  4. Syntax Highlighting – Proper highlighting for OpenTofu configuration files
  5. Real-time Diagnostics – Catch errors immediately as you type
  6. Code Actions – Quick fixes and refactoring suggestions
  7. Command Execution – Integrated commands like tofu init and tofu validate

Schema Validation: The Smart Part

One of Tofu-LS's most powerful features is its ability to understand OpenTofu schemas and validate your code against them. This is where things get technical and impressive.

Tofu-LS uses hcl-lang, a library that provides building blocks for HCL2-based language servers. It transforms the Abstract Syntax Tree (AST) of your HCL code into a schema that Tofu-LS can understand and validate against.

For example, when you define a resource like:

resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
  invalid_attribute = "value"  # ← Error caught here
}

Tofu-LS immediately detects that invalid_attribute is not a valid attribute for aws_s3_bucket and reports it as an error.

Provider Schema Support

Tofu-LS supports schema validation for OpenTofu providers in two ways:

  1. Bundled Providers: Core providers are bundled with Tofu-LS, providing immediate schema support
  2. Registry Integration: For other providers, Tofu-LS fetches schemas from the OpenTofu Registry, filtering based on your operating system and architecture

This means whether you're using common providers like Kubernetes, Helm, or Azure RM, or more specialized providers, Tofu-LS adapts to your needs automatically.

The Diagnostic Experience

Tofu-LS supports both pull and push diagnostics. With push diagnostics, the language server proactively sends error notifications to your editor using the textDocument/publishDiagnostics method. This creates that familiar IDE experience where errors appear as you type:

resource "aws_s3_bucket" "name" {
  bucket = "test"
  invalid_name = "test"
}

❌ Unexpected attribute: An attribute named "invalid_name" is not expected here

What's Next for Tofu-LS?

The OpenTofu community has an ambitious roadmap for Tofu-LS:

  • Refactor Capabilities – Symbol renaming across projects
  • Improved References & Definitions – Better jump-to-definition and find-references support
  • Performance Optimization – Handling large-scale OpenTofu projects with thousands of resources more efficiently

Getting Started with Tofu-LS

Tofu-LS is available in multiple package managers and editors:

Conclusion

The Language Server Protocol brings the power of OpenTofu to your text editor of choice, without compromise. By standardizing the communication between editors and language servers, LSP eliminates the need for duplicated tooling while giving developers a modern, responsive coding experience.

Tofu-LS represents the OpenTofu community's commitment to making Infrastructure as Code accessible, efficient, and enjoyable – whether you're a seasoned DevOps engineer or just starting with IaC.