hcl
hcl copied to clipboard
Make *AtPos functions work for incomplete config
HCL Template
provider ""
Parsing logic
package main
import (
"log"
"github.com/kr/pretty"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
)
func main() {
c, diags := hclsyntax.ParseConfig([]byte(`
provider ""
`), "test.tf", hcl.InitialPos)
if diags.HasErrors() {
log.Printf("diags: %s", diags.Error())
}
log.Printf("config: %s", pretty.Sprint(c))
b := c.OutermostBlockAtPos(hcl.Pos{
Line: 2,
Column: 11,
Byte: 13,
})
log.Printf("block: %s", pretty.Sprint(b))
}
Expected behavior
OutermostBlockAtPos
in the above example returns the incomplete block.
Actual behavior
OutermostBlockAtPos
in the above example returns nil
.
Steps to reproduce
go run
the above code snippet
Use Cases
When users are editing config and ask the language server via the IDE for completion, it's expectable they will want to complete an incomplete block, such as the above and the language server will therefore need to know where exactly in the incomplete block they're requesting completion.