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

New Code Action: Move a block into a file #1565

Open
12 tasks
radeksimko opened this issue Jan 5, 2024 · 0 comments
Open
12 tasks

New Code Action: Move a block into a file #1565

radeksimko opened this issue Jan 5, 2024 · 0 comments

Comments

@radeksimko
Copy link
Member

radeksimko commented Jan 5, 2024

Background

There is currently no documented convention by HashiCorp on the file name conventions and where exactly a block should reside. There are some known conventions folks have adopted though, such as

  • variable blocks in variables.tf
  • output blocks in outputs.tf

Users can do refactoring today by copying and pasting these blocks around. How easy that is will be relative to people's opinions, amount of code being refactored and probably other factors.

The server could make refactoring which involves moving blocks between files easier, especially for users who have keybinding for code actions and use them frequently when refactoring.

For example the user may start with main.tf

terraform {
  // ...
}
variable "foo" {}

and end with two files,

main.tf

terraform {
  // ...
}

variables.tf

variable "foo" {}

Proposal

  • Provide code action which can move a block into a new or existing file
    • check
    • data
    • import
    • locals
    • module
    • moved
    • output
    • provider
    • resource
    • terraform
    • variable

Needs research

It is not clear whether this code action would satisfy the definition of the standard kind refactor.extract. We may need to consider a different kind, or generic refactor.

Future thoughts

Eventually it may be useful to set and document conventions and provide more opinionated code actions, such as "move all variable blocks into variables.tf" and similar.

That is however not just implementation/technical work but a matter of getting buy in from involved teams internally on these opinions and documenting them first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant