Skip to content

Commit

Permalink
Add instance hash to debugger window
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavopsantos committed Aug 29, 2024
1 parent d3a1afe commit 329cf4d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void CellGUI(Rect cellRect, TreeViewItem<MyTreeElement> item, Column col
private void DrawName(TreeViewItem item, Rect area, string name)
{
area.xMin += GetContentIndent(item);
GUI.Label(area, name);
GUI.Label(area, name, Styles.RichTextLabel);
}

private void DrawContracts(TreeViewItem<MyTreeElement> item, Rect rect, string[] contracts)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Reflex/Editor/DebuggingWindow/ReflexDebuggerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ private void BuildDataRecursively(MyTreeElement parent, Container container)
pair.Item2.Select(x => x.GetName()).OrderBy(x => x).ToArray(),
pair.Item1.Lifetime.ToString(),
pair.Item1.GetDebugProperties().BindingCallsite,
kind: pair.Item1.GetType().Name.Replace("Singleton", string.Empty).Replace("Transient", string.Empty).Replace("Resolver", string.Empty)
kind: pair.Item1.GetType().Name.Replace("Singleton", string.Empty).Replace("Transient", string.Empty).Replace("Scoped", string.Empty).Replace("Resolver", string.Empty)
);

foreach (var (instance, callsite) in pair.Item1.GetDebugProperties().Instances)
{
var instanceTreeElement = new MyTreeElement(
instance.GetType().GetName(),
$"{instance.GetType().GetName()} <b><color=#3D99ED>({SHA1.ShortHash(instance.GetHashCode())})</color></b>",
resolverTreeElement.Depth + 1,
++_id,
InstanceIcon,
Expand Down
32 changes: 32 additions & 0 deletions Assets/Reflex/Editor/DebuggingWindow/SHA1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Security.Cryptography;
using System.Text;

namespace Reflex.Editor.DebuggingWindow
{
internal static class SHA1
{
public static string Hash(object obj)
{
var input = obj.ToString();

using (var sha1 = new SHA1Managed())
{
var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(input));
var sb = new StringBuilder(hash.Length * 2);

foreach (var b in hash)
{
sb.Append(b.ToString("x2"));
}

return sb.ToString();
}
}

public static string ShortHash(object obj)
{
var hash = Hash(obj);
return hash.Substring(0, 7);
}
}
}
3 changes: 3 additions & 0 deletions Assets/Reflex/Editor/DebuggingWindow/SHA1.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Assets/Reflex/Editor/DebuggingWindow/Styles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ namespace Reflex.Editor.DebuggingWindow
{
public static class Styles
{
private static GUIStyle _richTextLabel;
public static GUIStyle RichTextLabel
{
get
{
if (_richTextLabel == null)
{
_richTextLabel = new GUIStyle(EditorStyles.label)
{
richText = true
};
}

return _richTextLabel;
}
}

private static GUIStyle _stackTrace;
public static GUIStyle StackTrace
{
Expand Down

0 comments on commit 329cf4d

Please sign in to comment.