protected override async Task <IEnumerable <CodeActionOperation> > ComputePreviewOperationsAsync(CancellationToken cancellationToken) { // If we have a codeaction, then just call the base method which will call ComputeOperationsAsync below. // This creates an ApplyChagesOperation so that Roslyn can show a preview of the changes. if (_codeActionWorkspaceEdit != null) { return(await base.ComputePreviewOperationsAsync(cancellationToken).ConfigureAwait(false)); } // We have a command - this will be executed on the host but the host may have a preview for the current document. var runCodeActionsCommand = ((JToken)_command.Arguments?.Single()).ToObject <LSP.Command>(); var runCodeActionParams = ((JToken)runCodeActionsCommand.Arguments?.Single())?.ToObject <RunCodeActionParams>(); var request = new LspRequest <RunCodeActionParams, LSP.TextEdit[]>(RoslynMethods.CodeActionPreviewName); var textEdits = await _lspClient.RequestAsync(request, runCodeActionParams, cancellationToken).ConfigureAwait(false); if (textEdits == null || textEdits.Length == 0) { return(ImmutableArray <CodeActionOperation> .Empty); } var newDocument = await ApplyEditsAsync(_document, textEdits, cancellationToken).ConfigureAwait(false); return(ImmutableArray.Create(new ApplyChangesOperation(newDocument.Project.Solution))); }
public override void Apply(Workspace workspace, CancellationToken cancellationToken) { Task.Run(async() => { var executeCommandParams = new ExecuteCommandParams { Command = _command.CommandIdentifier, Arguments = _command.Arguments }; await _lspClient.RequestAsync(Methods.WorkspaceExecuteCommand, executeCommandParams, cancellationToken).ConfigureAwait(false); }); }