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: Resolve unexpected block #1563

Open
1 task
radeksimko opened this issue Jan 5, 2024 · 0 comments
Open
1 task

New Code Action: Resolve unexpected block #1563

radeksimko opened this issue Jan 5, 2024 · 0 comments

Comments

@radeksimko
Copy link
Member

Background

We currently report the following configuration as invalid:

terraform {
  my_block {

  }
}

validation-rule-unexpected-block

There can be multiple reasons for an unknown block:

  • too old/new schema we use for validation
  • typo
  • some hallucinated code generated by AI

It may be difficult to find the best solution if we don't know or can't guess the reason. Removing a block is a solution relevant in some contexts and not others.

Proposal

  • Consider providing quick fix code action which resolves the above diagnostic by removing the block

Further Thoughts

It may be worth looking at how the LS could guess the reason and provide more helpful quick fixes.

For example:

  • we could compare the block name with valid block names more loosely, just like Terraform Core does in its didyoumean package, so that we can suggest correction from e.g. terrafrom {} to terraform {} etc.
  • attempt to compare block names with other versions of the provider schema
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