Exemplo n.º 1
0
 public override Task <IReadOnlyList <CodeAction> > ProvideAsync(RazorCodeActionContext context, IEnumerable <CodeAction> codeActions, CancellationToken cancellationToken)
 {
     return(Task.FromResult(new List <CodeAction>()
     {
         new CodeAction()
     } as IReadOnlyList <CodeAction>));
 }
Exemplo n.º 2
0
        private static RazorCodeActionContext CreateRazorCodeActionContext(RazorCodeActionParams request, SourceLocation location, string filePath, string text, SourceSpan componentSourceSpan, bool supportsFileCreation = true)
        {
            var shortComponent = TagHelperDescriptorBuilder.Create(ComponentMetadata.Component.TagHelperKind, "Fully.Qualified.Component", "TestAssembly");

            shortComponent.TagMatchingRule(rule => rule.TagName = "Component");
            var fullyQualifiedComponent = TagHelperDescriptorBuilder.Create(ComponentMetadata.Component.TagHelperKind, "Fully.Qualified.Component", "TestAssembly");

            fullyQualifiedComponent.TagMatchingRule(rule => rule.TagName = "Fully.Qualified.Component");

            var tagHelpers = new[] { shortComponent.Build(), fullyQualifiedComponent.Build() };

            var sourceDocument = TestRazorSourceDocument.Create(text, filePath: filePath, relativePath: filePath);
            var projectEngine  = RazorProjectEngine.Create(builder => {
                builder.AddTagHelpers(tagHelpers);
            });
            var codeDocument = projectEngine.ProcessDesignTime(sourceDocument, FileKinds.Component, Array.Empty <RazorSourceDocument>(), tagHelpers);

            var cSharpDocument               = codeDocument.GetCSharpDocument();
            var diagnosticDescriptor         = new RazorDiagnosticDescriptor("RZ10012", () => "", RazorDiagnosticSeverity.Error);
            var diagnostic                   = RazorDiagnostic.Create(diagnosticDescriptor, componentSourceSpan);
            var cSharpDocumentWithDiagnostic = RazorCSharpDocument.Create(cSharpDocument.GeneratedCode, cSharpDocument.Options, new[] { diagnostic });

            codeDocument.SetCSharpDocument(cSharpDocumentWithDiagnostic);

            var documentSnapshot = Mock.Of <DocumentSnapshot>(document =>
                                                              document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
                                                              document.GetTextAsync() == Task.FromResult(codeDocument.GetSourceText()) &&
                                                              document.Project.TagHelpers == tagHelpers);

            var sourceText = SourceText.From(text);

            var context = new RazorCodeActionContext(request, documentSnapshot, codeDocument, location, sourceText, supportsFileCreation);

            return(context);
        }
        private static RazorCodeActionContext CreateRazorCodeActionContext(RazorCodeActionParams request, SourceLocation location, string filePath, string text, bool supportsFileCreation = true)
        {
            var codeDocument = TestRazorCodeDocument.CreateEmpty();

            codeDocument.SetFileKind(FileKinds.Component);

            var sourceDocument = TestRazorSourceDocument.Create(text, filePath: filePath, relativePath: filePath);
            var options        = RazorParserOptions.Create(o =>
            {
                o.Directives.Add(ComponentCodeDirective.Directive);
                o.Directives.Add(FunctionsDirective.Directive);
            });
            var syntaxTree = RazorSyntaxTree.Parse(sourceDocument, options);

            codeDocument.SetSyntaxTree(syntaxTree);

            var documentSnapshot = Mock.Of <DocumentSnapshot>(document =>
                                                              document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
                                                              document.GetTextAsync() == Task.FromResult(codeDocument.GetSourceText()));

            var sourceText = SourceText.From(text);

            var context = new RazorCodeActionContext(request, documentSnapshot, codeDocument, location, sourceText, supportsFileCreation, supportsCodeActionResolve: true);

            return(context);
        }
Exemplo n.º 4
0
 public override Task <CommandOrCodeActionContainer> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
 {
     return(Task.FromResult(new CommandOrCodeActionContainer(new List <CommandOrCodeAction>()
     {
         new CommandOrCodeAction(new CodeAction()),
     })));
 }
Exemplo n.º 5
0
        public static CodeAction WrapResolvableCSharpCodeAction(
            this CodeAction 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.Data = JToken.FromObject(resolutionParams);

            return(razorCodeAction);
        }
 public override Task <RazorCodeAction[]> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
 {
     // O# Code Actions don't have `Data`, but `Commands` do
     return(Task.FromResult(new[] {
         new RazorCodeAction()
         {
             Title = "SomeTitle",
             Data = new AddUsingsCodeActionParams()
         }
     }));
 }
Exemplo n.º 7
0
 public override Task <IReadOnlyList <CodeAction> > ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
 {
     // O# Code Actions don't have `Data`, but `Commands` do
     return(Task.FromResult(new List <CodeAction>()
     {
         new CodeAction()
         {
             Title = "SomeTitle",
             Data = JToken.FromObject(new AddUsingsCodeActionParams())
         }
     } as IReadOnlyList <CodeAction>));
 }
        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);
        }
    }
Exemplo n.º 9
0
 public override Task <IReadOnlyList <CodeAction> > ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
 {
     return(Task.FromResult <IReadOnlyList <CodeAction> >(null));
 }
 public override Task <RazorCodeAction[]> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
 {
     return(null);
 }
 public override Task <RazorCodeAction[]> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
 {
     return(Task.FromResult(new[] { new RazorCodeAction() }));
 }
Exemplo n.º 12
0
 public override Task <CommandOrCodeActionContainer> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
 {
     return(null);
 }