Ejemplo n.º 1
0
        private static Task <Document> RefactorAsync(
            Document document,
            PragmaWarningDirectiveTriviaSyntax directive,
            CancellationToken cancellationToken)
        {
            SyntaxTrivia trivia = directive.ParentTrivia;

            SyntaxTriviaList list = trivia.GetContainingList();

            int index = list.IndexOf(trivia);

            int start = directive.EndOfDirectiveToken.SpanStart;

            StringBuilder sb = StringBuilderCache.GetInstance();

            int i = index + 1;

            SyntaxKind disableOrRestoreKind = directive.DisableOrRestoreKeyword.Kind();

            int end = start;

            bool addComma = !directive.ErrorCodes.HasTrailingSeparator();

            while (i < list.Count)
            {
                SyntaxTrivia trivia2 = list[i];

                if (trivia2.IsWhitespaceOrEndOfLineTrivia())
                {
                    i++;
                    continue;
                }

                if (trivia2.GetStructure() is PragmaWarningDirectiveTriviaSyntax directive2 &&
                    disableOrRestoreKind == directive2.DisableOrRestoreKeyword.Kind())
                {
                    if (addComma)
                    {
                        sb.Append(",");
                    }

                    sb.Append(" ");

                    SeparatedSyntaxList <ExpressionSyntax> errorCodes = directive2.ErrorCodes;
                    sb.Append(errorCodes.ToString());

                    addComma = !errorCodes.HasTrailingSeparator();

                    end = directive2.ErrorCodes.Span.End;
                }

                i++;
            }

            return(document.WithTextChangeAsync(
                       TextSpan.FromBounds(start, end),
                       StringBuilderCache.GetStringAndFree(sb),
                       cancellationToken));
        }