Example #1
0
        public override IEnumerable <MonoDevelop.CodeActions.CodeAction> GetActions(MonoDevelop.Ide.Gui.Document document, TextLocation loc, CancellationToken cancellationToken)
        {
            var context = new MDRefactoringContext(document, loc);

            if (context.IsInvalid || context.RootNode == null)
            {
                yield break;
            }
            var actions = provider.GetActions(context);

            if (actions == null)
            {
                LoggingService.LogWarning(provider + " returned null actions.");
                yield break;
            }
            int num = 0;

            foreach (var action_ in actions)
            {
                var action = action_;
                if (actionId.Count <= num)
                {
                    actionId.Add(provider.GetType().FullName + "'" + num);
                }
                yield return(new NRefactoryCodeAction(actionId[num], GettextCatalog.GetString(action.Description ?? ""), action));

                num++;
            }
        }
Example #2
0
        protected static void TestWrongContext(ICodeActionProvider action, string input)
        {
            var  context = TestRefactoringContext.Create(input);
            bool isValid = action.GetActions(context).Any();

            if (!isValid)
            {
                Console.WriteLine("invalid node is:" + context.GetNode());
            }
            Assert.IsTrue(!isValid, action.GetType() + " shouldn't be valid there.");
        }
        protected static string RunContextAction(ICodeActionProvider action, string input, int actionIndex = 0)
        {
            var  context = TestRefactoringContext.Create(input);
            bool isValid = action.GetActions(context).Any();

            if (!isValid)
            {
                Console.WriteLine("invalid node is:" + context.GetNode());
            }
            Assert.IsTrue(isValid, action.GetType() + " is invalid.");
            using (var script = context.StartScript()) {
                action.GetActions(context).Skip(actionIndex).First().Run(script);
            }

            return(context.doc.Text);
        }