Skip to content

Set CloseBraceRange to last label in error-recovered blocks#786

Open
Yantrio wants to merge 1 commit intohashicorp:mainfrom
opentofu:block-range-error-recovery
Open

Set CloseBraceRange to last label in error-recovered blocks#786
Yantrio wants to merge 1 commit intohashicorp:mainfrom
opentofu:block-range-error-recovery

Conversation

@Yantrio
Copy link

@Yantrio Yantrio commented Feb 16, 2026

Description

When the HCL parser error-recovers from an incomplete block (no opening brace), Block.Range() only covered the type keyword, not the labels. This is because CloseBraceRange was set to ident.Range as a placeholder, so RangeBetween(TypeRange, CloseBraceRange) produced a range that ended at the type keyword.

This caused position-based lookups like OutermostBlockAtPos to miss positions within labels, which downstream affected things like completionAtPos in hcl-lang skipping incomplete blocks entirely and returning snippets instead of real label candidates.

This attempts to fix this by editing the finishParsingBodyBlock's error-recovery path, setting CloseBraceRange to the last label range (falling back to ident.Range if no labels exist). This ensures that the range includes more information than before.

Related Issue

How Has This Been Tested?

I've run the entire test suite and included new tests to cover the new functionality.

Signed-off-by: James Humphries <james@james-humphries.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments