Пример #1
0
            private string GetSingleIdentation()
            {
                // Insert a newline after the open token of the list.  Then ask the
                // ISynchronousIndentationService where it thinks that the next line should be
                // indented.
                var openToken = _listSyntax.GetFirstToken();

                var newSourceText = OriginalSourceText.WithChanges(new TextChange(new TextSpan(openToken.Span.End, 0), NewLine));

                newSourceText = newSourceText.WithChanges(
                    new TextChange(TextSpan.FromBounds(openToken.Span.End + NewLine.Length, newSourceText.Length), ""));
                var newDocument = OriginalDocument.WithText(newSourceText);

                var originalLineNumber = newSourceText.Lines.GetLineFromPosition(openToken.Span.Start).LineNumber;
                var desiredIndentation = _indentationService.GetBlankLineIndentation(
                    newDocument, originalLineNumber + 1,
                    FormattingOptions.IndentStyle.Smart,
                    CancellationToken);

                var baseLine         = newSourceText.Lines.GetLineFromPosition(desiredIndentation.BasePosition);
                var baseOffsetInLine = desiredIndentation.BasePosition - baseLine.Start;

                var indent = baseOffsetInLine + desiredIndentation.Offset;

                var indentString = indent.CreateIndentationString(UseTabs, TabSize);

                return(indentString);
            }
Пример #2
0
            public CallExpressionCodeActionComputer(
                AbstractChainedExpressionWrapper <TNameSyntax, TBaseArgumentListSyntax> service,
                Document document,
                SourceText originalSourceText,
                DocumentOptionSet options,
                ImmutableArray <ImmutableArray <SyntaxNodeOrToken> > chunks,
                CancellationToken cancellationToken)
                : base(service, document, originalSourceText, options, cancellationToken)
            {
                _chunks = chunks;

                var generator = SyntaxGenerator.GetGenerator(document);

                // Both [0][0] indices are safe here.  We can only get here if we had more than
                // two chunks to wrap.  And each chunk is required to have at least three elements
                // (i.e. <c>. name (arglist)</c>).
                var firstPeriod = chunks[0][0];

                _firstPeriodIndentationTrivia = new SyntaxTriviaList(generator.Whitespace(
                                                                         OriginalSourceText.GetOffset(firstPeriod.SpanStart).CreateIndentationString(UseTabs, TabSize)));

                _smartIndentTrivia = new SyntaxTriviaList(generator.Whitespace(
                                                              GetSmartIndentationAfter(firstPeriod)));

                _newlineBeforeOperatorTrivia = service.GetNewLineBeforeOperatorTrivia(NewLineTrivia);
            }
            public BinaryExpressionCodeActionComputer(
                AbstractBinaryExpressionWrapper <TBinaryExpressionSyntax> service,
                Document document,
                SourceText originalSourceText,
                DocumentOptionSet options,
                TBinaryExpressionSyntax binaryExpression,
                ImmutableArray <SyntaxNodeOrToken> exprsAndOperators,
                CancellationToken cancellationToken
                ) : base(service, document, originalSourceText, options, cancellationToken)
            {
                _exprsAndOperators = exprsAndOperators;
                _preference        = options.GetOption(CodeStyleOptions2.OperatorPlacementWhenWrapping);

                var generator = SyntaxGenerator.GetGenerator(document);

                _newlineBeforeOperatorTrivia = service.GetNewLineBeforeOperatorTrivia(
                    NewLineTrivia
                    );

                _indentAndAlignTrivia = new SyntaxTriviaList(
                    generator.Whitespace(
                        OriginalSourceText
                        .GetOffset(binaryExpression.Span.Start)
                        .CreateIndentationString(UseTabs, TabSize)
                        )
                    );

                _smartIndentTrivia = new SyntaxTriviaList(
                    generator.Whitespace(GetSmartIndentationAfter(_exprsAndOperators[1]))
                    );
            }
            private string GetAfterOpenTokenIdentation()
            {
                var openToken            = _listSyntax.GetFirstToken();
                var afterOpenTokenOffset = OriginalSourceText.GetOffset(openToken.Span.End);

                var indentString = afterOpenTokenOffset.CreateIndentationString(UseTabs, TabSize);

                return(indentString);
            }