Ejemplo n.º 1
0
        public async Task TestCodeActionResolveHandlerAsync_NestedAction()
        {
            var initialMarkup =
                @"class A
{
    void M()
    {
        int {|caret:|}i = 1;
    }
}";

            using var workspace = CreateTestWorkspace(initialMarkup, out var locations);

            var unresolvedCodeAction = CodeActionsTests.CreateCodeAction(
                title: string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(
                    FeaturesResources.Introduce_constant + "|" + string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                    locations["caret"].Single()),
                diagnostics: null);

            var expectedMarkup =
                @"class A
{
    private const int V = 1;

    void M()
    {
        int i = V;
    }
}";

            var expected = CodeActionsTests.CreateCodeAction(
                title: string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(
                    FeaturesResources.Introduce_constant + "|" + string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                    locations["caret"].Single()),
                diagnostics: null,
                edit: GenerateWorkspaceEdit(
                    locations, expectedMarkup, new LSP.Range {
                Start = new Position(0, 0), End = new Position(6, 1)
            }));

            var result = await RunGetCodeActionResolveAsync(workspace.CurrentSolution, unresolvedCodeAction);

            AssertJsonEquals(expected, result);
        }
Ejemplo n.º 2
0
        public async Task TestCodeActionResolveHandlerAsync()
        {
            var initialMarkup =
                @"class A
{
    void M()
    {
        {|caret:|}int i = 1;
    }
}";

            using var workspace = CreateTestWorkspace(initialMarkup, out var locations);

            var unresolvedCodeAction = CodeActionsTests.CreateCodeAction(
                title: CSharpAnalyzersResources.Use_implicit_type,
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(CSharpAnalyzersResources.Use_implicit_type, locations["caret"].Single()),
                diagnostics: null);

            var expectedMarkup =
                @"class A
{
    void M()
    {
        var i = 1;
    }
}";
            var expected = CodeActionsTests.CreateCodeAction(
                title: CSharpAnalyzersResources.Use_implicit_type,
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(CSharpAnalyzersResources.Use_implicit_type, locations["caret"].Single()),
                diagnostics: null,
                edit: GenerateWorkspaceEdit(
                    locations, expectedMarkup, new LSP.Range {
                Start = new Position(0, 0), End = new Position(6, 1)
            }));

            var result = await RunGetCodeActionResolveAsync(workspace.CurrentSolution, unresolvedCodeAction);

            AssertJsonEquals(expected, result);
        }
Ejemplo n.º 3
0
        public async Task TestCodeActionResolveHandlerAsync()
        {
            var initialMarkup =
                @"class A
{
    void M()
    {
        {|caret:|}int i = 1;
    }
}";

            using var testLspServer = CreateTestLspServer(initialMarkup, out var locations);

            var unresolvedCodeAction = CodeActionsTests.CreateCodeAction(
                title: CSharpAnalyzersResources.Use_implicit_type,
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(
                    CSharpAnalyzersResources.Use_implicit_type,
                    locations["caret"].Single()
                    ),
                priority: PriorityLevel.Low,
                groupName: "Roslyn1",
                applicableRange: new LSP.Range
            {
                Start = new Position {
                    Line = 4, Character = 8
                },
                End = new Position {
                    Line = 4, Character = 11
                }
            },
                diagnostics: null
                );

            // Expected text after edit:
            //     class A
            //     {
            //         void M()
            //         {
            //             var i = 1;
            //         }
            //     }
            var expectedTextEdits = new LSP.TextEdit[]
            {
                GenerateTextEdit(
                    "var",
                    new LSP.Range {
                    Start = new Position(4, 8), End = new Position(4, 11)
                }
                    )
            };

            var expectedResolvedAction = CodeActionsTests.CreateCodeAction(
                title: CSharpAnalyzersResources.Use_implicit_type,
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(
                    CSharpAnalyzersResources.Use_implicit_type,
                    locations["caret"].Single()
                    ),
                priority: PriorityLevel.Low,
                groupName: "Roslyn1",
                diagnostics: null,
                applicableRange: new LSP.Range
            {
                Start = new Position {
                    Line = 4, Character = 8
                },
                End = new Position {
                    Line = 4, Character = 11
                }
            },
                edit: GenerateWorkspaceEdit(locations, expectedTextEdits)
                );

            var actualResolvedAction = await RunGetCodeActionResolveAsync(
                testLspServer,
                unresolvedCodeAction
                );

            AssertJsonEquals(expectedResolvedAction, actualResolvedAction);
        }
Ejemplo n.º 4
0
        public async Task TestCodeActionResolveHandlerAsync_NestedAction()
        {
            var initialMarkup =
                @"class A
{
    void M()
    {
        int {|caret:|}i = 1;
    }
}";

            using var testLspServer = CreateTestLspServer(initialMarkup, out var locations);

            var unresolvedCodeAction = CodeActionsTests.CreateCodeAction(
                title: string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(
                    FeaturesResources.Introduce_constant
                    + "|"
                    + string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                    locations["caret"].Single()
                    ),
                priority: PriorityLevel.Normal,
                groupName: "Roslyn2",
                applicableRange: new LSP.Range
            {
                Start = new Position {
                    Line = 4, Character = 8
                },
                End = new Position {
                    Line = 4, Character = 11
                }
            },
                diagnostics: null
                );

            // Expected text after edits:
            //     class A
            //     {
            //         private const int V = 1;
            //
            //         void M()
            //         {
            //             int i = V;
            //         }
            //     }
            var expectedTextEdits = new LSP.TextEdit[]
            {
                GenerateTextEdit(
                    @"private const int V = 1;

",
                    new LSP.Range {
                    Start = new Position(2, 4), End = new Position(2, 4)
                }
                    ),
                GenerateTextEdit(
                    "V",
                    new LSP.Range {
                    Start = new Position(4, 16), End = new Position(4, 17)
                }
                    )
            };

            var expectedResolvedAction = CodeActionsTests.CreateCodeAction(
                title: string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                kind: CodeActionKind.Refactor,
                children: Array.Empty <LSP.VSCodeAction>(),
                data: CreateCodeActionResolveData(
                    FeaturesResources.Introduce_constant
                    + "|"
                    + string.Format(FeaturesResources.Introduce_constant_for_0, "1"),
                    locations["caret"].Single()
                    ),
                priority: PriorityLevel.Normal,
                groupName: "Roslyn2",
                applicableRange: new LSP.Range
            {
                Start = new Position {
                    Line = 4, Character = 8
                },
                End = new Position {
                    Line = 4, Character = 11
                }
            },
                diagnostics: null,
                edit: GenerateWorkspaceEdit(locations, expectedTextEdits)
                );

            var actualResolvedAction = await RunGetCodeActionResolveAsync(
                testLspServer,
                unresolvedCodeAction
                );

            AssertJsonEquals(expectedResolvedAction, actualResolvedAction);
        }