Skip to content

Commit

Permalink
add SrcRange to ExprSyntaxError
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarm committed Mar 13, 2024
1 parent 53ee54e commit 54e4175
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions hclsyntax/expression.go
Expand Up @@ -2019,6 +2019,7 @@ func (e *AnonSymbolExpr) StartRange() hcl.Range {
type ExprSyntaxError struct {
Placeholder cty.Value
ParseDiags hcl.Diagnostics
SrcRange hcl.Range
}

func (e *ExprSyntaxError) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
Expand All @@ -2030,9 +2031,9 @@ func (e *ExprSyntaxError) walkChildNodes(w internalWalkFunc) {
}

func (e *ExprSyntaxError) Range() hcl.Range {
return hcl.Range{}
return e.SrcRange
}

func (e *ExprSyntaxError) StartRange() hcl.Range {
return hcl.Range{}
return e.SrcRange
}
2 changes: 2 additions & 0 deletions hclsyntax/parser.go
Expand Up @@ -1173,6 +1173,7 @@ func (p *parser) finishParsingFunctionCall(name Token) (Expression, hcl.Diagnost
return &ExprSyntaxError{
ParseDiags: hcl.Diagnostics{&diag},
Placeholder: cty.DynamicVal,
SrcRange: hcl.RangeBetween(name.Range, nextName.Range),
}, diags
}

Expand Down Expand Up @@ -1209,6 +1210,7 @@ func (p *parser) finishParsingFunctionCall(name Token) (Expression, hcl.Diagnost
return &ExprSyntaxError{
ParseDiags: hcl.Diagnostics{&diag},
Placeholder: cty.DynamicVal,
SrcRange: hcl.RangeBetween(name.Range, openTok.Range),
}, diags
}

Expand Down
8 changes: 8 additions & 0 deletions hclsyntax/parser_test.go
Expand Up @@ -2583,6 +2583,10 @@ block "valid" {}
},
},
},
SrcRange: hcl.Range{
Start: hcl.Pos{Line: 1, Column: 5, Byte: 4},
End: hcl.Pos{Line: 2, Column: 1, Byte: 24},
},
},
SrcRange: hcl.Range{
Filename: "",
Expand Down Expand Up @@ -2636,6 +2640,10 @@ block "valid" {}
},
},
},
SrcRange: hcl.Range{
Start: hcl.Pos{Line: 1, Column: 5, Byte: 4},
End: hcl.Pos{Line: 2, Column: 1, Byte: 14},
},
},
SrcRange: hcl.Range{
Filename: "",
Expand Down

0 comments on commit 54e4175

Please sign in to comment.