Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public override LSP.TextDocumentIdentifier?GetTextDocumentIdentifier(LSP.ExecuteCommandParams request)
        {
            var runRequest = ((JToken)request.Arguments.Single()).ToObject <CodeActionResolveData>();

            Assumes.Present(runRequest);

            return(runRequest.TextDocument);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 /// <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);
Exemplo n.º 7
0
 public Task <object> InvokeCommandAsync(LSP.ExecuteCommandParams request, CancellationToken cancellationToken)
 => InvokeWithParametersAsync <object>("workspace/executeCommand", request, cancellationToken);