コード例 #1
0
ファイル: CodePreview.cs プロジェクト: studentutu/demystify
        private static string GetText(IReadOnlyList <string> lines, int line, int showLinesAboveAndBelow, out int lineCount)
        {
            if (TypesPatterns == null)
            {
                var patterns = SyntaxHighlighting.GetCodeSyntaxHighlightingPatterns();
                TypesPatterns = string.Join("|", patterns);
                if (DemystifySettings.DevelopmentMode)
                {
                    Debug.Log("Code Preview Patterns: " + TypesPatterns);
                }
            }

            lineCount = 0;
            if (lines == null || lines.Count <= 0)
            {
                return(null);
            }
            showLinesAboveAndBelow = Mathf.Max(0, showLinesAboveAndBelow);
            var from             = Mathf.Max(0, line - showLinesAboveAndBelow);
            var to               = Mathf.Min(lines.Count - 1, line + showLinesAboveAndBelow);
            var str              = string.Empty;
            var lastLineWasEmpty = false;

            for (var index = from; index < to; index++)
            {
                var l     = lines[index];
                var empty = string.IsNullOrWhiteSpace(l);
                if (lastLineWasEmpty && empty)
                {
                    continue;
                }
                lastLineWasEmpty = empty;
                // if (index == line) l = $"<color={HighlightTextColor}><b>{l}</b></color>";
                // else
                {
                    SyntaxHighlighting.AddSyntaxHighlighting(TypesPatterns, SyntaxHighlighting.CurrentTheme, ref l, false);
                    if (index == line)
                    {
                        l = "<b>" + l + "</b>";
                    }
                    // l = $"<color={NormalTextColor}>{l}</color>";
                }
                str       += l + "\n";
                lineCount += 1;
            }

            return(str);
        }
コード例 #2
0
ファイル: UnityDemystify.cs プロジェクト: nasa03/demystify
        public static void Apply(ref string stacktrace)
        {
            try
            {
                var str         = "";
                var lines       = stacktrace.Split('\n');
                var settings    = DemystifySettings.instance;
                var foundPrefix = false;
                foreach (var t in lines)
                {
                    var line = t;

                    if (StacktraceMarkerUtil.IsPrefix(line))
                    {
                        StacktraceMarkerUtil.RemoveMarkers(ref line);
                        if (!string.IsNullOrEmpty(settings.Separator))
                        {
                            str += settings.Separator + "\n";
                        }
                        foundPrefix = true;
                    }

                    if (foundPrefix && settings.UseSyntaxHighlighting)
                    {
                        SyntaxHighlighting.AddSyntaxHighlighting(ref line);
                    }

                    str += line.Trim();

                    if (!str.EndsWith("\n"))
                    {
                        str += "\n";
                    }
                }

                if (!string.IsNullOrWhiteSpace(str))
                {
                    stacktrace = str;
                }
            }
            catch
            // (Exception e)
            {
                // ignore
            }
        }
コード例 #3
0
            // ReSharper disable once UnusedMember.Local
            private static void Postfix(ref string __result)
            {
                if (__result != null && __result.Length <= 0)                // || __result == "Null")
                {
                    __result = string.Empty;
                    var stacktrace = new StackTrace();
                    var frame      = stacktrace.GetFrame(4);
                    var methodName = frame.GetMethod().FullDescription();
                    SyntaxHighlighting.AddSyntaxHighlighting(ref methodName);
                    __result += methodName;
                    // __result += "\n" + frame.GetFileName();
                }

                // for (var i = 0; i < stacktrace.FrameCount; i++)
                // {
                //  __result += i + ": " + stacktrace.GetFrame(i).GetMethod() + "\n";
                // }
            }
コード例 #4
0
        public static void Apply(ref string stacktrace)
        {
            try
            {
                using (new ProfilerMarker("Demystify.Apply").Auto())
                {
                    string[] lines = null;
                    using (new ProfilerMarker("Split Lines").Auto())
                        lines = stacktrace.Split('\n');
                    var settings    = DemystifySettings.instance;
                    var foundPrefix = false;
                    foreach (var t in lines)
                    {
                        var line = t;

                        using (new ProfilerMarker("Remove Markers").Auto())
                        {
                            if (StacktraceMarkerUtil.IsPrefix(line))
                            {
                                StacktraceMarkerUtil.RemoveMarkers(ref line);
                                if (!string.IsNullOrEmpty(settings.Separator))
                                {
                                    builder.AppendLine(settings.Separator);
                                }
                                foundPrefix = true;
                            }
                        }

                        if (foundPrefix && settings.UseSyntaxHighlighting)
                        {
                            SyntaxHighlighting.AddSyntaxHighlighting(ref line);
                        }

                        var l = line.Trim();
                        if (!string.IsNullOrEmpty(l))
                        {
                            if (!l.EndsWith("\n"))
                            {
                                builder.AppendLine(l);
                            }
                            else
                            {
                                builder.Append(l);
                            }
                        }
                    }

                    var res = builder.ToString();
                    if (!string.IsNullOrWhiteSpace(res))
                    {
                        stacktrace = res;
                    }
                    builder.Clear();
                }
            }
            catch
            // (Exception e)
            {
                // ignore
            }
        }