private async Task <Document> GetEditAsync(
            Solution solution,
            INamespaceOrTypeSymbol destination,
            Func <SyntaxNode, TCodeGenerationOptions, IList <bool>?, CancellationToken, SyntaxNode> declarationTransform,
            CodeGenerationContext context,
            CancellationToken cancellationToken)
        {
            var(destinationDeclaration, availableIndices) =
                await this.FindMostRelevantDeclarationAsync(solution, destination, context, cancellationToken).ConfigureAwait(false);

            if (destinationDeclaration == null)
            {
                throw new ArgumentException(WorkspacesResources.Could_not_find_location_to_generation_symbol_into);
            }

            var destinationTree = destinationDeclaration.SyntaxTree;
            var oldDocument     = solution.GetRequiredDocument(destinationTree);
            var options         = (TCodeGenerationOptions)await CodeGenerationOptions.FromDocumentAsync(context, oldDocument, cancellationToken).ConfigureAwait(false);

            var transformedDeclaration = declarationTransform(destinationDeclaration, options, availableIndices, cancellationToken);

            var root = await destinationTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var currentRoot = root.ReplaceNode(destinationDeclaration, transformedDeclaration);

            var newDocument = oldDocument.WithSyntaxRoot(currentRoot);

            if (context.AddImports)
            {
                newDocument = await ImportAdder.AddImportsFromSymbolAnnotationAsync(
                    newDocument,
                    await newDocument.GetOptionsAsync(cancellationToken).ConfigureAwait(false),
                    cancellationToken).ConfigureAwait(false);
            }

            return(newDocument);
        }
Пример #2
0
 protected abstract CodeGenerationOptions WithContextImpl(CodeGenerationContext value);
Пример #3
0
 public CodeGenerationOptions WithContext(CodeGenerationContext value)
 => WithContextImpl(value);
Пример #4
0
        public static async ValueTask <CodeGenerationOptions> FromDocumentAsync(CodeGenerationContext context, Document document, CancellationToken cancellationToken)
        {
            var preferences = await CodeGenerationPreferences.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false);

            return(preferences.GetOptions(context));
        }
Пример #5
0
 protected CodeGenerationOptions(CodeGenerationContext context)
 {
     Context = context;
 }
Пример #6
0
 public abstract CodeGenerationOptions GetOptions(CodeGenerationContext context);
 protected CodeGenerationContextInfo(CodeGenerationContext context)
 {
     Context = context;
 }
Пример #8
0
 public static CodeGenerationOptions GetOptions(this ICodeGenerationService service, ParseOptions parseOptions, OptionSet documentOptions, CodeGenerationContext context)
 => service.GetPreferences(parseOptions, documentOptions).GetOptions(context);