From 4a81e9910b34c935741b10bb2ba031c1baa121ac Mon Sep 17 00:00:00 2001 From: fwcd Date: Wed, 2 Sep 2020 20:36:05 +0200 Subject: [PATCH] Apply correct labels to graph edges in generic evaluator --- .../GenericEvaluationEngine.ts | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/extension/src/EvaluationWatchService/EvaluationEngine/GenericEvaluationEngine.ts b/extension/src/EvaluationWatchService/EvaluationEngine/GenericEvaluationEngine.ts index 575a198..e5f6e22 100644 --- a/extension/src/EvaluationWatchService/EvaluationEngine/GenericEvaluationEngine.ts +++ b/extension/src/EvaluationWatchService/EvaluationEngine/GenericEvaluationEngine.ts @@ -107,24 +107,29 @@ export class GenericEvaluator implements Evaluator { knownNodeIds: { [ref: number]: string; } = {}, recursionDepth: number = 0, maxRecursionDepth: number = 30, - maxKnownObjects: number = 100, - ): Promise { - var result: GraphNode = { - id: `${variablesReference}`, + maxKnownNodes: number = 100, + ): Promise { + const hasChilds = variablesReference > 0; + const knownCount = Object.keys(knownNodeIds).length + 1; + const canRecurse = recursionDepth < maxRecursionDepth && knownCount < maxKnownNodes; + let result: GraphNode = { + id: hasChilds ? `${variablesReference}` : `__${label}@${knownCount}__`, label, color: isTopLevel ? "lightblue" : undefined, shape: "box", }; knownNodeIds[variablesReference] = result.id; - const canRecurse = recursionDepth < maxRecursionDepth && Object.keys(knownNodeIds).length < maxKnownObjects; - - if (variablesReference > 0 && canRecurse) { + if (hasChilds && canRecurse) { for (const variable of await this.session.getVariables({ variablesReference })) { - // If the object is known, we have a (potentially cyclic) reference - // Otherwise, recurse on the object. - if (!(variable.variablesReference in knownNodeIds)) { - await this.constructGraphFromVariablesReference( + let childId: string; + + if (variable.variablesReference > 0 && variable.variablesReference in knownNodeIds) { + // If the object is known, we have a (potentially cyclic) reference. + childId = knownNodeIds[variable.variablesReference]; + } else { + // Otherwise recurse + childId = await this.constructGraphFromVariablesReference( variable.value, variable.variablesReference, graph, @@ -132,15 +137,16 @@ export class GenericEvaluator implements Evaluator { knownNodeIds, recursionDepth + 1, maxRecursionDepth, - maxKnownObjects + maxKnownNodes ); } - graph.edges.push({ from: result.id, to: knownNodeIds[variable.variablesReference] }); + graph.edges.push({ from: result.id, to: childId, label: variable.name }); } } graph.nodes.push(result); + return result.id; } protected getFinalExpression(args: {