protected virtual void OnDebugServiceUpdateSync(object sender, SledDebugServiceBreakpointEventArgs e)
        {
            if (Collection.Count <= 0)
            {
                return;
            }

            // See if any variables need to be looked up
            foreach (var state in Collection[0].ExpandedStates)
            {
                foreach (var node in state.GetFlattenedHierarchy())
                {
                    if (node.LookUp == null)
                    {
                        continue;
                    }

                    // Already looking up this item
                    if (ListNameInsert.Contains(node.Variable.Name))
                    {
                        continue;
                    }

                    // Keep track of items getting looked up
                    ListNameInsert.Add(node.Variable.Name);
                    ListNameInsertDict.Add(node.Variable.Name, new Pair <string, IList <SledLuaVarNameTypePairType> >(node.Variable.DisplayName, node.Variable.TargetHierarchy));

                    //SledOutDevice.OutLine(SledMessageType.Error, "[Variable Lookup] {0}", node.LookUp);

                    DebugService.SendScmp(new Scmp.LuaVarLookUp(LuaLanguagePlugin.LanguageId, node.LookUp));
                }
            }
        }
        protected virtual void OnDebugServiceDisconnected(object sender, SledDebugServiceEventArgs e)
        {
            // Clear GUI
            Editor.View = null;

            CleanupCollection();

            LookingUp = false;
            ListInsert.Clear();
            ListNameInsert.Clear();
            ListNameInsertDict.Clear();
        }
        protected virtual void OnDebugServiceUpdateBegin(object sender, SledDebugServiceBreakpointEventArgs e)
        {
            if (Collection.Count > 0)
            {
                Collection[0].ValidationBeginning();
            }

            // Save while items still in collection & on GUI
            if (Collection.Count > 0)
            {
                Collection[0].SaveExpandedStates();
            }

            Editor.SaveState();

            // Clear GUI
            Editor.View = null;

            // Clear out all items
            for (var i = 0; i < Collection.Count; i++)
            {
                Collection[i].Variables.Clear();

                if (i > 0)
                {
                    Collection[i].ResetExpandedStates();
                }
            }

            if (Collection.Count > 0)
            {
                Editor.View = Collection[0];
            }

            // Reset
            ListInsert.Clear();
            ListNameInsert.Clear();
            ListNameInsertDict.Clear();
        }
        protected virtual void OnDebugServiceLookupBegin()
        {
            LookingUp = true;

            // If not during an update it's a
            // manual lookup and we are good to go
            if (!DebugService.IsUpdateInProgress)
            {
                return;
            }

            // Uh-oh
            if (ListNameInsert.Count <= 0)
            {
                return;
            }

            // Find where to place the incoming variable
            try
            {
                var pieces = new List <string>();
                {
                    Pair <string, IList <SledLuaVarNameTypePairType> > temp;
                    if (!ListNameInsertDict.TryGetValue(ListNameInsert[0], out temp))
                    {
                        throw new InvalidOperationException("Unknown variable");
                    }

                    pieces.AddRange(temp.Second.Select(kv => kv.Name)); // to navigate to the right table
                    pieces.Add(temp.First);                             // actual variable name
                }

                TType insert = null;

                // Try and find where the variable should be inserted
                for (var i = 0; i < pieces.Count; i++)
                {
                    IList <TType> lstVariables;

                    if (i == 0)
                    {
                        lstVariables = Collection[0].Variables;
                    }
                    else
                    {
                        if (insert == null)
                        {
                            throw new InvalidOperationException("Variable not found");
                        }

                        lstVariables =
                            new List <TType>(
                                insert.Variables.Select(v => v.As <TType>()));
                    }

                    var iPos = -1;

                    for (var j = 0; j < lstVariables.Count; j++)
                    {
                        if (string.Compare(lstVariables[j].DisplayName, pieces[i], StringComparison.Ordinal) != 0)
                        {
                            continue;
                        }

                        iPos = j;
                        break;
                    }

                    if (iPos == -1)
                    {
                        throw new InvalidOperationException("Variable not found");
                    }

                    insert = lstVariables[iPos];
                }

                if (insert == null)
                {
                    throw new InvalidOperationException("Variable not found");
                }

                // Finally found where to place lookups
                ListInsert.Add(insert);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(SledMessageType.Error, "{0}: Exception in OnDebugServiceLookupBegin: {1}", this, ex.Message);
            }
            finally
            {
                // Remove the item we just used
                if (ListNameInsert.Count > 0)
                {
                    ListNameInsertDict.Remove(ListNameInsert[0]);
                    ListNameInsert.RemoveAt(0);
                }
            }
        }