Skip to content

New Code Action: Generate local value declaration for an orphaned local.* reference #1564

Open
@radeksimko

Description

@radeksimko

Background

The existing validation logic currently aids users by reporting references to undeclared variables, such as below.

Screenshot 2024-01-05 at 17 06 43

There can be different reasons behind an "orphaned" reference (reference without corresponding declaration). It could be a result of an intentional removal. But it can also be because the user started using variable reference before declaring it.

The server could help in the latter case by generating the local value declaration for the user.

For example, user may start with:

output "example" {
  value = local.foo
}

and want to end up with:

locals {
  foo = "value"
}

output "example" {
  value = local.foo
}

Proposal

  • Provide quickfix code action for any undeclared local.* references which will generate locals entry with the empty value based on constraints surrounding the reference

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions