MCPcopy
hub / github.com/hashicorp/hcl / decodeRangeFromBody

Method decodeRangeFromBody

cmd/hclspecsuite/test_file.go:301–329  ·  view source on GitHub ↗
(body hcl.Body)

Source from the content-addressed store, hash-verified

299}
300
301func (r *Runner) decodeRangeFromBody(body hcl.Body) (hcl.Range, hcl.Body, hcl.Diagnostics) {
302 var diags hcl.Diagnostics
303
304 rangeBody, remain, moreDiags := body.PartialContent(testFileRangeSchema)
305
306 diags = append(diags, moreDiags...)
307 if rangeBody == nil {
308 return hcl.Range{}, nil, diags
309 }
310
311 var Range hcl.Range
312 for _, block := range rangeBody.Blocks {
313 switch block.Type {
314 // We intentionally omit Filename here, because the test spec doesn't
315 // need to specify that explicitly: we can infer it to be the file
316 // path we pass to hcldec.
317 case "from":
318 Range.Start, moreDiags = r.decodePosFromBody(block.Body)
319 diags = append(diags, moreDiags...)
320 case "to":
321 Range.End, moreDiags = r.decodePosFromBody(block.Body)
322 diags = append(diags, moreDiags...)
323 default:
324 panic(fmt.Sprintf("unsupported block type %q", block.Type))
325 }
326 }
327
328 return Range, remain, diags
329}
330
331var testFileSchema = &hcl.BodySchema{
332 Attributes: []hcl.AttributeSchema{

Callers 2

Calls 2

decodePosFromBodyMethod · 0.95
PartialContentMethod · 0.65

Tested by

no test coverage detected