hashicorp / hashicorp/hcl

hclsyntax: Recovery of incomplete parenthesis

Open
#649 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

## Context

Similar to some earlier issues, we ran into an edge case while implementing support for operators and parenthesis (`ParenthesesExpr`) in the Terraform language server.

```hcl
attr = (
```

This is parsed as following:

```go
hclsyntax.Attribute{
Name: "attr",
Expr: &hclsyntax.LiteralValueExpr{
SrcRange: hcl.Range{
Start: hcl.Pos {Line: 2, Column: 1, Byte: 9},
End: hcl.Pos {Line: 2, Column: 1, Byte: 9}
}
},
SrcRange: hcl.Range{
Start: hcl.Pos {Line: 1, Column: 1, Byte: 0},
End: hcl.Pos {Line: 2, Column: 1, Byte: 9}
}
}
```

So while we can tell we are inside of an attribute and that the expression is part of the attribute - i.e. within its range, it remains awkward/difficult to figure out whether we are inside of the expression.

As with other reports related to recovery from incomplete configuration, the context is - again - enabling completion. Users would reasonably expect to be offered relevant completion in the above context, because it is exactly the nature of completion to complete the incomplete configuration.

## Proposal

Report/parse the above incomplete expression with the following range:

```go
hcl.Range{
Start: hcl.Pos {Line: 1, Column: 8, Byte: 7},
End: hcl.Pos {Line: 2, Column: 1, Byte: 9}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing hclsyntax parsing for incomplete ParenthesesExpr expressions and compare it with the existing recovery cases referenced in the issue. Reproduce the `attr = (` example, then verify that the incomplete expression receives the proposed range from line 1, column 8, byte 7 through line 2, column 1, byte 9.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.