Skip to content

Commit

Permalink
Merge pull request #2271 from alixander/set-layer-ast
Browse files Browse the repository at this point in the history
set the ast range path
  • Loading branch information
alixander authored Jan 8, 2025
2 parents c50fab7 + af781f5 commit 13af63a
Show file tree
Hide file tree
Showing 88 changed files with 517 additions and 155 deletions.
19 changes: 19 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3515,6 +3515,25 @@ svc_1."think about A"
svc_1.t2 -> b: do with B
`,
},
{
name: "layer-import-nested-layer",
text: `layers: {
ok: {...@meow}
}
`,
files: map[string]string{
"meow.d2": `layers: {
1: {
asdf
}
}
`,
},
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "d2/testdata/d2compiler/TestCompile/layer-import-nested-layer.d2", g.Layers[0].AST.Range.Path)
tassert.Equal(t, "d2/testdata/d2compiler/TestCompile/meow.d2", g.Layers[0].Layers[0].AST.Range.Path)
},
},
}

for _, tc := range testCases {
Expand Down
6 changes: 6 additions & 0 deletions d2ir/d2ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,12 @@ func (m *Map) AST() d2ast.Node {
astMap := &d2ast.Map{
Range: d2ast.MakeRange(",0:0:0-1:0:0"),
}
if m.parent != nil && NodeBoardKind(m) != "" {
f, ok := m.parent.(*Field)
if ok {
astMap.Range.Path = f.Name.GetRange().Path
}
}
for _, f := range m.Fields {
astMap.Nodes = append(astMap.Nodes, d2ast.MakeMapNodeBox(f.AST().(d2ast.MapNode)))
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions testdata/d2compiler/TestCompile/import-link-layer-1.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions testdata/d2compiler/TestCompile/import-link-layer-3.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions testdata/d2compiler/TestCompile/import-link-layer-4.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 13af63a

Please sign in to comment.