コード例 #1
0
        private static string GetReplacementText(
            ITextView textView,
            DocumentOptionSet options,
            ITextSnapshotLine triviaLine,
            SyntaxTrivia trivia,
            int position
            )
        {
            // We're inside a comment.  Instead of inserting just a newline here, insert
            // 1. a newline
            // 2. spaces up to the indentation of the current comment
            // 3. the comment prefix (extended out for repeated chars).

            // Then, depending on if the current comment starts with whitespace or not, we will insert those same spaces
            // to match.

            var commentStartColumn = triviaLine.GetColumnFromLineOffset(
                trivia.SpanStart - triviaLine.Start,
                textView.Options
                );

            var useTabs = options.GetOption(FormattingOptions.UseTabs);
            var tabSize = options.GetOption(FormattingOptions.TabSize);

            var prefix          = GetCommentPrefix(triviaLine.Snapshot, trivia, position);
            var replacementText =
                options.GetOption(FormattingOptions.NewLine)
                + commentStartColumn.CreateIndentationString(useTabs, tabSize)
                + prefix
                + GetWhitespaceAfterCommentPrefix(trivia, triviaLine, prefix, position);

            return(replacementText);
        }