Ejemplo n.º 1
0
        public IAsyncAction RegisterCodeActionProviderAsync(string languageId, CodeActionProvider provider)
        {
            if (_editor.TryGetTarget(out CodeEditor editor))
            {
                // link:registerCodeActionProvider.ts:ProvideCodeActions
                editor._parentAccessor.RegisterEvent("ProvideCodeActions" + languageId, async(args) =>
                {
                    if (args != null && args.Length >= 2)
                    {
                        var range   = JsonConvert.DeserializeObject <Range>(args[0]);
                        var context = JsonConvert.DeserializeObject <CodeActionContext>(args[1]);

                        var list = await provider.ProvideCodeActionsAsync(editor.GetModel(), range, context);

                        if (list != null)
                        {
                            return(JsonConvert.SerializeObject(list));
                        }
                    }

                    return(null);
                });

                // link:registerCodeActionProvider.ts:registerCodeActionProvider
                return(editor.InvokeScriptAsync("registerCodeActionProvider", new object[] { languageId }).AsAsyncAction());
            }

            return(null);
        }
Ejemplo n.º 2
0
 bool CreateCodeActionProvider()
 {
     lock (this) {
         if (codeActionProvider == null)
         {
             codeActionProvider = (CodeActionProvider)Activator.CreateInstance(type);
         }
         return(true);
     }
 }
Ejemplo n.º 3
0
        protected void TestActionDescriptions(CodeActionProvider 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());
        }
Ejemplo n.º 4
0
        protected void TestWrongContext(CodeActionProvider action, string input)
        {
            var context = TestRefactoringContext.Create(input);

            context.FormattingOptions = formattingOptions;
            bool isValid = action.GetActions(context).Any();

            if (isValid)
            {
                Console.WriteLine("valid node is:" + context.GetNode());
            }
            Assert.IsTrue(!isValid, action.GetType() + " shouldn't be valid there.");
        }
Ejemplo n.º 5
0
        public void Test(CodeActionProvider 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);
        }
 public NRefactoryCodeActionProvider(CodeActionProvider provider, ContextActionAttribute attr)
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if (attr == null)
     {
         throw new ArgumentNullException("attr");
     }
     this.provider = provider;
     Title         = GettextCatalog.GetString(attr.Title ?? "");
     Description   = GettextCatalog.GetString(attr.Description ?? "");
     Category      = GettextCatalog.GetString(attr.Category ?? "");
     MimeType      = "text/x-csharp";
 }
Ejemplo n.º 7
0
        // The capabilities that we are registering to provide
        private static InitializeResult GetCapabilities()
        {
            // The commands we can execute require a little bit of special sauce
            var commandList = CodeActionProvider.GetCommands();

            commandList.AddRange(ExecuteCommandProvider.GetCommands());
            commandList.Add(ReloadWorkspaceCommandString);
            commandList.Add(OpenLogFileCommandString);

            return(new InitializeResult
            {
                Capabilities = new ServerCapabilities
                {
                    CodeActionProvider = true,
                    CodeLensProvider = new CodeLensOptions()
                    {
                        ResolveProvider = false,
                    },
                    CompletionProvider = new CompletionOptions
                    {
                        ResolveProvider = true,
                        TriggerCharacters = new[] { "." },
                    },
                    DefinitionProvider = true,
                    DocumentFormattingProvider = true,
                    DocumentSymbolProvider = true,
                    ExecuteCommandProvider = new ExecuteCommandOptions()
                    {
                        Commands = commandList.ToArray(),
                    },
                    HoverProvider = true,
                    RenameProvider = true,
                    ReferencesProvider = true,
                    SignatureHelpProvider = new SignatureHelpOptions()
                    {
                        TriggerCharacters = new[] { "(", "," },
                    },
                    TextDocumentSync = new TextDocumentSyncOptions
                    {
                        Change = TextDocumentSyncKind.Full,
                        OpenClose = true,
                    },
                },
            });
        }
Ejemplo n.º 8
0
        protected string RunContextAction(CodeActionProvider action, string input,
                                          int actionIndex = 0, bool expectErrors = false)
        {
            var context = TestRefactoringContext.Create(input, expectErrors);

            context.FormattingOptions = formattingOptions;
            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);
        }
Ejemplo n.º 9
0
 public static void AddProvider(CodeActionProvider provider)
 {
     contextActions.Add(provider);
 }