Merge pull request #1874 from alixander/make-writeable-refs-public
d2oracle: make get writeable refs public
This commit is contained in:
commit
7d84b7c1b9
3 changed files with 29 additions and 25 deletions
|
|
@ -146,6 +146,10 @@ func (gs *dslGenState) edge() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if src == dst && gs.nodeShapes[dst] == d2target.ShapeSequenceDiagram {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
srcArrow := "-"
|
srcArrow := "-"
|
||||||
if gs.randBool() {
|
if gs.randBool() {
|
||||||
srcArrow = "<"
|
srcArrow = "<"
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ func ReconnectEdge(g *d2graph.Graph, boardPath []string, edgeKey string, srcKey,
|
||||||
|
|
||||||
refs := edge.References
|
refs := edge.References
|
||||||
if baseAST != g.AST {
|
if baseAST != g.AST {
|
||||||
refs = getWriteableEdgeRefs(edge, baseAST)
|
refs = GetWriteableEdgeRefs(edge, baseAST)
|
||||||
if len(refs) == 0 || refs[0].ScopeAST != baseAST {
|
if len(refs) == 0 || refs[0].ScopeAST != baseAST {
|
||||||
// TODO null
|
// TODO null
|
||||||
return nil, OutsideScopeError{}
|
return nil, OutsideScopeError{}
|
||||||
|
|
@ -387,7 +387,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
|
||||||
|
|
||||||
var maybeNewScope *d2ast.Map
|
var maybeNewScope *d2ast.Map
|
||||||
if baseAST != g.AST || imported {
|
if baseAST != g.AST || imported {
|
||||||
writeableRefs := getWriteableRefs(obj, baseAST)
|
writeableRefs := GetWriteableRefs(obj, baseAST)
|
||||||
for _, ref := range writeableRefs {
|
for _, ref := range writeableRefs {
|
||||||
if ref.MapKey != nil && ref.MapKey.Value.Map != nil {
|
if ref.MapKey != nil && ref.MapKey.Value.Map != nil {
|
||||||
maybeNewScope = ref.MapKey.Value.Map
|
maybeNewScope = ref.MapKey.Value.Map
|
||||||
|
|
@ -414,7 +414,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
|
||||||
writeableLabelMK := true
|
writeableLabelMK := true
|
||||||
var objK *d2ast.Key
|
var objK *d2ast.Key
|
||||||
if baseAST != g.AST || imported {
|
if baseAST != g.AST || imported {
|
||||||
writeableRefs := getWriteableRefs(obj, baseAST)
|
writeableRefs := GetWriteableRefs(obj, baseAST)
|
||||||
if len(writeableRefs) > 0 {
|
if len(writeableRefs) > 0 {
|
||||||
objK = writeableRefs[0].MapKey
|
objK = writeableRefs[0].MapKey
|
||||||
}
|
}
|
||||||
|
|
@ -497,7 +497,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
|
||||||
imported = IsImportedEdge(baseAST, edge)
|
imported = IsImportedEdge(baseAST, edge)
|
||||||
refs := edge.References
|
refs := edge.References
|
||||||
if baseAST != g.AST || imported {
|
if baseAST != g.AST || imported {
|
||||||
refs = getWriteableEdgeRefs(edge, baseAST)
|
refs = GetWriteableEdgeRefs(edge, baseAST)
|
||||||
}
|
}
|
||||||
onlyInChain := true
|
onlyInChain := true
|
||||||
for _, ref := range refs {
|
for _, ref := range refs {
|
||||||
|
|
@ -920,7 +920,7 @@ func Delete(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph,
|
||||||
} else {
|
} else {
|
||||||
refs := e.References
|
refs := e.References
|
||||||
if len(boardPath) > 0 {
|
if len(boardPath) > 0 {
|
||||||
refs := getWriteableEdgeRefs(e, baseAST)
|
refs := GetWriteableEdgeRefs(e, baseAST)
|
||||||
if len(refs) != len(e.References) {
|
if len(refs) != len(e.References) {
|
||||||
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
||||||
}
|
}
|
||||||
|
|
@ -991,7 +991,7 @@ func Delete(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph,
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
if len(boardPath) > 0 {
|
if len(boardPath) > 0 {
|
||||||
writeableRefs := getWriteableRefs(obj, baseAST)
|
writeableRefs := GetWriteableRefs(obj, baseAST)
|
||||||
if len(writeableRefs) != len(obj.References) {
|
if len(writeableRefs) != len(obj.References) {
|
||||||
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
||||||
}
|
}
|
||||||
|
|
@ -1759,7 +1759,7 @@ func move(g *d2graph.Graph, boardPath []string, key, newKey string, includeDesce
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(boardPath) > 0 {
|
if len(boardPath) > 0 {
|
||||||
writeableRefs := getWriteableRefs(obj, baseAST)
|
writeableRefs := GetWriteableRefs(obj, baseAST)
|
||||||
if len(writeableRefs) != len(obj.References) {
|
if len(writeableRefs) != len(obj.References) {
|
||||||
return nil, OutsideScopeError{}
|
return nil, OutsideScopeError{}
|
||||||
}
|
}
|
||||||
|
|
@ -3226,21 +3226,3 @@ func filterReservedPath(path []*d2ast.StringBox) (filtered []*d2ast.StringBox) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWriteableRefs(obj *d2graph.Object, writeableAST *d2ast.Map) (out []d2graph.Reference) {
|
|
||||||
for i, ref := range obj.References {
|
|
||||||
if ref.ScopeAST == writeableAST && ref.Key.Range.Path == writeableAST.Range.Path {
|
|
||||||
out = append(out, obj.References[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getWriteableEdgeRefs(edge *d2graph.Edge, writeableAST *d2ast.Map) (out []d2graph.EdgeReference) {
|
|
||||||
for i, ref := range edge.References {
|
|
||||||
if ref.ScopeAST == writeableAST {
|
|
||||||
out = append(out, edge.References[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -245,3 +245,21 @@ func GetID(key string) string {
|
||||||
|
|
||||||
return d2format.Format(d2ast.RawString(mk.Key.Path[len(mk.Key.Path)-1].Unbox().ScalarString(), true))
|
return d2format.Format(d2ast.RawString(mk.Key.Path[len(mk.Key.Path)-1].Unbox().ScalarString(), true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetWriteableRefs(obj *d2graph.Object, writeableAST *d2ast.Map) (out []d2graph.Reference) {
|
||||||
|
for i, ref := range obj.References {
|
||||||
|
if ref.ScopeAST == writeableAST && ref.Key.Range.Path == writeableAST.Range.Path {
|
||||||
|
out = append(out, obj.References[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWriteableEdgeRefs(edge *d2graph.Edge, writeableAST *d2ast.Map) (out []d2graph.EdgeReference) {
|
||||||
|
for i, ref := range edge.References {
|
||||||
|
if ref.ScopeAST == writeableAST {
|
||||||
|
out = append(out, edge.References[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue