hcl icon indicating copy to clipboard operation
hcl copied to clipboard

Incorrect `srcRange` for files starting with a multiline comment

Open dbanck opened this issue 3 years ago • 1 comments

When a HCL file starts with a multiline comment, the SrcRange of the hclsyntax.Body starts after the multiline comment.

Test data

Example file starting with a multiline comment:

/********************************
 Some comment
********************************/

data "google_project" "project" {
  project_id = var.project_id
}

Example code for parsing the file:

f, _ := hclsyntax.ParseConfig(src, filename, pos)
body, _ := f.Body.(*hclsyntax.Body)
fmt.Println(body.Range())

Full example here: https://gist.github.com/dbanck/83e0e7936556eab2184d5d89e9d1feac

Expected behavior

SrcRange for the example file should be main.tf:1,1-8,1

Actual behavior

SrcRange for the example file is reported as main.tf:3,34-8,1

dbanck avatar Aug 29 '22 09:08 dbanck

Any updates on this? I'll still facing this as of today.

rickygodoy avatar Jan 20 '24 13:01 rickygodoy