private async void ReplaceButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var cancellationToken = ResetCancellationToken();

                var replaceExpression = TextBoxReplace.Text;
                var searchExpression  = SearchExpression;

                // Create new solution in Background Task
                var solution = await Task.Run(() => Replace(searchExpression, replaceExpression, cancellationToken), cancellationToken);

                // Updating the Visual Studio Workspace shoud be done back on the UI Thread
                var success = RoslynVisxHelpers.GetWorkspace().TryApplyChanges(solution);
                if (!success)
                {
                    AddToListView("Unable to update solution, maybe it was updated during replace action?");
                }
            }
            catch (CompilationErrorException cex)
            {
                DisplayDiagnostics(cex.Diagnostics);
            }
            catch (Exception ex)
            {
                AddToListView(ex);
            }
        }
        private static async Task <Solution> Replace(string findExpression, string replaceExpression, CancellationToken cancellationToken)
        {
            var scriptResult = await ScriptRunner.RunScriptAsync(findExpression, new ScriptGlobals(cancellationToken), cancellationToken);

            var nodesAndTokens  = RoslynHelpers.GetSyntaxNodesAndTokens(MakeEnumerable(scriptResult));
            var currentSolution = RoslynVisxHelpers.GetWorkspace().CurrentSolution;

            return(await currentSolution.ReplaceNodesWithLiteralAsync(nodesAndTokens, replaceExpression, cancellationToken));
        }
 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
 {
     RoslynVisxHelpers.SelectSpanInCodeWindow(_lineSpan);
     e.Handled = true;
     base.OnMouseDoubleClick(e);
 }