private void ReplaceSpaces(ITreeNode leftNode, ITreeNode rightNode, IEnumerable <string> wsTexts) { if (wsTexts == null) { return; } FormatterImplHelper.ReplaceSpaces(leftNode, rightNode, CreateWhitespaces(wsTexts)); }
public static void ReplaceSpaces(ITreeNode leftNode, ITreeNode rightNode, IEnumerable <string> wsTexts) { if (wsTexts == null) { return; } FormatterImplHelper.ReplaceSpaces(leftNode, rightNode, wsTexts.CreateWhitespaces().Cast <ITreeNode>().ToArray()); }
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 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) { if (ShaderLabDoNotFormatInjectionsCookie.IsInjectionFormatterSuppressed) { return; } using (new SuspendInjectRegenerationCookie()) { FormatterImplHelper.RunFormatterForGeneratedLanguages(file, formatTask.FirstElement, lastNode, profile, it => true, PsiLanguageCategories.All, parameters.ChangeProgressIndicator(fmtProgress)); } } } } }
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)); }
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)); }
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)); }
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)); }
protected override ITreeNode[] CreateSpace(string indent) { return(new[] { TreeElementFactory.CreateLeafElement(JavaScriptTokenType.WHITE_SPACE, FormatterImplHelper.GetPooledWhitespace(indent), 0, indent.Length) }); }
public static IWhitespaceNode CreateSpace(string spaceText) { return((IWhitespaceNode)TreeElementFactory.CreateLeafElement(JavaScriptTokenType.WHITE_SPACE, FormatterImplHelper.GetPooledWhitespace(spaceText), 0, spaceText.Length)); }
public override ITreeRange FormatInsertedRange(ITreeNode nodeFirst, ITreeNode nodeLast, ITreeRange origin) => FormatterImplHelper.FormatInsertedRangeHelper(this, nodeFirst, nodeLast, origin, true);
public override void FormatInsertedNodes(ITreeNode nodeFirst, ITreeNode nodeLast, bool formatSurround) => FormatterImplHelper.FormatInsertedNodesHelper(this, nodeFirst, nodeLast, formatSurround);
public override void FormatDeletedNodes(ITreeNode parent, ITreeNode prevNode, ITreeNode nextNode) => FormatterImplHelper.FormatDeletedNodesHelper(this, parent, prevNode, nextNode, parent is PrimaryConstructorDeclaration);
public override void FormatReplacedRange(ITreeNode first, ITreeNode last, ITreeRange oldNodes) { FormatInsertedNodes(first, last, false); FormatterImplHelper.CheckForMinimumSeparator(this, first, last); }
public override void FormatReplacedNode(ITreeNode oldNode, ITreeNode newNode) { FormatInsertedNodes(newNode, newNode, true); FormatterImplHelper.CheckForMinimumSeparator(this, newNode); }
public override void FormatDeletedNodes(ITreeNode parent, ITreeNode prevNode, ITreeNode nextNode) => FormatterImplHelper.FormatDeletedNodesHelper(this, parent, prevNode, nextNode, false);