示例#1
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.");
        }
示例#2
0
        protected void TestActionDescriptions(ICodeActionProvider provider, string input, params string[] expected)
        {
            var ctx = TestRefactoringContext.Create(input);

            ctx.FormattingOptions = formattingOptions;
            var actions = provider.GetActions(ctx).ToList();

            Assert.AreEqual(
                expected,
                actions.Select(a => a.Description).ToArray());
        }
		public NRefactoryCodeActionProvider (ICodeActionProvider provider, ContextActionAttribute attr)
		{
			if (provider == null)
				throw new System.ArgumentNullException ("provider");
			if (attr == null)
				throw new System.ArgumentNullException ("attr");
			this.provider = provider;
			Title = GettextCatalog.GetString (attr.Title ?? "");
			Description = GettextCatalog.GetString (attr.Description ?? "");
			Category = GettextCatalog.GetString (attr.Category ?? "");
			MimeType = "text/x-csharp";
		}
示例#4
0
        public void Test(ICodeActionProvider provider, string input, string output, int action = 0, bool expectErrors = false)
        {
            string result = RunContextAction(provider, HomogenizeEol(input), action, expectErrors);
            bool   passed = result == output;

            if (!passed)
            {
                Console.WriteLine("-----------Expected:");
                Console.WriteLine(output);
                Console.WriteLine("-----------Got:");
                Console.WriteLine(result);
            }
            Assert.AreEqual(HomogenizeEol(output), result);
        }
示例#5
0
 public NRefactoryCodeActionProvider(ICodeActionProvider provider, ContextActionAttribute attr)
 {
     if (provider == null)
     {
         throw new System.ArgumentNullException("provider");
     }
     if (attr == null)
     {
         throw new System.ArgumentNullException("attr");
     }
     this.provider = provider;
     Title         = GettextCatalog.GetString(attr.Title ?? "");
     Description   = GettextCatalog.GetString(attr.Description ?? "");
     Category      = GettextCatalog.GetString(attr.Category ?? "");
     MimeType      = "text/x-csharp";
 }
        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);
        }
示例#7
0
        private async Task <IEnumerable <CodeActionOperation> > GetUsingActions(ICodeActionProvider codeActionProvider,
                                                                                ImmutableArray <Diagnostic> pointDiagnostics, string actionPrefix)
        {
            var actions   = new List <CodeAction>();
            var context   = new CodeFixContext(_document, pointDiagnostics.First().Location.SourceSpan, pointDiagnostics, (a, d) => actions.Add(a), CancellationToken.None);
            var providers = codeActionProvider.CodeFixes;

            //Disable await warning since we dont need the result of the call. Else we need to use a throwaway variable.
#pragma warning disable 4014
            foreach (var provider in providers)
            {
                provider.RegisterCodeFixesAsync(context);
            }
#pragma warning restore 4014

            var tasks = actions.Where(a => a.Title.StartsWith(actionPrefix))
                        .Select(async a => await a.GetOperationsAsync(CancellationToken.None)).ToList();

            return((await Task.WhenAll(tasks)).SelectMany(x => x));
        }
示例#8
0
        private async Task<IEnumerable<CodeActionOperation>> GetUsingActions(ICodeActionProvider codeActionProvider,
                ImmutableArray<Diagnostic> pointDiagnostics, string actionPrefix)
        {
            var actions = new List<CodeAction>();
            var context = new CodeFixContext(_document, pointDiagnostics.First().Location.SourceSpan, pointDiagnostics, (a, d) => actions.Add(a), CancellationToken.None);
            var providers = codeActionProvider.CodeFixes;

            //Disable await warning since we dont need the result of the call. Else we need to use a throwaway variable.
#pragma warning disable 4014
            foreach (var provider in providers)
            {
                provider.RegisterCodeFixesAsync(context);
            }
#pragma warning restore 4014

            var tasks = actions.Where(a => a.Title.StartsWith(actionPrefix))
                    .Select(async a => await a.GetOperationsAsync(CancellationToken.None)).ToList();

            return (await Task.WhenAll(tasks)).SelectMany(x => x);
        }