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

Align hcl.Block & hclsyntax.Block DefRange #487

Merged
merged 1 commit into from
Sep 22, 2021
Merged

Conversation

radeksimko
Copy link
Member

This patch fixes a minor discrepancy between hclsyntax and hcl in how DefRange is computed for a block.

DefRange of the "higher-level" hcl.Block (typically used by most applications) ends with the last label.

DefRange of the "lower-level" hclsyntax.Block ended with the opening brace { (i.e. at least 2 characters further).

Here we align the low-level API with the high-level one, meaning that most consumers should not be affected by this change, partly because they use hcl.Block (which isn't changing) or because they use DefRange to inform some non-critical decisions such as enriching diagnostics.


I ran into this discrepancy when working on adding support to JSON syntax to the language server in hashicorp/hcl-lang#88

This patch fixes a minor discrepancy between `hclsyntax` and `hcl`
in how DefRange is computed for a block.

DefRange of the "higher-level" `hcl.Block` (typically used by most applications)
ends with the last label.

DefRange of the "lower-level" `hclsyntax.Block` ended with the opening brace `{`
(i.e. at least 2 characters further).

Here we align the low-level API with the high-level one, meaning that most consumers
should not be affected by this change, partly because they use
`hcl.Block` (which isn't changing) or because they use DefRange
to inform some non-critical decisions such as enriching diagnostics.
@radeksimko radeksimko added the bug label Sep 22, 2021
Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@radeksimko radeksimko merged commit e84201c into main Sep 22, 2021
@radeksimko radeksimko deleted the align-def-range branch September 22, 2021 16:10
radeksimko added a commit to hashicorp/hcl-lang that referenced this pull request Jan 5, 2022
radeksimko added a commit to hashicorp/hcl-lang that referenced this pull request Jan 5, 2022
)

* build(deps): bump github.com/hashicorp/hcl/v2 from 2.10.1 to 2.11.1

Bumps [github.com/hashicorp/hcl/v2](https://github.com/hashicorp/hcl) from 2.10.1 to 2.11.1.
- [Release notes](https://github.com/hashicorp/hcl/releases)
- [Changelog](https://github.com/hashicorp/hcl/blob/main/CHANGELOG.md)
- [Commits](hashicorp/hcl@v2.10.1...v2.11.1)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/hcl/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update position lookup for outside of body

This is to reflect upstream change hashicorp/hcl#487

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Radek Simko <radek.simko@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants