예제 #1
0
        public void Register(IRefactoring refactoring)
        {
            Contract.Requires(refactoring != null);

            var context = this;

            try {
                CancellationTokenExtensions.SetCancellationToken(context._originalContext.CancellationToken);

                var newRoot  = refactoring.ComputeRoot(context.Root);
                var document = context.Document.WithSyntaxRoot(newRoot);

                if (ProducedEquivalent(context.Root, newRoot))
                {
                    document = context.Document;
                }

                var codeAction = CodeAction.Create(refactoring.Description, async c => document);
                _originalContext.RegisterRefactoring(codeAction);
            }
            catch (OperationCanceledException) {
                throw;
            }
            catch (Exception) {
                if (Settings.Instance.CanThrow)
                {
                    throw;
                }
                // TODO: add logging
            }
        }
예제 #2
0
        public void RegisterAsync(IRefactoring refactoring)
        {
            Contract.Requires(refactoring != null);

            Register(GetCodeAction(
                         title: refactoring.Description,
                         getRoot: (root, c) => Task.Run(() => refactoring.ComputeRoot(root), c),
                         context: this));
        }