From 14ff4f03e132ab110fa14842ee1167a1f2f74722 Mon Sep 17 00:00:00 2001 From: pinzart Date: Thu, 4 Aug 2022 11:29:41 -0400 Subject: [PATCH] fix edge case of ShowExecutionPreview --- .../ViewModels/Core/ConnectorViewModel.cs | 2 +- src/Engine/ProtoScript/Runners/LiveRunner.cs | 47 ++++++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs index de81aebf28f..6888f707cca 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs @@ -504,7 +504,7 @@ public PreviewState PreviewState return PreviewState.None; } - if (Nodevm.ShowExecutionPreview) + if (Nodevm.ShowExecutionPreview || NodeEnd.ShowExecutionPreview) { return PreviewState.ExecutionPreview; } diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index cf5f5b8d8e7..6bf0245da7a 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -478,17 +478,20 @@ public ChangeSetComputer Clone() { comp.currentSubTreeList.Add(subTreePairs.Key, subTreePairs.Value); } - - comp.csData = new ChangeSetData(); - comp.csData.ContainsDeltaAST = csData.ContainsDeltaAST; - comp.csData.DeletedBinaryExprASTNodes = new List(csData.DeletedBinaryExprASTNodes); - comp.csData.DeletedFunctionDefASTNodes = new List(csData.DeletedFunctionDefASTNodes); - comp.csData.RemovedBinaryNodesFromModification = new List(csData.RemovedBinaryNodesFromModification); - comp.csData.ModifiedNodesForRuntimeSetValue = new List(csData.ModifiedNodesForRuntimeSetValue); - comp.csData.RemovedFunctionDefNodesFromModification = new List(csData.RemovedFunctionDefNodesFromModification); - comp.csData.ForceExecuteASTList = new List(csData.ForceExecuteASTList); - comp.csData.ModifiedFunctions = new List(csData.ModifiedFunctions); - comp.csData.ModifiedNestedLangBlock = new List(csData.ModifiedNestedLangBlock); + + if (csData != null) + { + comp.csData = new ChangeSetData(); + comp.csData.ContainsDeltaAST = csData.ContainsDeltaAST; + comp.csData.DeletedBinaryExprASTNodes = new List(csData.DeletedBinaryExprASTNodes); + comp.csData.DeletedFunctionDefASTNodes = new List(csData.DeletedFunctionDefASTNodes); + comp.csData.RemovedBinaryNodesFromModification = new List(csData.RemovedBinaryNodesFromModification); + comp.csData.ModifiedNodesForRuntimeSetValue = new List(csData.ModifiedNodesForRuntimeSetValue); + comp.csData.RemovedFunctionDefNodesFromModification = new List(csData.RemovedFunctionDefNodesFromModification); + comp.csData.ForceExecuteASTList = new List(csData.ForceExecuteASTList); + comp.csData.ModifiedFunctions = new List(csData.ModifiedFunctions); + comp.csData.ModifiedNestedLangBlock = new List(csData.ModifiedNestedLangBlock); + } return comp; } @@ -601,7 +604,7 @@ private IEnumerable GetDeltaAstListDeleted(IEnumerable return deltaAstList; } - private IEnumerable GetDeltaAstListAdded(IEnumerable addedSubTrees) + internal IEnumerable GetDeltaAstListAdded(IEnumerable addedSubTrees) { var deltaAstList = new List(); if (addedSubTrees != null) @@ -787,7 +790,6 @@ private void UpdateCachedASTList(Subtree st, List modifiedASTLi } } - private IEnumerable GetDeltaAstListModified(List modifiedSubTrees) { var deltaAstList = new List(); @@ -1660,11 +1662,30 @@ private void CompileAndExecuteForDeltaExecution(List astList) private List PreviewInternal(GraphSyncData syncData) { var previewChangeSetComputer = changeSetComputer.Clone(); + // Get the list of ASTs that will be affected by syncData var previewAstList = previewChangeSetComputer.GetDeltaASTList(syncData); // Get the list of guid's affected by the astlist List cbnGuidList = previewChangeSetComputer.EstimateNodesAffectedByASTList(previewAstList); + + var finalDeltaAstList = new List(); + + // Newly added nodes will not be in the VM yet. + // So we need to add them to the preview list. + var addCSComputer = changeSetComputer.Clone(); + + var addedDeltaAsts = addCSComputer.GetDeltaAstListAdded(syncData.AddedSubtrees); + foreach (AssociativeNode ast in addedDeltaAsts) + { + if (ast is BinaryExpressionNode bnode) + { + if (!cbnGuidList.Contains(bnode.guid)) + { + cbnGuidList.Add(bnode.guid); + } + } + } return cbnGuidList; }