예제 #1
0
 public override ITreeRange Format(
     ITreeNode firstElement,
     ITreeNode lastElement,
     CodeFormatProfile profile,
     AdditionalFormatterParameters parameters = null
     )
 => new TreeRange(firstElement, lastElement);
예제 #2
0
 protected override CodeFormattingContext CreateFormatterContext(
     CodeFormatProfile profile,
     ITreeNode firstNode,
     ITreeNode lastNode,
     AdditionalFormatterParameters parameters,
     ICustomFormatterInfoProvider provider
     ) => new CodeFormattingContext(this, firstNode, lastNode, profile, FormatterLoggerProvider.FormatterLogger, parameters);
        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);

            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))
                        {
                            PsiFormattingStage.DoFormat(context, subPi.CreateSubProgress(1));
                            PsiIndentingStage.DoIndent(context, subPi.CreateSubProgress(1), false);
                        }
                    }
                }
                else
                {
                    using (IProgressIndicator subPi = pi.CreateSubProgress(4))
                    {
                        PsiIndentingStage.DoIndent(context, subPi, true);
                    }
                }
            }
            return(new TreeRange(firstElement, lastElement));
        }
예제 #4
0
		public override ITreeRange Format(
			ITreeNode firstElement,
			ITreeNode lastElement,
			CodeFormatProfile profile,
			IProgressIndicator progressIndicator,
			IContextBoundSettingsStore overrideSettingsStore = null,
			IPotentSettingsTracker settingsTracker = null)
			=> new TreeRange(firstElement, lastElement);
예제 #5
0
 public override ITreeRange Format(
     ITreeNode firstElement,
     ITreeNode lastElement,
     CodeFormatProfile profile,
     IProgressIndicator progressIndicator,
     IContextBoundSettingsStore overrideSettingsStore = null,
     IPotentSettingsTracker settingsTracker           = null)
 => new TreeRange(firstElement, lastElement);
예제 #6
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 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);
        }
예제 #8
0
 /// <summary>
 /// Format the given subtree
 /// </summary>
 public override void Format(ITreeNode root, CodeFormatProfile profile, IProgressIndicator progressIndicator, IContextBoundSettingsStore overrideSettingsStore = null)
 {
     base.Format(root, profile, progressIndicator, overrideSettingsStore);
 }
예제 #9
0
 protected override bool IsFormatNextSpaces(CodeFormatProfile profile)
 {
     return(profile != CodeFormatProfile.INDENT);
 }
예제 #10
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));
        }
예제 #11
0
        public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile,
                                          AdditionalFormatterParameters parameters = null)
        {
            parameters = parameters ?? AdditionalFormatterParameters.Empty;
            var       pointer  = FormatterImplHelper.CreateRangePointer(firstElement, lastElement);
            ITreeNode lastNode = lastElement;

            var task = new FormatTask(firstElement, lastNode, profile);

            task.Adjust(this);
            if (task.FirstElement == null)
            {
                return(new TreeRange(firstElement, lastElement));
            }

            //ASSERT(!IsWhitespaceToken(lastNode), "Whitespace node on the right side of the range");

            var settings = GetFormattingSettings(task.FirstElement, parameters, myShaderLabFormattingInfo);

            settings.Settings.SetValue((key => key.WRAP_LINES), false);

            DoDeclarativeFormat(settings, myShaderLabFormattingInfo, null, new[] { task }, parameters,
                                _ => false, null, FormatChildren, false);

            return(FormatterImplHelper.PointerToRange(pointer, firstElement, lastElement));

            void FormatChildren(FormatTask formatTask, FmtSettings <ShaderLabFormatSettingsKey> formatSettings, CodeFormattingContext context)
            {
                using (var fmtProgress = parameters.ProgressIndicator.CreateSubProgress(1))
                {
                    Assertion.Assert(formatTask.FirstElement != null, "firstNode != null");
                    var file = formatTask.FirstElement.GetContainingFile();
                    if (file != null)
                    {
                        using (new SuspendInjectRegenerationCookie())
                        {
                            FormatterImplHelper.RunFormatterForGeneratedLanguages(file, formatTask.FirstElement, lastNode, profile,
                                                                                  it => true, PsiLanguageCategories.All, parameters.ChangeProgressIndicator(fmtProgress));
                        }
                    }
                }
            }
        }
예제 #12
0
        public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile,
                                          AdditionalFormatterParameters parameters = null)
        {
            parameters ??= AdditionalFormatterParameters.Empty;
            var task = new FormatTask(firstElement, lastElement, profile);

            task.Adjust(this);
            if (task.FirstElement == null)
            {
                return(new TreeRange(firstElement, lastElement));
            }

            if (!firstElement.FSharpFormatterEnabled())
            {
                return(new TreeRange(firstElement, lastElement));
            }

            var formatterSettings = GetFormattingSettings(task.FirstElement, parameters, myFormatterInfoProvider);

            DoDeclarativeFormat(formatterSettings, myFormatterInfoProvider, null, new[] { task },
                                parameters, null, null, null, false);

            return(new TreeRange(firstElement, lastElement));
        }
예제 #13
0
		protected override bool IsFormatNextSpaces(CodeFormatProfile profile)
			=> false;
예제 #14
0
 protected override bool IsFormatNextSpaces(CodeFormatProfile profile)
 {
     return(false);
 }
예제 #15
0
 /// <summary>
 /// Format the given subtree
 /// </summary>
 public override void Format(ITreeNode root, CodeFormatProfile profile, IProgressIndicator progressIndicator, IContextBoundSettingsStore overrideSettingsStore = null)
 {
     base.Format(root, profile, progressIndicator, overrideSettingsStore);
 }
예제 #16
0
 protected override bool IsFormatNextSpaces(CodeFormatProfile profile)
 => false;
예제 #17
0
 protected override CodeFormattingContext CreateFormatterContext(CodeFormatProfile profile, ITreeNode firstNode, ITreeNode lastNode, AdditionalFormatterParameters parameters, ICustomFormatterInfoProvider provider, int stageNumber)
 {
     throw new System.NotImplementedException();
 }
예제 #18
0
 /// <summary>
 /// Format the given range in document
 /// </summary>
 public override void Format(ISolution solution, DocumentRange docRange, CodeFormatProfile profile, bool formatSpacesBefore, bool formatSpacesAfter,
     IProgressIndicator progressIndicator, IContextBoundSettingsStore overrideSettingsStore = null)
 {
     base.Format(solution, docRange, profile, formatSpacesBefore, formatSpacesAfter, progressIndicator, overrideSettingsStore);
 }
 protected override bool IsFormatNextSpaces(CodeFormatProfile profile)
 {
     throw new NotImplementedException();
 }
예제 #20
0
        public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, AdditionalFormatterParameters parameters = null)
        {
            parameters ??= AdditionalFormatterParameters.Empty;

            var task = new FormatTask(firstElement, lastElement, profile);

            task.Adjust(this);

            if (task.FirstElement == null)
            {
                return(new TreeRange(firstElement, lastElement));
            }

            var formatterSettings = GetFormattingSettings(task.FirstElement, parameters, _formatterInfoProvider);

            formatterSettings.Settings.SetValue(key => key.WRAP_LINES, false);

            DoDeclarativeFormat(formatterSettings, _formatterInfoProvider, null, new[] { task },
                                parameters, (settings => true), null, null, false);

            return(new TreeRange(firstElement, lastElement));
        }
예제 #21
0
        public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null)
        {
            var firstNode = firstElement;
            var lastNode  = lastElement;

            Assertion.Assert(firstNode != null || lastNode != null, "The condition (firstNode != null || lastNode != null) is false.");

            // if first node is null, then start from the file beginning
            if (firstNode == null)
            {
                firstNode = lastNode.PathToRoot().Last();
                foreach (var child in firstNode.FirstDescendants())
                {
                    if (firstNode == lastNode)
                    {
                        return(new TreeRange(firstElement, lastElement));
                    }
                    firstNode = child;
                }
            }

            var token = (firstNode as ITokenNode).SkipLeftWhitespaces();

            if (token != null)
            {
                firstNode = token;
            }

            //var solution = firstNode.GetSolution();
            //var globalSettings = GlobalFormatSettingsHelper.GetService(solution).GetSettingsForLanguage(LanguageType);
            //var contextBoundSettingsStore = GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode);
            //var formatterSettings = new JavaScriptCodeFormattingSettings(contextBoundSettingsStore, mySettingsOptimization, globalSettings);

            using (firstNode.CreateWriteLock())
                using (pi.SafeTotal(4))
                {
                    var context = new CodeFormattingContext(this, firstNode, lastNode, NullProgressIndicator.Instance);
                    if (profile != CodeFormatProfile.INDENT)
                    {
                        /*using (var subPi = pi.CreateSubProgress(1))
                         * {
                         * //FormatterImplHelper.DecoratingIterateNodes(context, context.FirstNode, context.LastNode, new JavaScriptDecorationStage(formatterSettings, profile, subPi));
                         * }*/

                        using (var subPi = pi.CreateSubProgress(1))
                        {
                            using (subPi.SafeTotal(2))
                            {
                                FormattingStage(context).DoFormat(subPi.CreateSubProgress(1));
                                IndentingStage().DoIndent(context, subPi.CreateSubProgress(1));
                            }
                        }
                    }
                    else
                    {
                        using (var subPi = pi.CreateSubProgress(4))
                        {
                            IndentingStage().DoIndent(context, subPi, true);
                        }
                    }
                }
            return(new TreeRange(firstElement, lastElement));
        }
예제 #22
0
 public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, IProgressIndicator progressIndicator, IContextBoundSettingsStore overrideSettingsStore = null)
 {
     return new TreeRange(firstElement, lastElement);
 }
예제 #23
0
 /// <summary>
 /// Format the given range in document
 /// </summary>
 public override void Format(ISolution solution, DocumentRange docRange, CodeFormatProfile profile, bool formatSpacesBefore, bool formatSpacesAfter,
                             IProgressIndicator progressIndicator, IContextBoundSettingsStore overrideSettingsStore = null)
 {
     base.Format(solution, docRange, profile, formatSpacesBefore, formatSpacesAfter, progressIndicator, overrideSettingsStore);
 }
 public PsiFormatProfile(CodeFormatProfile profile)
 {
     Profile = profile;
 }
예제 #25
0
 public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, IProgressIndicator progressIndicator, IContextBoundSettingsStore overrideSettingsStore = null)
 {
     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);
    }
 public PsiFormatProfile(CodeFormatProfile profile)
 {
   Profile = profile;
 }
 protected override bool IsFormatNextSpaces(CodeFormatProfile profile)
 {
   return profile != CodeFormatProfile.INDENT;
 }