MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / FormatLayerGraph

Function FormatLayerGraph

internal/layergraph/format.go:128–172  ·  view source on GitHub ↗

FormatLayerGraph renders the full layer graph as a Mermaid flowchart TD with entity-encoded labels. Intentional divergence from .repos reference: this output format includes cross-file location annotations (e.g., "_in simple.ts at ln 6 col 19_") on nodes originating from a different source file. The

(
	c *checker.Checker,
	layerGraph *graph.Graph[LayerGraphNodeInfo, LayerGraphEdgeInfo],
	sf *ast.SourceFile,
)

Source from the content-addressed store, hash-verified

126// including them in nested, outline, and quickinfo formats. The Go version adds them here as an
127// enhancement to help users locate cross-file nodes in the flat graph.
128func FormatLayerGraph(
129 c *checker.Checker,
130 layerGraph *graph.Graph[LayerGraphNodeInfo, LayerGraphEdgeInfo],
131 sf *ast.SourceFile,
132) string {
133 var lines []string
134 lines = append(lines, "flowchart TD")
135
136 // Nodes in index order.
137 for idx, nodeInfo := range layerGraph.Nodes() {
138 nodeSourceFile := getNodeSourceFile(nodeInfo.Node)
139 text := getNodeText(nodeInfo.Node, nodeSourceFile)
140
141 var provides []string
142 for _, t := range nodeInfo.Provides {
143 provides = append(provides, getTypeDisplayName(c, t))
144 }
145 var requires []string
146 for _, t := range nodeInfo.Requires {
147 requires = append(requires, getTypeDisplayName(c, t))
148 }
149
150 label := text + "\nprovides: " + strings.Join(provides, ", ") + "\nrequires: " + strings.Join(requires, ", ")
151 if nodeSourceFile != nil && nodeSourceFile != sf {
152 label += "\n_" + formatLocation(nodeInfo.Node, sf) + "_"
153 }
154 label = mermaidEntityEncode(label)
155 label = strings.ReplaceAll(label, "\n", "<br/>")
156 label = mermaidEscapeOutputLabel(label)
157 lines = append(lines, fmt.Sprintf(" %d[\"%s\"]", idx, label))
158 }
159
160 // Edges in index order.
161 for _, edge := range layerGraph.Edges() {
162 jsonBytes, err := json.Marshal(edge.Data)
163 if err != nil {
164 continue
165 }
166 edgeLabel := mermaidEntityEncode(string(jsonBytes))
167 edgeLabel = mermaidEscapeOutputLabel(edgeLabel)
168 lines = append(lines, fmt.Sprintf(" %d -->|\"%s\"| %d", edge.Source, edgeLabel, edge.Target))
169 }
170
171 return strings.Join(lines, "\n")
172}
173
174// FormatNestedLayerGraph renders the layer graph as a Mermaid flowchart TB with nested subgraphs.
175func FormatNestedLayerGraph(

Callers 1

Calls 8

getNodeSourceFileFunction · 0.85
getNodeTextFunction · 0.85
getTypeDisplayNameFunction · 0.85
formatLocationFunction · 0.85
mermaidEntityEncodeFunction · 0.85
mermaidEscapeOutputLabelFunction · 0.85
NodesMethod · 0.80
EdgesMethod · 0.80

Tested by

no test coverage detected