Exemplo n.º 1
0
        public static RazorCodeAction WrapResolvableCSharpCodeAction(
            this RazorCodeAction razorCodeAction,
            RazorCodeActionContext context,
            string action = LanguageServerConstants.CodeActions.Default)
        {
            if (razorCodeAction is null)
            {
                throw new ArgumentNullException(nameof(razorCodeAction));
            }

            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var csharpParams = new CSharpCodeActionParams()
            {
                Data         = razorCodeAction.Data,
                RazorFileUri = context.Request.TextDocument.Uri
            };

            razorCodeAction.Data = new RazorCodeActionResolutionParams()
            {
                Action   = action,
                Language = LanguageServerConstants.CodeActions.Languages.CSharp,
                Data     = csharpParams
            };

            return(razorCodeAction);
        }
Exemplo n.º 2
0
        public static CommandOrCodeAction AsVSCodeCommandOrCodeAction(this RazorCodeAction razorCodeAction)
        {
            if (razorCodeAction.Data is null)
            {
                // Only code action edit, we must convert this to a resolvable command

                var resolutionParams = new RazorCodeActionResolutionParams
                {
                    Action   = LanguageServerConstants.CodeActions.EditBasedCodeActionCommand,
                    Language = LanguageServerConstants.CodeActions.Languages.Razor,
                    Data     = razorCodeAction.Edit ?? new WorkspaceEdit()
                };

                razorCodeAction = new RazorCodeAction()
                {
                    Title = razorCodeAction.Title,
                    Data  = JToken.FromObject(resolutionParams)
                };
            }

            var serializedParams = JToken.FromObject(razorCodeAction.Data);
            var arguments        = new JArray(serializedParams);

            return(new CommandOrCodeAction(new Command
            {
                Title = razorCodeAction.Title ?? string.Empty,
                Name = LanguageServerConstants.RazorCodeActionRunnerCommand,
                Arguments = arguments
            }));
        }
Exemplo n.º 3
0
        public static CommandOrCodeAction AsVSCodeCommandOrCodeAction(this RazorCodeAction razorCodeAction)
        {
            if (razorCodeAction.Data is null)
            {
                // No command data
                return(new CommandOrCodeAction(razorCodeAction));
            }

            var serializedParams = JToken.FromObject(razorCodeAction.Data);
            var arguments        = new JArray(serializedParams);

            return(new CommandOrCodeAction(new Command
            {
                Title = razorCodeAction.Title ?? string.Empty,
                Name = LanguageServerConstants.RazorCodeActionRunnerCommand,
                Arguments = arguments
            }));
        }
        public static RazorCodeAction WrapResolvableCSharpCodeAction(
            this RazorCodeAction razorCodeAction,
            RazorCodeActionContext context,
            string action = LanguageServerConstants.CodeActions.Default)
        {
            if (razorCodeAction is null)
            {
                throw new ArgumentNullException(nameof(razorCodeAction));
            }

            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var csharpParams = new CSharpCodeActionParams()
            {
                Data         = razorCodeAction.Data,
                RazorFileUri = context.Request.TextDocument.Uri
            };

            var resolutionParams = new RazorCodeActionResolutionParams()
            {
                Action   = action,
                Language = LanguageServerConstants.CodeActions.Languages.CSharp,
                Data     = csharpParams
            };

            razorCodeAction = razorCodeAction with {
                Data = JToken.FromObject(resolutionParams)
            };

            if (razorCodeAction.Children != null)
            {
                for (var i = 0; i < razorCodeAction.Children.Length; i++)
                {
                    razorCodeAction.Children[i] = razorCodeAction.Children[i].WrapResolvableCSharpCodeAction(context, action);
                }
            }

            return(razorCodeAction);
        }
    }