public void Execute(ISolution solution, ITextControl textControl)
        {
            if (!_literalExpression.IsValid())
            {
                return;
            }

            var containingFile = _literalExpression.GetContainingFile();
            var psiModule      = _literalExpression.GetPsiModule();
            var elementFactory = CSharpElementFactory.GetInstance(psiModule);

            IExpression newExpression = null;

            _literalExpression.GetPsiServices().Transactions.Execute(GetType().Name, () =>
            {
                using (solution.GetComponent <IShellLocks>().UsingWriteLock())
                    newExpression = ModificationUtil.ReplaceChild(
                        _literalExpression.Task, elementFactory.CreateExpression("$0.ConfigureAwait($1)", _literalExpression.Task,
                                                                                 elementFactory.CreateExpressionByConstantValue(CSharpConstantValueFactory.CreateBoolValue(_value, psiModule))));
            });

            if (newExpression != null)
            {
                IRangeMarker marker = newExpression.GetDocumentRange().CreateRangeMarker(solution.GetComponent <DocumentManager>());
                containingFile.OptimizeImportsAndRefs(marker, false, true, NullProgressIndicator.Instance);
            }
        }
Beispiel #2
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var literalExpression = _highlighting.Expression;

            if (!literalExpression.IsValid())
            {
                return(null);
            }

            var containingFile = literalExpression.GetContainingFile();
            var psiModule      = literalExpression.GetPsiModule();
            var elementFactory = CSharpElementFactory.GetInstance(literalExpression);

            IExpression newExpression = null;

            literalExpression.GetPsiServices().Transactions.Execute(GetType().Name, () =>
            {
                using (solution.GetComponent <IShellLocks>().UsingWriteLock())
                    newExpression = ModificationUtil.ReplaceChild(
                        literalExpression.Task, elementFactory.CreateExpression("$0.ConfigureAwait($1)", literalExpression.Task,
                                                                                elementFactory.CreateExpressionByConstantValue(CSharpConstantValueFactory.CreateBoolValue(_value, psiModule))));
            });

            if (newExpression != null)
            {
                var marker = newExpression.GetDocumentRange().CreateRangeMarker(solution.GetComponent <DocumentManager>());
                containingFile.OptimizeImportsAndRefs(marker, false, true, NullProgressIndicator.Create());
            }

            return(null);
        }