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));
                        }
                    }
                }
            }
        }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
0
        static private Dictionary <string, FormatTask> ParseOutput(string iwyuOutput)
        {
            Dictionary <string, FormatTask> fileTasks = new Dictionary <string, FormatTask>();
            FormatTask currentTask    = null;
            bool       removeCommands = true;

            //- #include <Core/Basics.h>  // lines 3-3

            // Parse what to do.
            var  lines            = Regex.Split(iwyuOutput, "\r\n|\r|\n");
            bool lastLineWasEmpty = false;

            foreach (string line in lines)
            {
                if (line.Length == 0)
                {
                    if (lastLineWasEmpty)
                    {
                        currentTask = null;
                    }

                    lastLineWasEmpty = true;
                    continue;
                }

                int i = line.IndexOf(" should add these lines:");
                if (i < 0)
                {
                    i = line.IndexOf(" should remove these lines:");
                    if (i >= 0)
                    {
                        removeCommands = true;
                    }
                }
                else
                {
                    removeCommands = false;
                }

                if (i >= 0)
                {
                    string file = line.Substring(0, i);

                    if (!fileTasks.TryGetValue(file, out currentTask))
                    {
                        currentTask = new FormatTask();
                        fileTasks.Add(file, currentTask);
                    }
                }
                else if (currentTask != null)
                {
                    if (removeCommands)
                    {
                        var match = RegexRemoveLine.Match(line);
                        if (match.Success)
                        {
                            int removeStart, removeEnd;
                            if (int.TryParse(match.Groups[1].Value, out removeStart) &&
                                int.TryParse(match.Groups[2].Value, out removeEnd))
                            {
                                for (int lineIdx = removeStart; lineIdx <= removeEnd; ++lineIdx)
                                {
                                    currentTask.linesToRemove.Add(lineIdx - 1);
                                }
                            }
                        }
                        else if (lastLineWasEmpty)
                        {
                            currentTask = null;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            currentTask.linesToAdd.Add(line);
                        }
                        else if (lastLineWasEmpty)
                        {
                            currentTask = null;
                        }
                    }
                }

                lastLineWasEmpty = false;
            }

            return(fileTasks);
        }
Пример #5
0
        private Dictionary <string, FormatTask> ParseOutput(string iwyuOutput)
        {
            Dictionary <string, FormatTask> fileTasks = new Dictionary <string, FormatTask>();
            FormatTask currentTask    = null;
            bool       removeCommands = true;

            var removeRegex  = new Regex(@"^-\s+#include\s*[""<](.+)["">]\s+\/\/ lines (\d+)-(\d+)$");
            var addlineRegex = new Regex(@"(#include\s*[""<].+["">])|(^class.+;$)|(^struct.+;$)");
            //- #include <Core/Basics.h>  // lines 3-3

            // Parse what to do.
            var  lines            = Regex.Split(iwyuOutput, "\r\n|\r|\n");
            bool lastLineWasEmpty = false;

            foreach (string line in lines)
            {
                if (line.Length == 0)
                {
                    if (lastLineWasEmpty)
                    {
                        currentTask = null;
                    }

                    lastLineWasEmpty = true;
                    continue;
                }

                int i = line.IndexOf(" should add these lines:");
                if (i < 0)
                {
                    i = line.IndexOf(" should remove these lines:");
                    if (i >= 0)
                    {
                        removeCommands = true;
                    }
                }
                else
                {
                    removeCommands = false;
                }

                if (i >= 0)
                {
                    string file = line.Substring(0, i);

                    if (!fileTasks.TryGetValue(file, out currentTask))
                    {
                        currentTask = new FormatTask();
                        fileTasks.Add(file, currentTask);
                    }
                }
                else if (currentTask != null)
                {
                    if (removeCommands)
                    {
                        var match = removeRegex.Match(line);
                        if (match.Success)
                        {
                            int removeStart, removeEnd;
                            if (int.TryParse(match.Groups[2].Value, out removeStart) &&
                                int.TryParse(match.Groups[3].Value, out removeEnd))
                            {
                                for (int lineIdx = removeStart; lineIdx <= removeEnd; ++lineIdx)
                                {
                                    currentTask.linesToRemove.Add(lineIdx - 1);
                                }
                            }
                        }
                        else if (lastLineWasEmpty)
                        {
                            currentTask = null;
                        }
                    }
                    else
                    {
                        var match = addlineRegex.Match(line);
                        if (match.Success)
                        {
                            currentTask.linesToAdd.Add(line);
                        }
                        else if (lastLineWasEmpty)
                        {
                            currentTask = null;
                        }
                    }
                }

                lastLineWasEmpty = false;
            }

            return(fileTasks);
        }