fix again

This commit is contained in:
Alexander Wang 2023-05-08 18:45:36 -07:00
parent b4d6551ec5
commit 0124b68780
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 483 additions and 6 deletions

View file

@ -1697,16 +1697,12 @@ func move(g *d2graph.Graph, key, newKey string, includeDescendants bool) (*d2gra
}
if len(go2.Filter(ref.Key.Path, func(x *d2ast.StringBox) bool { return x.Unbox().ScalarString() != "_" })) > 1 {
detachedK := cloneKey(ref.Key)
if includeDescendants {
detachedK.Path = detachedK.Path[:len(detachedK.Path)-len(newPath)]
} else {
detachedK.Path = detachedK.Path[:len(detachedK.Path)-1]
}
detachedK.Path = detachedK.Path[:len(detachedK.Path)-1]
ensureNode(g, refEdges, ref.ScopeObj, ref.Scope, ref.MapKey, detachedK, false)
}
if includeDescendants {
ref.Key.Path = append(ref.Key.Path[:go2.Max(0, ref.KeyPathIndex-1)], append(newPath, ref.Key.Path[go2.Min(len(ref.Key.Path), ref.KeyPathIndex+len(newPath)):]...)...)
ref.Key.Path = append(ref.Key.Path[:go2.Max(0, ref.KeyPathIndex-len(newPath))], append(newPath, ref.Key.Path[go2.Min(len(ref.Key.Path), ref.KeyPathIndex+len(newPath)):]...)...)
} else {
ref.Key.Path = newPath
}

View file

@ -4114,6 +4114,18 @@ z
exp: `x -> z.y
z
`,
},
{
name: "include_descendants_edge_ref_7",
text: `d.t -> d.np.s
`,
key: `d.np.s`,
newKey: `d.s`,
includeDescendants: true,
exp: `d.t -> d.s
d.np
`,
},
{

View file

@ -0,0 +1,469 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-2:0:16",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:10:10",
"edges": [
{
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:10:10",
"src": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:3:3",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:1:1",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:2:2-0:3:3",
"value": [
{
"string": "t",
"raw_string": "t"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:7:7-0:10:10",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:7:7-0:8:8",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:9:9-0:10:10",
"value": [
{
"string": "s",
"raw_string": "s"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:0:11-1:4:15",
"key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:0:11-1:4:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:0:11-1:1:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:2:13-1:4:15",
"value": [
{
"string": "np",
"raw_string": "np"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"attributes": {
"label": {
"value": ""
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"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": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"objects": [
{
"id": "d",
"id_val": "d",
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:3:3",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:1:1",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:2:2-0:3:3",
"value": [
{
"string": "t",
"raw_string": "t"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:7:7-0:10:10",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:7:7-0:8:8",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:9:9-0:10:10",
"value": [
{
"string": "s",
"raw_string": "s"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:0:11-1:4:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:0:11-1:1:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:2:13-1:4:15",
"value": [
{
"string": "np",
"raw_string": "np"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "d"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "t",
"id_val": "t",
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:3:3",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:0:0-0:1:1",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:2:2-0:3:3",
"value": [
{
"string": "t",
"raw_string": "t"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "t"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "s",
"id_val": "s",
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:7:7-0:10:10",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:7:7-0:8:8",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,0:9:9-0:10:10",
"value": [
{
"string": "s",
"raw_string": "s"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "s"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "np",
"id_val": "np",
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:0:11-1:4:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:0:11-1:1:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_7.d2,1:2:13-1:4:15",
"value": [
{
"string": "np",
"raw_string": "np"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "np"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}