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; }
private static IEnumerable<FormattingRange> GetNodePairs(CodeFormattingContext context) { ITreeNode firstNode = context.FirstNode; ITreeNode lastNode = context.LastNode; IList<FormattingRange> list = new List<FormattingRange>(); GetNodePairs(firstNode, lastNode, list); return list; }
public static IEnumerable <FormattingRange> GetNodePairs(this CodeFormattingContext context) { ITreeNode firstNode = context.FirstNode; ITreeNode lastNode = context.LastNode; IList <FormattingRange> list = new List <FormattingRange>(); GetNodePairs(firstNode, lastNode, list); return(list); }
public SecretFormattingVisitor(CodeFormattingContext context) { ITreeNode node = context.FirstNode; IPsiSourceFile projectFile = node.GetSourceFile(); if (projectFile != null) { this.myIsGenerated = !Equals(projectFile.PrimaryPsiLanguage, node.Language); } }
public IOptionNode GetOptionTree(ITreeNode node, CodeFormattingContext context) { Assertion.Assert(node is CppFile, "node is CppFile"); var cgProgram = (node.Parent as IInjectedFileHolder)?.OriginalNode.PrevSibling; var s = GetIndentInCgProgram(cgProgram); return(new ConstantOptionNode( new IndentOptionValue(IndentType.AfterFirstToken | IndentType.AbsoluteIndent | IndentType.NonAdjustable, 0, s))); }
private static SecretFormattingVisitor CreateFormattingVisitor(CodeFormattingContext context) { IPsiSourceFile sourceFile = context.FirstNode.GetSourceFile(); if (sourceFile != null) { var projectFileTypeServices = Shell.Instance.GetComponent<IProjectFileTypeServices>(); var factory = projectFileTypeServices.TryGetService<ISecretCodeFormatterFactory>(sourceFile.LanguageType); if (factory != null) { return factory.CreateFormattingVisitor(context); } } return new SecretFormattingVisitor(context); }
public static void DoFormat(CodeFormattingContext context, IProgressIndicator pi) { if (context.FirstNode == context.LastNode) { return; } var stage = new SecretFormattingStage(context); IEnumerable<FormattingRange> nodePairs = GetNodePairs(context); 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)); }
private static PsiFormattingVisitor CreateFormattingVisitor(CodeFormattingContext context) { IPsiSourceFile sourceFile = context.LastNode.GetSourceFile(); if (sourceFile != null) { var projectFileTypeServices = Shell.Instance.GetComponent <IProjectFileTypeServices>(); var factory = projectFileTypeServices.TryGetService <IPsiCodeFormatterFactory>(sourceFile.LanguageType); if (factory != null) { return(factory.CreateFormattingVisitor(context)); } } return(new PsiFormattingVisitor(context)); }
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( 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(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)); }
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)); }
public bool MatchesPatterns(ITreeNode node, CodeFormattingContext context) { return(myNodePattern.Matches(node, context)); }
public ITreeNode GetClosingNode(ITreeNode node, CodeFormattingContext checker) { return(node); }
public SecretFormattingVisitor CreateFormattingVisitor(CodeFormattingContext context) { return new SecretFormattingVisitor(context); }
public JavaScriptFormattingStageResearch(CodeFormattingContext context, JavaScriptResearchFormatter javaScriptResearchFormatter) : base(javaScriptResearchFormatter) { myContext = context; }
public PsiFormattingVisitor CreateFormattingVisitor(CodeFormattingContext context) { return(new PsiFormattingVisitor(context)); }
private PsiFormattingStage(FormattingStageData data) { myContext = data.Context; myFmtVisitor = CreateFormattingVisitor(data); }
private PsiFormattingStage(CodeFormattingContext context) { myFmtVisitor = CreateFormattingVisitor(context); }
private SecretFormattingStage(CodeFormattingContext context) { this.myFmtVisitor = CreateFormattingVisitor(context); }
private IList <IndentRange> BuildRanges(CodeFormattingContext context) { var parent = context.FirstNode.FindCommonParent(context.LastNode); return(BuildRanges(parent)); }
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)); }
protected override FormattingStageResearchBase FormattingStage(CodeFormattingContext context) { return(new JavaScriptFormattingStageResearch(context, this)); }
public SecretFormattingVisitor CreateFormattingVisitor(CodeFormattingContext context) { return(new SecretFormattingVisitor(context)); }
protected abstract FormattingStageResearchBase FormattingStage(CodeFormattingContext context);