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

Function navigationStepsRev

json/navigation.go:35–73  ·  view source on GitHub ↗
(v node, offset int)

Source from the content-addressed store, hash-verified

33}
34
35func navigationStepsRev(v node, offset int) []string {
36 switch tv := v.(type) {
37 case *objectVal:
38 // Do any of our properties have an object that contains the target
39 // offset?
40 for _, attr := range tv.Attrs {
41 k := attr.Name
42 av := attr.Value
43
44 switch av.(type) {
45 case *objectVal, *arrayVal:
46 // okay
47 default:
48 continue
49 }
50
51 if av.Range().ContainsOffset(offset) {
52 return append(navigationStepsRev(av, offset), "."+k)
53 }
54 }
55 case *arrayVal:
56 // Do any of our elements contain the target offset?
57 for i, elem := range tv.Values {
58
59 switch elem.(type) {
60 case *objectVal, *arrayVal:
61 // okay
62 default:
63 continue
64 }
65
66 if elem.Range().ContainsOffset(offset) {
67 return append(navigationStepsRev(elem, offset), fmt.Sprintf("[%d]", i))
68 }
69 }
70 }
71
72 return nil
73}

Callers 1

ContextStringMethod · 0.85

Calls 2

ContainsOffsetMethod · 0.80
RangeMethod · 0.65

Tested by

no test coverage detected