Repository: dotnet/roslyn
File: src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.AddConstructorParametersCodeAction.cs (C#)

Code before:
            var newConstructor = constructor;
            newConstructor = codeGenerator.AddParameters(newConstructor, _missingParameters, _info, cancellationToken);

            if (!isPrimaryConstructor)
            {
                // For regular constructors, add assignment statements
                newConstructor = codeGenerator.AddStatements(newConstructor, CreateAssignStatements(_constructorCandidate), _info, cancellationToken)
                                                      .WithAdditionalAnnotations(Formatter.Annotation);

                var syntaxTree = constructor.SyntaxTree;
                var newRoot = syntaxTree.GetRoot(cancellationToken).ReplaceNode(constructor, newConstructor);

                // Make sure we get the document that contains the constructor we just updated
                var constructorDocument = _document.Project.GetDocument(syntaxTree);
                Contract.ThrowIfNull(constructorDocument);

                return constructorDocument.WithSyntaxRoot(newRoot).Project.Solution;
            }
            else
            {
                // For primary constructors, we need to:
                // 1. Update the primary constructor with new parameters
                // 2. Add initializers to the properties/fields
                var solution = await AddParametersAndInitializersToPrimaryConstructorAsync(
                    newConstructor, cancellationToken).ConfigureAwait(false);
                return solution;
            }
        }

        private async Task<Solution> AddParametersAndInitializersToPrimaryConstructorAsync(
            SyntaxNode newConstructor,
            CancellationToken cancellationToken)
        {
            var solution = _document.Project.Solution;
            var solutionEditor = new SolutionEditor(solution);

            // First, update the primary constructor declaration with the new parameters
            var oldConstructor = _document.GetRequiredLanguageService<ISymbolDeclarationService>()
                .GetDeclarations(_constructorCandidate.Constructor)
                .Select(r => r.GetSyntax(cancellationToken))
                .First();

            var syntaxTree = oldConstructor.SyntaxTree;
            var documentToUpdate = solution.GetRequiredDocument(syntaxTree);
            var editor = await solutionEditor.GetDocumentEditorAsync(documentToUpdate.Id, cancellationToken).ConfigureAwait(false);
            editor.ReplaceNode(oldConstructor, newConstructor.WithAdditionalAnnotations(Formatter.Annotation));

            // Now add initializers to each member
            for (var i = 0; i < _missingParameters.Length; ++i)
            {
                var member = _constructorCandidate.MissingMembers[i];

Review comment (suggestion):
```suggestion
                return await AddParametersAndInitializersToPrimaryConstructorAsync(
                    newConstructor, cancellationToken).ConfigureAwait(false);
```

Code after:
            var newConstructor = codeGenerator.AddParameters(
                oldConstructor, MissingParameters.SelectAsArray(t => t.parameter), _info, cancellationToken);

            return newConstructor;
        }

        private Solution AddParametersToRegularConstructor(SyntaxNode constructor, CancellationToken cancellationToken)
        {
            var codeGenerator = _document.GetRequiredLanguageService<ICodeGenerationService>();

            // For regular constructors, add assignment statements
            var newConstructor = GetNewConstructor(constructor, cancellationToken);
            newConstructor = codeGenerator
                .AddStatements(newConstructor, CreateAssignStatements(), _info, cancellationToken)
                .WithAdditionalAnnotations(Formatter.Annotation);

            var syntaxTree = constructor.SyntaxTree;
            var newRoot = syntaxTree.GetRoot(cancellationToken).ReplaceNode(constructor, newConstructor);

            // Make sure we get the document that contains the constructor we just updated
            var constructorDocument = _document.Project.GetDocument(syntaxTree);
            Contract.ThrowIfNull(constructorDocument);

            return constructorDocument.WithSyntaxRoot(newRoot).Project.Solution;
        }

        private async Task<Solution> AddParametersAndInitializersToPrimaryConstructorAsync(
            SyntaxNode constructor,
            CancellationToken cancellationToken)
        {
            // For primary constructors, we need to:
            //
            // 1. Add initializers to the properties/fields
            // 2. Update the primary constructor with new parameters
            //
            // We need to do it in this order so that we see the adjustment to the properties/fields when we're updating
            // the primary constructor that wraps them all.
            var newConstructor = GetNewConstructor(constructor, cancellationToken);

            var solution = _document.Project.Solution;
            var solutionEditor = new SolutionEditor(solution);

            // First, update the primary constructor declaration with the new parameters
            var oldConstructor = _document.GetRequiredLanguageService<ISymbolDeclarationService>()
                .GetDeclarations(Constructor)
                .Select(r => r.GetSyntax(cancellationToken))
                .First();

            var oldConstructorSyntaxTree = oldConstructor.SyntaxTree;

            foreach (var (parameter, member) in MissingParameters)