public static void DoFormat(CodeFormattingContext context, IProgressIndicator pi)
        {
            if (context.FirstNode == context.LastNode)
            {
                return;
            }

            var stage = new PsiFormattingStage(context);

            IEnumerable <FormattingRange> nodePairs = context.GetNodePairs();

            IEnumerable <FormatResult <IEnumerable <string> > > spaces = nodePairs.Select(
                range => new FormatResult <IEnumerable <string> >(range, stage.CalcSpaces(new FormattingStageContext(range))));

            FormatterImplHelper.ForeachResult(spaces, pi, res => stage.MakeFormat(res.Range, res.ResultValue));
        }
Beispiel #2
0
        public static void DoIndent(CodeFormattingContext context, IProgressIndicator progress, bool inTypingAssist)
        {
            var indentCache = new PsiIndentCache(context.CodeFormatter,
                                                 AlignmentTabFillStyle.USE_SPACES, new GlobalFormatSettings(true, 2));

            _indentVisitor = CreateIndentVisitor(indentCache, inTypingAssist);
            var stage = new PsiIndentingStage(inTypingAssist);
            //List<FormattingRange> nodePairs = context.SequentialEnumNodes().Where(p => context.CanModifyInsideNodeRange(p.First, p.Last)).ToList();
            List <FormattingRange> nodePairs = context.GetNodePairs().Where(p => context.CanModifyInsideNodeRange(p.First, p.Last)).ToList();
            //nodePairs.Add(new FormattingRange(null, context.FirstNode));
            IEnumerable <FormatResult <string> > indents = nodePairs.
                                                           Select(range => new FormatResult <string>(range, stage.CalcIndent(new FormattingStageContext(range)))).
                                                           Where(res => res.ResultValue != null);

            FormatterImplHelper.ForeachResult(
                indents,
                progress,
                res => res.Range.Last.MakeIndent(res.ResultValue));
        }