Commands
September 3, 2025 ยท View on GitHub
The server exposes the following executable commands via LSP to clients. Typically these commands are not invokable by end-users automatically. Instead this serves as a documentation for client maintainers, and clients may expose these e.g. via command palette where appropriate.
Every care is taken to avoid breaking changes, but these interfaces should not be considered stable yet and may change.
Either way clients should always follow LSP spec in the sense
that they check whether a command is actually supported or not
(via ServerCapabilities.executeCommandProvider.commands).
Command Prefix
All commands use tofu-ls. prefix to avoid any conflicts
with commands registered by any other language servers user
may be using at the same time.
Some clients may also choose to generate additional prefix where e.g. the language server runs in multiple instances and registering the same commands would lead to conflicts.
This can be passed as part of initializationOptions,
as documented in Settings.
Arguments
All commands accept arguments as string arrays with = used
as a separator between key and value. i.e.
{
"command": "command-name",
"arguments": ["key=value"]
}
Supported Commands
tofu.init
Runs tofu init using available tofu installation from $PATH.
Arguments:
uri- URI of the directory in which to runtofu init
Outputs:
Error is returned e.g. when tofu is not installed, or when execution fails,
but no output is returned if init successfully finishes.
tofu.validate
Runs tofu validate using available tofu installation from $PATH.
Any violations are published back the the client via textDocument/publishDiagnostics notification.
Diagnostics are not persisted and any document change will cause them to be lost.
Arguments:
uri- URI of the directory in which to runtofu validate
Outputs:
Error is returned e.g. when tofu is not installed, or when execution fails,
but no output is returned if validate successfully finishes.
module.callers
In OpenTofu module hierarchy "callers" are modules which call another module
via module "..." { blocks.
Language server will attempt to discover any module hierarchy within the workspace
and this command can be used to obtain the data about such hierarchy, which
can be used to hint the user e.g. where to run init or validate from.
Arguments:
uri- URI of the directory of the module in question, e.g.file:///path/to/network
Outputs:
v- describes version of the format; Will be used in the future to communicate format changes.callers- array of any modules found in the workspace which call the module in questionuri- URI of the directory (absolute path)
{
"v": 0,
"callers": [
{
"uri": "file:///path/to/dev"
},
{
"uri": "file:///path/to/prod"
}
]
}
module.calls
List of modules called by the module under the given URI.
Empty array may be returned when e.g.
- the URI doesn't represent a module
- the configuration is invalid
- there are no module calls
The data is sourced from the declared modules inside the files of the module.
Arguments:
uri- URI of the directory of the module in question, e.g.file:///path/to/network
Outputs:
v- describes version of the format; Will be used in the future to communicate format changes.module_calls- array of modules which are called from the module in questionname- the reference name of this particular module (i.e.networkfrommodule "network" { ...)source_addr- human-readable version of the source address given for this module call (e.g.terraform-aws-modules/eks/aws)version- version constraint of the module call; applicable to modules hosted by the OpenTofu Registry (e.g.~> 1.0source_type- source of the OpenTofu module, e.g.githubortfregistrydocs_link- a link to the module documentation; if availabledependent_modules- DEPRECATED (always empty inv0.29+) - array of dependent modules with the same structure asmodule_calls
{
"v": 0,
"module_calls": [
{
"name": "child",
"source_addr": "./child",
"source_type": "local",
"dependent_modules": []
},
{
"name": "vpc",
"source_addr": "terraform-aws-modules/vpc/aws",
"version": "3.11.0",
"source_type": "tfregistry",
"docs_link": "https://search.opentofu.org/module/terraform-aws-modules/vpc/aws/v3.11.0",
"dependent_modules": []
}
]
}
module.providers
Provides information about the providers of the current module, including requirements and installed version.
Arguments:
uri- URI of the directory of the module in question, e.g.file:///path/to/network
Outputs:
v- describes version of the format; Will be used in the future to communicate format changes.provider_requirements- map of provider FQN string to requirements objectdisplay_name- a human-readable name of the provider (e.g.hashicorp/aws)version_constraint- a comma-separated list of version constraints (e.g.>= 1.0, < 1.2)docs_link- a link to the provider documentation; if available
installed_providers- map where key is the provider FQN and value is the installed version of the provider; can be empty if none are installed
{
"v": 0,
"provider_requirements": {
"registry.opentofu.org/hashicorp/aws": {
"display_name": "hashicorp/aws",
"version_constraint": "~> 3.64.0",
"docs_link": "https://search.opentofu.org/provider/hashicorp/aws/latest"
}
},
"installed_providers": {
"registry.opentofu.org/hashicorp/aws": "3.64.2"
}
}
module.opentofu
Provides information about the tofu binary version for the current module.
Arguments:
uri- URI of the directory of the module in question, e.g.file:///path/to/network
Outputs:
v- describes version of the format; Will be used in the future to communicate format changes.required_version- Version constraint specified in configurationdiscovered_version- Version discovered fromtofu version --jsonin the directory specified inuri
{
"v": 0,
"required_version": "~> 0.15",
"discovered_version": "1.1.0"
}