示例#1
0
        public async Task GetCSharpCodeActionsFromLanguageServerAsync_InvalidRangeMapping()
        {
            // Arrange
            var   documentPath           = "C:/path/to/Page.razor";
            var   codeDocument           = CreateCodeDocument("@code {}");
            var   documentResolver       = CreateDocumentResolver(documentPath, codeDocument);
            Range projectedRange         = null;
            var   documentMappingService = Mock.Of <DefaultRazorDocumentMappingService>(
                d => d.TryMapToProjectedDocumentRange(It.IsAny <RazorCodeDocument>(), It.IsAny <Range>(), out projectedRange) == false
                );
            var codeActionEndpoint = new CodeActionEndpoint(
                documentMappingService,
                Array.Empty <RazorCodeActionProvider>(),
                new CSharpCodeActionProvider[] {
                new MockCSharpCodeActionProvider()
            },
                Dispatcher,
                documentResolver,
                LanguageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

            var initialRange = new Range(new Position(0, 1), new Position(0, 1));
            var request      = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = initialRange,
                Context      = new ExtendedCodeActionContext()
            };

            var context = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, default);

            // Act
            var results = await codeActionEndpoint.GetCSharpCodeActionsFromLanguageServerAsync(context, default);

            // Assert
            Assert.Empty(results);
            Assert.Equal(initialRange, context.Request.Range);
        }
示例#2
0
        public async Task GetCSharpCodeActionsFromLanguageServerAsync_ReturnsCodeActions()
        {
            // Arrange
            var documentPath           = "C:/path/to/Page.razor";
            var codeDocument           = CreateCodeDocument("@code {}");
            var documentResolver       = CreateDocumentResolver(documentPath, codeDocument);
            var projectedRange         = new Range(new Position(15, 2), new Position(15, 2));
            var documentMappingService = CreateDocumentMappingService(projectedRange);
            var languageServer         = CreateLanguageServer();
            var codeActionEndpoint     = new CodeActionEndpoint(
                documentMappingService,
                Array.Empty <RazorCodeActionProvider>(),
                new CSharpCodeActionProvider[] {
                new MockCSharpCodeActionProvider()
            },
                Dispatcher,
                documentResolver,
                languageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

            var initialRange = new Range(new Position(0, 1), new Position(0, 1));
            var request      = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = initialRange,
                Context      = new ExtendedCodeActionContext()
            };

            var context = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, default);

            // Act
            var results = await codeActionEndpoint.GetCSharpCodeActionsFromLanguageServerAsync(context, default);

            // Assert
            Assert.Single(results);
            Assert.Equal(projectedRange, context.Request.Range);
        }
示例#3
0
        public async Task GenerateRazorCodeActionContextAsync_WithSelectionRange()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeDocument       = CreateCodeDocument("@code {}");
            var documentResolver   = CreateDocumentResolver(documentPath, codeDocument);
            var codeActionEndpoint = new CodeActionEndpoint(
                DocumentMappingService,
                new RazorCodeActionProvider[] {
                new MockRazorCodeActionProvider()
            },
                Array.Empty <CSharpCodeActionProvider>(),
                Dispatcher,
                documentResolver,
                LanguageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

            var initialRange   = new Range(new Position(0, 1), new Position(0, 1));
            var selectionRange = new Range(new Position(0, 5), new Position(0, 5));
            var request        = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = initialRange,
                Context      = new ExtendedCodeActionContext()
                {
                    SelectionRange = selectionRange,
                }
            };

            // Act
            var razorCodeActionContext = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, default);

            // Assert
            Assert.NotNull(razorCodeActionContext);
            Assert.Equal(selectionRange, razorCodeActionContext.Request.Range);
        }