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); }
protected abstract CodeGenerationOptions WithContextImpl(CodeGenerationContext value);
public CodeGenerationOptions WithContext(CodeGenerationContext value) => WithContextImpl(value);
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)); }
protected CodeGenerationOptions(CodeGenerationContext context) { Context = context; }
public abstract CodeGenerationOptions GetOptions(CodeGenerationContext context);
protected CodeGenerationContextInfo(CodeGenerationContext context) { Context = context; }
public static CodeGenerationOptions GetOptions(this ICodeGenerationService service, ParseOptions parseOptions, OptionSet documentOptions, CodeGenerationContext context) => service.GetPreferences(parseOptions, documentOptions).GetOptions(context);