d2ir: References wip
This commit is contained in:
parent
0a19aeb367
commit
7721c8b2b4
1 changed files with 9 additions and 15 deletions
24
d2ir/d2ir.go
24
d2ir/d2ir.go
|
|
@ -316,8 +316,8 @@ type RefContext struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc RefContext) EdgeIndex() int {
|
func (rc RefContext) EdgeIndex() int {
|
||||||
for i, e := range rc.Context.Key.Edges {
|
for i, e := range rc.Key.Edges {
|
||||||
if e == rc.Context.Edge {
|
if e == rc.Edge {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -584,24 +584,18 @@ func (m *Map) appendKeyReferences(i int, kp *d2ast.KeyPath, refctx *RefContext)
|
||||||
KeyPath: kp,
|
KeyPath: kp,
|
||||||
Context: refctx,
|
Context: refctx,
|
||||||
})
|
})
|
||||||
|
if i+1 == len(kp.Path) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if f_m, ok := f.Composite.(*Map); ok {
|
if f_m, ok := f.Composite.(*Map); ok {
|
||||||
f_m.appendReferences(i+1, kp, refctx)
|
f_m.appendKeyReferences(i+1, kp, refctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Map) appendEdgeReferences(e *Edge, refctx *RefContext) {
|
func (m *Map) appendEdgeReferences(e *Edge, refctx *RefContext) {
|
||||||
sb := kp.Path[i]
|
e.References = append(e.References, EdgeReference{
|
||||||
f := m.Get([]string{sb.Unbox().ScalarString()})
|
|
||||||
if f == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
f.References = append(f.References, KeyReference{
|
|
||||||
String: sb,
|
|
||||||
KeyPath: kp,
|
|
||||||
Context: refctx,
|
Context: refctx,
|
||||||
})
|
})
|
||||||
if f_m, ok := f.Composite.(*Map); ok {
|
m.appendKeyReferences(0, refctx.Edge.Src, refctx)
|
||||||
f_m.appendReferences(i+1, kp, refctx)
|
m.appendKeyReferences(0, refctx.Edge.Dst, refctx)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue