The diff may be confusing, but there is just a few real changes being introduced:
decoupled & exposed function LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics which was previously just an implementation detail of loadModule()
exposed newModule(dir) as NewModule(dir) given that the above function will require caller to create the instance somehow
error handling is removed by assuming that that expression will always belong to the file being parsed, and therefore there's always a relevant byte slice to access and there should be no need to ask the parser - see below
The use case I have in mind for this is the Terraform language server, where we would benefit from not having to go through the tokenization and parsing twice. I assume that other callers like Terraform core might benefit too though as this library is used there as an "early config parser/decoder" and the same config would then be parsed again by a more detailed/precise decoder with more detailed schema AFAIK?
which would probably be cleaner, but the piece of code related to the error handling which is looking up more context in byte slice sadly makes that much more difficult and I didn't feel like it's a good idea to just remove it.
The diff may be confusing, but there is just a few real changes being introduced:
LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics
which was previously just an implementation detail ofloadModule()
newModule(dir)
asNewModule(dir)
given that the above function will require caller to create the instance somehowhttps://github.com/hashicorp/terraform-config-inspect/blob/c481b8bfa41ea9dca417c2a8a98fd21bd0399e14/tfconfig/load_hcl.go#L125-L139
The use case I have in mind for this is the Terraform language server, where we would benefit from not having to go through the tokenization and parsing twice. I assume that other callers like Terraform core might benefit too though as this library is used there as an "early config parser/decoder" and the same config would then be parsed again by a more detailed/precise decoder with more detailed schema AFAIK?
I originally wanted to propose something like
which would probably be cleaner, but the piece of code related to the error handling which is looking up more context in byte slice sadly makes that much more difficult and I didn't feel like it's a good idea to just remove it.
Another alternative interface is also this
but I'm unsure whether that's significantly better 🤔