コード例 #1
0
        public static async Task <Solution> GetRequiredChangedSolutionAsync(this CodeAction codeAction, IProgressTracker progressTracker, CancellationToken cancellationToken)
        {
            var solution = await codeAction.GetChangedSolutionAsync(progressTracker, cancellationToken).ConfigureAwait(false);

            if (solution is null)
            {
                throw new InvalidOperationException(string.Format(WorkspacesResources.CodeAction__0__did_not_produce_a_changed_solution, codeAction.Title));
            }

            return(solution);
        }
コード例 #2
0
        private async Task <(ProjectChanges, IEnumerable <TextChange>)> GetChangesForCodeActionAsync(
            Document document,
            CodeAction codeAction,
            ProgressTracker progressTracker,
            IDocumentTextDifferencingService textDiffingService,
            CancellationToken cancellationToken)
        {
            var newSolution = await codeAction.GetChangedSolutionAsync(
                progressTracker, cancellationToken : cancellationToken).ConfigureAwait(false);

            var newDocument = newSolution.GetDocument(document.Id);

            // Use Line differencing to reduce the possibility of changes that overwrite existing code.
            var textChanges = await textDiffingService.GetTextChangesAsync(
                document, newDocument, TextDifferenceTypes.Line, cancellationToken).ConfigureAwait(false);

            var projectChanges = newDocument.Project.GetChanges(document.Project);

            return(projectChanges, textChanges);
        }