public FormattingStageData(PsiCodeFormattingSettings formattingSettings, CodeFormattingContext context, PsiFormatProfile profile, List<IPsiCodeFormatterExtension> extensions)
 {
   FormattingSettings = formattingSettings;
   Extensions = extensions;
   Context = context;
   Profile = profile;
 }
 public FormattingStageData(PsiCodeFormattingSettings formattingSettings, CodeFormattingContext context, PsiFormatProfile profile, List <IPsiCodeFormatterExtension> extensions)
 {
     FormattingSettings = formattingSettings;
     Extensions         = extensions;
     Context            = context;
     Profile            = profile;
 }
    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));
    }
示例#4
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));
        }
示例#5
0
        public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, [CanBeNull] IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null)
        {
            var       psiProfile = new PsiFormatProfile(profile);
            ITreeNode firstNode  = firstElement;
            ITreeNode lastNode   = lastElement;

            if (firstElement != lastElement)
            {
                if (firstElement == null)
                {
                    firstNode = lastElement;
                }
                ITreeNode commonParent = firstNode.FindCommonParent(lastNode);
                ITreeNode firstChild   = firstNode;
                ITreeNode lastChild    = lastElement;
                while (firstChild.Parent != commonParent)
                {
                    firstChild = firstChild.Parent;
                }
                while (lastChild.Parent != commonParent)
                {
                    lastChild = lastChild.Parent;
                }

                bool hasPrevSibling = false;
                while (firstNode.NextSibling == null)
                {
                    if (firstNode.PrevSibling != null)
                    {
                        hasPrevSibling = true;
                    }
                    firstNode = firstNode.Parent;
                    if (firstNode == firstChild)
                    {
                        break;
                    }
                }
                if (hasPrevSibling)
                {
                    while ((firstNode == firstChild) || (firstChild.IsWhitespaceToken()))
                    {
                        firstChild = firstChild.NextSibling;
                    }
                }
                firstNode = firstChild;
                while (firstNode.FirstChild != null)
                {
                    firstNode = firstNode.FirstChild;
                }
            }
            else
            {
                if (firstElement.FirstChild != null)
                {
                    firstNode = firstElement.FirstChild;
                    lastNode  = firstElement.LastChild;
                }
            }
            ISolution            solution = firstNode.GetSolution();
            var                  contextBoundSettingsStore = GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode);
            GlobalFormatSettings globalSettings            = GlobalFormatSettingsHelper.GetService(solution).GetSettingsForLanguage(myLanguage);
            //var formatterSettings = new PsiCodeFormattingSettings(globalSettings, contextBoundSettingsStore.GetKey<CommonFormatterSettingsKey>(mySettingsOptimization));
            var formatterSettings = new PsiCodeFormattingSettings(globalSettings);

            using (pi.SafeTotal(4))
            {
                var context = new PsiCodeFormattingContext(this, firstNode, lastNode, NullProgressIndicator.Instance);
                if (psiProfile.Profile != CodeFormatProfile.INDENT)
                {
                    using (pi.CreateSubProgress(1))
                    {
                        //FormatterImplHelper.DecoratingIterateNodes(context, context.FirstNode, context.LastNode, new PsiDecorationStage(formatterSettings, psiProfile, subPi));
                    }

                    using (IProgressIndicator subPi = pi.CreateSubProgress(1))
                    {
                        using (subPi.SafeTotal(2))
                        {
                            var data = new FormattingStageData(formatterSettings, context, psiProfile, myExtensions.ToList());
                            PsiFormattingStage.DoFormat(data, subPi.CreateSubProgress(1));
                            PsiIndentingStage.DoIndent(formatterSettings, context, subPi.CreateSubProgress(1), false);
                        }
                    }
                }
                else
                {
                    using (IProgressIndicator subPi = pi.CreateSubProgress(4))
                    {
                        PsiIndentingStage.DoIndent(formatterSettings, context, subPi, true);
                    }
                }
            }
            return(new TreeRange(firstElement, lastElement));
        }
    public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, [CanBeNull] IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null)
    {
      var psiProfile = new PsiFormatProfile(profile);
      ITreeNode firstNode = firstElement;
      ITreeNode lastNode = lastElement;
      if (firstElement != lastElement)
      {
        if (firstElement == null)
        {
          firstNode = lastElement;
        }
        ITreeNode commonParent = firstNode.FindCommonParent(lastNode);
        ITreeNode firstChild = firstNode;
        ITreeNode lastChild = lastElement;
        while (firstChild.Parent != commonParent)
        {
          firstChild = firstChild.Parent;
        }
        while (lastChild.Parent != commonParent)
        {
          lastChild = lastChild.Parent;
        }

        bool hasPrevSibling = false;
        while (firstNode.NextSibling == null)
        {
          if (firstNode.PrevSibling != null)
          {
            hasPrevSibling = true;
          }
          firstNode = firstNode.Parent;
          if (firstNode == firstChild)
          {
            break;
          }
        }
        if (hasPrevSibling)
        {
          while ((firstNode == firstChild) || (firstChild.IsWhitespaceToken()))
          {
            firstChild = firstChild.NextSibling;
          }
        }
        firstNode = firstChild;
        while (firstNode.FirstChild != null)
        {
          firstNode = firstNode.FirstChild;
        }
      } else
      {
        if (firstElement.FirstChild != null)
        {
          firstNode = firstElement.FirstChild;
          lastNode = firstElement.LastChild;
        }
      }
      ISolution solution = firstNode.GetSolution();
      var contextBoundSettingsStore = GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode);
      GlobalFormatSettings globalSettings = GlobalFormatSettingsHelper.GetService(solution).GetSettingsForLanguage(myLanguage);
      //var formatterSettings = new PsiCodeFormattingSettings(globalSettings, contextBoundSettingsStore.GetKey<CommonFormatterSettingsKey>(mySettingsOptimization));
      var formatterSettings = new PsiCodeFormattingSettings(globalSettings);
      using (pi.SafeTotal(4))
      {
        var context = new PsiCodeFormattingContext(this, firstNode, lastNode, NullProgressIndicator.Instance);
        if (psiProfile.Profile != CodeFormatProfile.INDENT)
        {
          using (pi.CreateSubProgress(1))
          {
            //FormatterImplHelper.DecoratingIterateNodes(context, context.FirstNode, context.LastNode, new PsiDecorationStage(formatterSettings, psiProfile, subPi));
          }

          using (IProgressIndicator subPi = pi.CreateSubProgress(1))
          {
            using (subPi.SafeTotal(2))
            {
              var data = new FormattingStageData(formatterSettings, context, psiProfile, myExtensions.ToList());
              PsiFormattingStage.DoFormat(data, subPi.CreateSubProgress(1));
              PsiIndentingStage.DoIndent(formatterSettings, context, subPi.CreateSubProgress(1), false);
            }
          }
        }
        else
        {
          using (IProgressIndicator subPi = pi.CreateSubProgress(4))
          {
            PsiIndentingStage.DoIndent(formatterSettings, context, subPi, true);
          }
        }
      }
      return new TreeRange(firstElement, lastElement);
    }
 private PsiIndentingStage(PsiCodeFormattingSettings formattingSettings, bool inTypingAssist = false)
 {
   myFormattingSettings = formattingSettings;
   myInTypingAssist = inTypingAssist;
 }
示例#8
0
 private PsiIndentingStage(PsiCodeFormattingSettings formattingSettings, bool inTypingAssist = false)
 {
     myFormattingSettings = formattingSettings;
     myInTypingAssist     = inTypingAssist;
 }