Enhance debug visualization for linked list with custom node table view

This commit is contained in:
mynameisdeleted
2026-07-09 09:17:12 -04:00
parent 5f5599009c
commit 273d4dbf2b
3 changed files with 348 additions and 6 deletions

View File

@@ -50,20 +50,25 @@ public:
return head_ ? &head_->data : nullptr;
}
// Build a JSON string describing the list as a graph, for the VS Code
// "Debug Visualizer" extension: watch `list.toDebugGraph()` while paused.
// Schema: https://hediet.github.io/visualization/docs/visualization-data-schema.json
// Build a JSON string describing the list for the VS Code "Debug
// Visualizer" extension's custom "node table" view (see
// vis-plugins/node-table-visualizer.js): watch `list.toDebugGraph()`
// while paused. Each node is rendered as its own address-labeled box
// with a field table -- data as a plain value, next as a hex pointer.
std::string toDebugGraph() const {
std::ostringstream json;
json << "{\"kind\":{\"graph\":true},\"nodes\":[";
json << "{\"kind\":{\"nodeTable\":true},\"nodes\":[";
for (Node<T>* n = head_; n; n = n->next) {
if (n != head_) json << ",";
json << "{\"id\":\"" << n << "\",\"label\":\"" << n->data << "\"}";
json << "{\"id\":\"" << n << "\",\"fields\":["
<< "{\"name\":\"data\",\"value\":\"" << n->data << "\"},"
<< "{\"name\":\"next\",\"value\":\"" << n->next << "\",\"isPointer\":true}"
<< "]}";
}
json << "],\"edges\":[";
for (Node<T>* n = head_; n && n->next; n = n->next) {
if (n != head_) json << ",";
json << "{\"from\":\"" << n << "\",\"to\":\"" << n->next << "\"}";
json << "{\"from\":\"" << n << "\",\"to\":\"" << n->next << "\",\"label\":\"next\"}";
}
json << "]}";
return json.str();