示例#1
0
        private LineColumnDelta FormatStructuredTrivia(
            LineColumn lineColumn, SyntaxTrivia trivia, ArrayBuilder <TextChange> changes, CancellationToken cancellationToken)
        {
            if (trivia.Kind() == SyntaxKind.SkippedTokensTrivia)
            {
                // don't touch anything if it contains skipped tokens
                _succeeded = false;
                return(GetLineColumnDelta(lineColumn, trivia));
            }

            // TODO : make document comment to be formatted by structured trivia formatter as well.
            if (!trivia.IsDocComment())
            {
                var result = CSharpStructuredTriviaFormatEngine.Format(
                    trivia, this.InitialLineColumn.Column, this.Options, this.FormattingRules, cancellationToken);
                if (result.GetTextChanges(cancellationToken).Count == 0)
                {
                    return(GetLineColumnDelta(lineColumn, trivia));
                }

                changes.AddRange(result.GetTextChanges(cancellationToken));

                var formattedTrivia = SyntaxFactory.Trivia((StructuredTriviaSyntax)result.GetFormattedRoot(cancellationToken));
                return(GetLineColumnDelta(lineColumn, formattedTrivia));
            }

            var docComment = FormatDocumentComment(lineColumn, trivia);

            if (docComment != trivia)
            {
                changes.Add(new TextChange(trivia.FullSpan, docComment.ToFullString()));
            }

            return(GetLineColumnDelta(lineColumn, docComment));
        }
示例#2
0
        private LineColumnDelta FormatStructuredTrivia(
            LineColumn lineColumn, SyntaxTrivia trivia, List <SyntaxTrivia> changes, CancellationToken cancellationToken)
        {
            if (trivia.CSharpKind() == SyntaxKind.SkippedTokensTrivia)
            {
                // don't touch anything if it contains skipped tokens
                this.succeeded = false;
                changes.Add(trivia);

                return(GetLineColumnDelta(lineColumn, trivia));
            }

            // TODO : make document comment to be formatted by structured trivia formatter as well.
            if (!trivia.IsDocComment())
            {
                var result = CSharpStructuredTriviaFormatEngine.Format(
                    trivia, this.InitialLineColumn.Column, this.OptionSet, this.FormattingRules, cancellationToken);
                var formattedTrivia = SyntaxFactory.Trivia((StructuredTriviaSyntax)result.GetFormattedRoot(cancellationToken));

                changes.Add(formattedTrivia);
                return(GetLineColumnDelta(lineColumn, formattedTrivia));
            }

            var docComment = FormatDocumentComment(lineColumn, trivia);

            changes.Add(docComment);

            return(GetLineColumnDelta(lineColumn, docComment));
        }
 public static IFormattingResult Format(
     SyntaxTrivia trivia,
     int initialColumn,
     OptionSet optionSet,
     ChainedFormattingRules formattingRules,
     CancellationToken cancellationToken)
 {
     var root = trivia.GetStructure();
     var formatter = new CSharpStructuredTriviaFormatEngine(trivia, initialColumn, optionSet, formattingRules, root.GetFirstToken(includeZeroWidth: true), root.GetLastToken(includeZeroWidth: true));
     return formatter.FormatAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);
 }
示例#4
0
        public static IFormattingResult Format(
            SyntaxTrivia trivia,
            int initialColumn,
            AnalyzerConfigOptions options,
            ChainedFormattingRules formattingRules,
            CancellationToken cancellationToken)
        {
            var root      = trivia.GetStructure();
            var formatter = new CSharpStructuredTriviaFormatEngine(trivia, initialColumn, options, formattingRules, root.GetFirstToken(includeZeroWidth: true), root.GetLastToken(includeZeroWidth: true));

            return(formatter.Format(cancellationToken));
        }
示例#5
0
        public static IFormattingResult Format(
            SyntaxTrivia trivia,
            int initialColumn,
            OptionSet optionSet,
            ChainedFormattingRules formattingRules,
            CancellationToken cancellationToken)
        {
            var root      = trivia.GetStructure();
            var formatter = new CSharpStructuredTriviaFormatEngine(trivia, initialColumn, optionSet, formattingRules, root.GetFirstToken(includeZeroWidth: true), root.GetLastToken(includeZeroWidth: true));

            return(formatter.FormatAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken));
        }