private static async Task <Document> ConvertFileScopedNamespaceAsync(Document document, CancellationToken cancellationToken) { var root = (CompilationUnitSyntax)await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); return(root.Members.OfType <FileScopedNamespaceDeclarationSyntax>().FirstOrDefault() is { } fileScopedNamespace ? await ConvertNamespaceTransform.ConvertFileScopedNamespaceAsync(document, fileScopedNamespace, cancellationToken).ConfigureAwait(false) : document); }
public async Task <Document> FormatNewDocumentAsync(Document document, Document?hintDocument, CodeCleanupOptions options, CancellationToken cancellationToken) { var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); var root = (CompilationUnitSyntax)await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var namespaces = GetNamespacesToReplace(document, root, optionSet).ToList(); if (namespaces.Count != 1) { return(document); } return(await ConvertNamespaceTransform.ConvertAsync(document, namespaces[0], options.FormattingOptions, cancellationToken).ConfigureAwait(false)); }
public async Task <Document> FormatNewDocumentAsync(Document document, Document?hintDocument, CancellationToken cancellationToken) { var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); var root = (CompilationUnitSyntax)await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var namespaces = GetNamespacesToReplace(document, root, optionSet); return(await document.ReplaceNodesAsync(namespaces, (oldNode, newNode) => ConvertNamespaceTransform.Convert((BaseNamespaceDeclarationSyntax)newNode), cancellationToken).ConfigureAwait(false)); }