<commit_before>using System;
using System.Threading;
using System.Threading.Tasks;

using CodeFormatter.Engine;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Simplification;

namespace CodeFormatter.Rules
{
    [ExportFormattingRule(Int32.MaxValue / 2)]
    internal sealed class IsSimplifiedFormattingRule : IFormattingRule
    {
        public Task<Document> ProcessAsync(CancellationToken cancellationToken, Document document)
        {
            return Simplifier.ReduceAsync(document, cancellationToken: cancellationToken);
        }
    }
}<commit_msg>Make simplifier work<commit_after>using System;
using System.Threading;
using System.Threading.Tasks;

using CodeFormatter.Engine;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Simplification;

namespace CodeFormatter.Rules
{
    [ExportFormattingRule(Int32.MaxValue / 2)]
    internal sealed class IsSimplifiedFormattingRule : IFormattingRule
    {
        public async Task<Document> ProcessAsync(CancellationToken cancellationToken, Document document)
        {
            var root = await document.GetSyntaxRootAsync(cancellationToken);

            // The simplifier will only simplify nodes that are annotated with a
            // specific annotation. Right now, there is no API on the simplifier
            // to say "ignore all annotations and reduce everything". The
            // workaround is to simply annotate each node. Yep, that's not going
            // to make the GC happy but it will totally get the job done.
            var annotater = new Annotater();
            var annoatedRoot = annotater.Visit(root);
            var annotatedDocument = document.WithSyntaxRoot(annoatedRoot);

            return await Simplifier.ReduceAsync(annotatedDocument, cancellationToken: cancellationToken);
        }

        private sealed class Annotater : CSharpSyntaxRewriter
        {
            public override SyntaxNode Visit(SyntaxNode node)
            {
                if (node == null)
                    return null;

                var rewrittenNode = base.Visit(node);
                return rewrittenNode.WithAdditionalAnnotations(Simplifier.Annotation);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06476105404198303, 'fraction_numerical': 0.0026797677534613666, 'mean_word_length': 2.8487972508591066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3111056', 'n_tokens_mistral': 561, 'n_tokens_neox': 537, 'n_words': 157}