public async Task <object> HandleRequestAsync(LSP.ExecuteCommandParams request, RequestContext context, CancellationToken cancellationToken) { var runRequest = ((JToken)request.Arguments.Single()).ToObject <CodeActionResolveData>(); var document = _solutionProvider.GetDocument(runRequest.TextDocument); Contract.ThrowIfNull(document); var codeActions = await CodeActionHelpers.GetCodeActionsAsync( _codeActionsCache, document, runRequest.Range, _codeFixService, _codeRefactoringService, cancellationToken).ConfigureAwait(false); var actionToRun = CodeActionHelpers.GetCodeActionToResolve(runRequest.UniqueIdentifier, codeActions); Contract.ThrowIfNull(actionToRun); var operations = await actionToRun.GetOperationsAsync(cancellationToken).ConfigureAwait(false); // TODO - This UI thread dependency should be removed. // https://github.com/dotnet/roslyn/projects/45#card-20619668 await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); foreach (var operation in operations) { operation.Apply(document.Project.Solution.Workspace, cancellationToken); } return(true); }
public override LSP.TextDocumentIdentifier?GetTextDocumentIdentifier(LSP.ExecuteCommandParams request) { var runRequest = ((JToken)request.Arguments.Single()).ToObject <CodeActionResolveData>(); Assumes.Present(runRequest); return(runRequest.TextDocument); }
public async Task <object?> ExecuteWorkspaceCommandAsync(LSP.ExecuteCommandParams request, CancellationToken cancellationToken) { Contract.ThrowIfNull(_clientCapabilities, $"{nameof(InitializeAsync)} has not been called."); var requestMethod = AbstractExecuteWorkspaceCommandHandler.GetRequestNameForCommandName(request.Command); var result = await _requestDispatcher.ExecuteRequestAsync <LSP.ExecuteCommandParams, object>( requestMethod, request, _clientCapabilities, _queue, cancellationToken).ConfigureAwait(false); return(result); }
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); }
public async Task <object> HandleRequestAsync(Solution solution, LSP.ExecuteCommandParams request, LSP.ClientCapabilities clientCapabilities, CancellationToken cancellationToken) { var runRequest = ((JToken)request.Arguments.Single()).ToObject <RunCodeActionParams>(); var codeActions = await GetCodeActionsAsync(solution, runRequest.CodeActionParams.TextDocument.Uri, runRequest.CodeActionParams.Range, cancellationToken).ConfigureAwait(false); var actionToRun = codeActions?.FirstOrDefault(a => a.Title == runRequest.Title); if (actionToRun != null) { foreach (var operation in await actionToRun.GetOperationsAsync(cancellationToken).ConfigureAwait(false)) { operation.Apply(solution.Workspace, cancellationToken); } } return(true); }
/// <summary> /// Answers an execute workspace command request by handling the specified command name. /// https://microsoft.github.io/language-server-protocol/specification#workspace_executeCommand /// </summary> /// <param name="solution">the solution relevant to the workspace.</param> /// <param name="request">the request command name and arguments.</param> /// <param name="clientCapabilities">the client capabilities for the request.</param> /// <param name="cancellationToken">a cancellation token.</param> /// <returns>any or null.</returns> public Task <object> ExecuteWorkspaceCommandAsync(Solution solution, LSP.ExecuteCommandParams request, LSP.ClientCapabilities clientCapabilities, CancellationToken cancellationToken) => ExecuteRequestAsync <LSP.ExecuteCommandParams, object>(LSP.Methods.WorkspaceExecuteCommandName, solution, request, clientCapabilities, cancellationToken);
public Task <object> InvokeCommandAsync(LSP.ExecuteCommandParams request, CancellationToken cancellationToken) => InvokeWithParametersAsync <object>("workspace/executeCommand", request, cancellationToken);