示例#1
0
        public override ITreeRange Format(
            ITreeNode firstElement,
            ITreeNode lastElement,
            CodeFormatProfile profile,
            IProgressIndicator pi,
            IContextBoundSettingsStore overrideSettingsStore = null)
        {
            ITreeNode firstNode;
            ITreeNode lastNode;

            GetFirstAndLastNode(firstElement, lastElement, out firstNode, out lastNode);

            var contextBoundSettingsStore = this.GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode);

            var globalSettings = GlobalFormatSettingsHelper
                                 .GetService(firstNode.GetSolution())
                                 .GetSettingsForLanguage(this.myLanguage, firstNode.GetProjectFileType(), contextBoundSettingsStore);

            using (pi.SafeTotal(4))
            {
                var context = new PsiCodeFormattingContext(this, firstNode, lastNode);
                if (profile != CodeFormatProfile.INDENT)
                {
                    using (IProgressIndicator subPi = pi.CreateSubProgress(2))
                    {
                        using (subPi.SafeTotal(2))
                        {
                            SecretFormattingStage.DoFormat(context, subPi.CreateSubProgress(1));
                            SecretIndentingStage.DoIndent(context, globalSettings, subPi.CreateSubProgress(1), false);
                        }
                    }
                }
                else
                {
                    using (IProgressIndicator subPi = pi.CreateSubProgress(4))
                    {
                        SecretIndentingStage.DoIndent(context, globalSettings, subPi, true);
                    }
                }
            }
            return(new TreeRange(firstElement, lastElement));
        }
        public static void DoIndent(
            CodeFormattingContext context, GlobalFormatSettings formatSettings, IProgressIndicator progress, bool inTypingAssist)
        {
            var indentCache = new SecretIndentCache(
                context.CodeFormatter, null, AlignmentTabFillStyle.OPTIMAL_FILL, formatSettings);

            ourIndentVisitor = CreateIndentVisitor(indentCache, inTypingAssist);
            var stage = new SecretIndentingStage(inTypingAssist);
            List<FormattingRange> nodePairs =
                context.SequentialEnumNodes().Where(p => context.CanModifyInsideNodeRange(p.First, p.Last)).ToList();
            //List<FormattingRange> nodePairs = GetNodePairs(context).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));
        }
        public static void DoIndent(
            CodeFormattingContext context, GlobalFormatSettings formatSettings, IProgressIndicator progress, bool inTypingAssist)
        {
            var indentCache = new SecretIndentCache(
                context.CodeFormatter, null, AlignmentTabFillStyle.OPTIMAL_FILL, formatSettings);

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