-
Notifications
You must be signed in to change notification settings - Fork 26
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
decoder: Add support for LiteralValue
as Constraint
#187
Conversation
1b308c0
to
0b459ab
Compare
LiteralValue
as Constraint
LiteralValue
as Constraint
0b459ab
to
1aa46b1
Compare
99eca7e
to
2e952d9
Compare
305645c
to
b8f42e4
Compare
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.
if editRange.End.Line != pos.Line { | ||
// account for quotes or brackets that are not closed | ||
editRange.End = pos | ||
} |
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.
Nitpick: This would not account for completion inside a (valid) multi-line expression, which is one of the reasons we use slightly more sophisticated solution for such an edge case, e.g. in Map
hcl-lang/decoder/expr_map_completion.go
Lines 143 to 148 in d469d16
// check any incomplete configuration up to a terminating character | |
fileBytes := m.pathCtx.Files[eType.Range().Filename].Bytes | |
recoveredBytes := recoverLeftBytes(fileBytes, pos, func(offset int, r rune) bool { | |
return isObjectItemTerminatingRune(r) && offset > recoveryPos.Byte | |
}) | |
trimmedBytes := bytes.TrimRight(recoveredBytes, " \t") |
Given that we only get to deal with primitive types here (which are mostly single-line), it should be fine to ignore. Multiline strings do exist (HEREDOC syntax) but we don't really use them in Terraform as constraint anywhere.
Implementing a perfect solution would be unnecessarily costly as we'd have to be looking for different terminating character or even a sequence of characters, depending on what type we can "guess".
TL;DR it's fine as is.
Side note - I am surprised that config such as this
attr = "foo
is parsed by HCL at all and returns expression with range that we can take advantage of here, because a lot of other invalid configuration variations end up missing from the AST entirely (including the attribute), which is also what motivated that recovery logic linked above. 😅
Part of hashicorp/terraform-ls#496
TODO