-
Notifications
You must be signed in to change notification settings - Fork 601
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
add ExprSyntaxError
#668
add ExprSyntaxError
#668
Conversation
…ails for namespaced functions
hclsyntax/expression.go
Outdated
} | ||
|
||
func (e *ExprSyntaxError) Range() hcl.Range { | ||
return hcl.Range{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a valid Range we could return here? Maybe from the diagnostic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the simplest approach would be to add SourceRange
as a field in ExprSyntaxError
and then have the parser decide what range to "blame" for the error.
As you noted, the parser already ought to be picking source ranges to go into the diagnostics anyway, and so I think it shouldn't be a big hardship to choose one of those ranges to also write into that field, and then we can keep it explicit and thus hopefully the ranges are more likely to be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Added SrcRange
to that struct and set the same range as in the diagnostic 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! 🎉
Thanks for the review! Went ahead and merged it. |
As suggested by @apparentlymart in this review comment this PR introduces a
ExprSyntaxError
which is returned instead ofnil
when an invalid namespaced function is encountered during parsing. This makes it easier to walk / inspect the parse result even when it was invalid (as e.g. required in the Terraform Language server) without the need to check fornil
expressions all over the place.This PR supersedes #665