コード例 #1
0
        private SyntaxNode FormatSyntaxNode(SyntaxNode node)
        {
            Workspace customWorkspace = new AdhocWorkspace();
            var       options         = customWorkspace.Options;
            var       formattedResult = Formatter.Format(node, customWorkspace, options);

            return(formattedResult);
        }
コード例 #2
0
 public Task <Document> FormatAsync(Document document, IEnumerable <TextSpan>?spans, OptionSet?options, CancellationToken cancellationToken)
 => Formatter.FormatAsync(document, spans, options, rules: null, cancellationToken: cancellationToken);
コード例 #3
0
        private LineColumn FormatTrivia <T>(Formatter <T> formatter, WhitespaceAppender <T> whitespaceAdder, ArrayBuilder <T> changes, CancellationToken cancellationToken)
        {
            var lineColumn = this.InitialLineColumn;

            var existingWhitespaceDelta  = LineColumnDelta.Default;
            var previousWhitespaceTrivia = default(SyntaxTrivia);
            var previousTrivia           = default(SyntaxTrivia);
            var implicitLineBreak        = false;

            var list = new TriviaList(this.Token1.TrailingTrivia, this.Token2.LeadingTrivia);

            // Holds last position before _ ' Comment so we can reset after processing comment
            var          previousLineColumn = LineColumn.Default;
            SyntaxTrivia trivia;

            for (var i = 0; i < list.Count; i++)
            {
                trivia = list[i];
                if (trivia.RawKind == 0)
                {
                    continue;
                }

                if (IsWhitespaceOrEndOfLine(trivia))
                {
                    existingWhitespaceDelta = existingWhitespaceDelta.With(
                        GetLineColumnOfWhitespace(
                            lineColumn,
                            previousTrivia,
                            previousWhitespaceTrivia,
                            existingWhitespaceDelta,
                            trivia));

                    if (IsEndOfLine(trivia))
                    {
                        implicitLineBreak = false;
                        // If we are on a new line we don't want to continue
                        // reseting indenting this handles the case of a NewLine
                        // followed by whitespace and a comment
                        previousLineColumn = LineColumn.Default;
                    }
                    else if (LineContinuationFollowedByWhitespaceComment(previousTrivia, (i + 1) < list.Count ? list[i + 1] : default))
                    {
                        // we have a comment following an underscore space the formatter
                        // thinks this next line should be shifted to right by
                        // indentation value. Since we know through the test above that
                        // this is the special case of _ ' Comment we don't want the extra indent
                        // so we set the LineColumn value back to where it was before the comment
                        previousLineColumn = lineColumn;
                    }

                    previousWhitespaceTrivia = trivia;
                    continue;
                }

                previousWhitespaceTrivia = default;

                lineColumn = FormatFirstTriviaAndWhitespaceAfter(
                    lineColumn,
                    previousTrivia, existingWhitespaceDelta, trivia,
                    formatter, whitespaceAdder,
                    changes, implicitLineBreak, cancellationToken);

                if (previousLineColumn.Column != 0 &&
                    previousLineColumn.Column < lineColumn.Column &&
                    IsVisualBasicComment(trivia))
                {
                    lineColumn = previousLineColumn;
                    // When we see a NewLine we don't want any special handling
                    // for _ ' Comment
                    previousLineColumn = LineColumn.Default;
                }

                implicitLineBreak       = implicitLineBreak || ContainsImplicitLineBreak(trivia);
                existingWhitespaceDelta = LineColumnDelta.Default;

                previousTrivia = trivia;
            }

            lineColumn = FormatFirstTriviaAndWhitespaceAfter(
                lineColumn,
                previousTrivia, existingWhitespaceDelta, default,
コード例 #4
0
        public Task <Document> FormatAsync(Document document, IEnumerable <TextSpan>?spans, OptionSet options, CancellationToken cancellationToken)
        {
            var formattingOptions = SyntaxFormattingOptions.Create(options, document.Project.Solution.Workspace.Services, document.Project.Language);

            return(Formatter.FormatAsync(document, spans, formattingOptions, rules: null, cancellationToken));
        }