public override async Task <object> HandleRequestAsync(LSP.ExecuteCommandParams request, RequestContext context, CancellationToken cancellationToken)
        {
            var document = context.Document;

            Contract.ThrowIfNull(document);

            var runRequest = ((JToken)request.Arguments.Single()).ToObject <CodeActionResolveData>();

            Assumes.Present(runRequest);

            var options = _globalOptions.GetCodeActionOptionsProvider();

            var codeActionsCache = context.GetRequiredLspService <CodeActionsCache>();
            var codeActions      = await CodeActionHelpers.GetCodeActionsAsync(
                codeActionsCache, document, runRequest.Range, options, _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);
        }
Esempio n. 2
0
        public async Task <LSP.CodeAction[]> HandleRequestAsync(LSP.CodeActionParams request, RequestContext context, CancellationToken cancellationToken)
        {
            var document = context.Document;

            Contract.ThrowIfNull(document);

            var options = _globalOptions.GetCodeActionOptionsProvider();

            var codeActionsCache = context.GetRequiredLspService <CodeActionsCache>();
            var codeActions      = await CodeActionHelpers.GetVSCodeActionsAsync(
                request, codeActionsCache, document, options, _codeFixService, _codeRefactoringService, cancellationToken).ConfigureAwait(false);

            return(codeActions);
        }