d2oracle: fix setting with comments
This commit is contained in:
parent
3caa110592
commit
bd7f9e1c39
3 changed files with 284 additions and 3 deletions
|
|
@ -562,7 +562,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
|
||||||
foundMap = true
|
foundMap = true
|
||||||
scope = ref.MapKey.Value.Map
|
scope = ref.MapKey.Value.Map
|
||||||
for _, n := range scope.Nodes {
|
for _, n := range scope.Nodes {
|
||||||
if n.MapKey.Value.Map == nil {
|
if n.MapKey == nil || n.MapKey.Value.Map == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if n.MapKey.Key == nil || len(n.MapKey.Key.Path) != 1 {
|
if n.MapKey.Key == nil || len(n.MapKey.Key.Path) != 1 {
|
||||||
|
|
@ -1059,7 +1059,7 @@ func bumpChildrenUnderscores(m *d2ast.Map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func hoistRefChildren(g *d2graph.Graph, key *d2ast.KeyPath, ref d2graph.Reference) {
|
func hoistRefChildren(g *d2graph.Graph, key *d2ast.KeyPath, ref d2graph.Reference) {
|
||||||
if ref.MapKey.Value.Map == nil {
|
if ref.MapKey == nil || ref.MapKey.Value.Map == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1115,7 +1115,7 @@ func renameConflictsToParent(g *d2graph.Graph, key *d2ast.KeyPath) (*d2graph.Gra
|
||||||
var absKeys []*d2ast.KeyPath
|
var absKeys []*d2ast.KeyPath
|
||||||
|
|
||||||
if len(ref.Key.Path)-1 == ref.KeyPathIndex {
|
if len(ref.Key.Path)-1 == ref.KeyPathIndex {
|
||||||
if ref.MapKey.Value.Map == nil {
|
if ref.MapKey == nil || ref.MapKey.Value.Map == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var mapKeys []*d2ast.KeyPath
|
var mapKeys []*d2ast.KeyPath
|
||||||
|
|
|
||||||
|
|
@ -2502,6 +2502,22 @@ x -> a.b -> a.b.c
|
||||||
x -> a.b -> a.b.c
|
x -> a.b -> a.b.c
|
||||||
(a.b -> a.b.c)[0].style.stroke: green
|
(a.b -> a.b.c)[0].style.stroke: green
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "edge-comment",
|
||||||
|
|
||||||
|
text: `x -> y: {
|
||||||
|
# hi
|
||||||
|
style.stroke: blue
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
key: `(x -> y)[0].style.stroke`,
|
||||||
|
value: go2.Pointer(`green`),
|
||||||
|
exp: `x -> y: {
|
||||||
|
# hi
|
||||||
|
style.stroke: green
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
265
testdata/d2oracle/TestSet/edge-comment.exp.json
generated
vendored
Normal file
265
testdata/d2oracle/TestSet/edge-comment.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,265 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:0:0-4:0:41",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:0:0-3:1:40",
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:0:0-0:6:6",
|
||||||
|
"src": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"src_arrow": "",
|
||||||
|
"dst": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:5:5-0:6:6",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:5:5-0:6:6",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "y",
|
||||||
|
"raw_string": "y"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"dst_arrow": ">"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:8:8-3:1:40",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"comment": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,1:2:12-1:6:16",
|
||||||
|
"value": "hi"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,2:2:19-2:21:38",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,2:2:19-2:14:31",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,2:2:19-2:7:24",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "style",
|
||||||
|
"raw_string": "style"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,2:8:25-2:14:31",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "stroke",
|
||||||
|
"raw_string": "stroke"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,2:16:33-2:21:38",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "green",
|
||||||
|
"raw_string": "green"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"id": "",
|
||||||
|
"id_val": "",
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
},
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"isCurve": false,
|
||||||
|
"src_arrow": false,
|
||||||
|
"dst_arrow": true,
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"map_key_edge_index": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {
|
||||||
|
"stroke": {
|
||||||
|
"value": "green"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"id": "x",
|
||||||
|
"id_val": "x",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "x"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "y",
|
||||||
|
"id_val": "y",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:5:5-0:6:6",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestSet/edge-comment.d2,0:5:5-0:6:6",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "y",
|
||||||
|
"raw_string": "y"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "y"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": "<nil>"
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue