async Task Listen() { var token = _cancellationTokenSource.Token; string last = null; while (!token.IsCancellationRequested && !token.WaitHandle.WaitOne(500)) { string clipboard = Clipboard.GetText(); // Get clipboard. if (clipboard == last || clipboard == null) { continue; // Clipboard did not change. } last = clipboard; // Clipboard changed. try { // As workshop actions ConvertTextToElement tte = new ConvertTextToElement(clipboard); Workshop workshop = tte.GetActionList(); if (workshop != null) // Determines if the clipboard is an action list. { DebuggerActionSetResult actionStream = new DebuggerActionSetResult(workshop); // Action list successfully parsed. // Get the DeltinScript. VariableCollection = (await _languageServer.DocumentHandler.OnScriptAvailability())?.DebugVariables; // Error obtaining debug variables. if (VariableCollection == null) { return; } // Apply debugger variables. VariableCollection.Apply(actionStream); // Notify the adapter of the new state. _languageServer.Server.SendNotification("debugger.activated"); } } catch (Exception ex) { _languageServer.DebuggerException(ex); } } }
public void Apply(DebuggerActionSetResult actionStream) { ActionStream = actionStream; // Reset the variables list. Variables = new List <IDebugVariable>(LinkableVariables); // Reset the references. References.Clear(); _currentReference = 0; // Add scope references. References.Add(_variablesScope, GetReference()); References.Add(_rawScope, GetReference()); _rawScope.Variables.Clear(); foreach (LinkableDebugVariable variable in LinkableVariables) { // Reset the obtained variable. variable.ResetStreamVariable(); // Make sure the set matches. if (variable.Variable.IsGlobal == (actionStream.Set == DebuggerActionStreamSet.Global)) { // Get the related variable foreach (var debuggerVariable in actionStream.Variables) { if (debuggerVariable.Name == variable.Variable.Name) { variable.SetStreamVariable(debuggerVariable); break; } } } } // Raw variables foreach (var value in actionStream.Variables) { var variable = new ChildDebugVariable(new DefaultResolver(), value.Value, value.Name, null); Add(variable); _rawScope.Variables.Add(variable); } }