public void DoFormat(IProgressIndicator pi)
        {
            if (Context.FirstNode == Context.LastNode)
            {
                return;
            }

            var nodePairs = Context.HierarchicalEnumNodes().Where(p => Context.CanModifyInsideNodeRange(p.First, p.Last)).ToList();
            //var nodePairs = Context.HierarchicalEnumNodes().ToList();

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

            FormatterImplHelper.ForeachResult(spaces, pi, res => MakeFormat(res.Range, res.ResultValue));
        }
        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));
        }
Esempio n. 3
0
        public void DoIndent(CodeFormattingContext context, IProgressIndicator progress, bool indent = false)
        {
            var indentRanges = BuildRanges(context);
            var nodePairs    = context.SequentialEnumNodes().Where(p => context.CanModifyInsideNodeRange(p.First, p.Last)).Where(p => HasLineFeedsTo(p.First, p.Last)).ToList();
            var parent       = context.FirstNode.FindCommonParent(context.LastNode);

            CollectNewLines(indentRanges);
            CalcIndents(indentRanges, GetIndent(parent));
            var indents = nodePairs.
                          Select(range => new FormatResult <string>(range, CalcIndent(new FormattingStageContext(range), indentRanges, indent))).
                          Where(res => res.ResultValue != null);

            FormatterImplHelper.ForeachResult(
                indents,
                progress,
                res => MakeIndent(res.Range.Last, res.ResultValue));
        }
Esempio n. 4
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));
        }
Esempio n. 5
0
        public static void DoIndent(PsiCodeFormattingSettings formattingSettings, CodeFormattingContext context, IProgressIndicator progress, bool inTypingAssist)
        {
            /*PsiIndentCache indentCache = new PsiIndentCache(
             * context.CodeFormatter,
             * null,
             * formattingSettings.CommonSettings.ALIGNMENT_TAB_FILL_STYLE,
             * formattingSettings.GlobalSettings); */
            PsiIndentCache indentCache = new PsiIndentCache();

            myIndentVisitor = CreateIndentVisitor(indentCache, inTypingAssist);
            var stage = new PsiIndentingStage(formattingSettings, inTypingAssist);
            List <FormattingRange> nodePairs             = context.SequentialEnumNodes().Where(p => context.CanModifyInsideNodeRange(p.First, p.Last)).ToList();
            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));
        }