public async Task TestRunCodeActions() { var markup = @"class A { class {|caret:|}B { } }"; var expectedTextForB = @"partial class A { class B { } }"; using var testLspServer = await CreateTestLspServerAsync(markup); var caretLocation = testLspServer.GetLocations("caret").Single(); var commandArgument = new CodeActionResolveData(string.Format(FeaturesResources.Move_type_to_0, "B.cs"), customTags: ImmutableArray <string> .Empty, caretLocation.Range, new LSP.TextDocumentIdentifier { Uri = caretLocation.Uri }); var results = await ExecuteRunCodeActionCommandAsync(testLspServer, commandArgument); var documentForB = testLspServer.TestWorkspace.CurrentSolution.Projects.Single().Documents.Single(doc => doc.Name.Equals("B.cs", StringComparison.OrdinalIgnoreCase)); var textForB = await documentForB.GetTextAsync(); Assert.Equal(expectedTextForB, textForB.ToString()); }
private static async Task <bool> ExecuteRunCodeActionCommandAsync( TestLspServer testLspServer, CodeActionResolveData codeActionData) { var command = new LSP.ExecuteCommandParams { Command = CodeActionsHandler.RunCodeActionCommandName, Arguments = new object[] { JToken.FromObject(codeActionData) } }; var result = await testLspServer.ExecuteRequestAsync <LSP.ExecuteCommandParams, object>( LSP.Methods.WorkspaceExecuteCommandName, command, new LSP.ClientCapabilities(), null, CancellationToken.None); return((bool)result); }
internal static LSP.VSCodeAction CreateCodeAction( string title, LSP.CodeActionKind kind, LSP.VSCodeAction[] children, CodeActionResolveData data, LSP.Diagnostic[] diagnostics, LSP.WorkspaceEdit edit = null, LSP.Command command = null) { var action = new LSP.VSCodeAction { Title = title, Kind = kind, Children = children, Data = JToken.FromObject(data), Diagnostics = diagnostics, Edit = edit, Command = command }; return(action); }
static LSP.Command SetCommand(string title, CodeActionResolveData data) => new LSP.Command { CommandIdentifier = CodeActionsHandler.RunCodeActionCommandName, Title = title, Arguments = new object[] { data } };