From e031bdfc42b44e4b864c7ecc879dc07c3ab4588b Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sat, 11 Oct 2025 16:10:15 +1000 Subject: [PATCH] Method attributes --- .../CodeEditor/SymbolInfoComponents.cs | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SymbolInfoComponents.cs b/src/SharpIDE.Godot/Features/CodeEditor/SymbolInfoComponents.cs index fb17225..206555f 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/SymbolInfoComponents.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/SymbolInfoComponents.cs @@ -17,10 +17,8 @@ public static class SymbolInfoComponents label.SetAnchorsPreset(Control.LayoutPreset.FullRect); label.PushColor(CachedColors.White); label.PushFont(MonospaceFont); - label.PushColor(CachedColors.KeywordBlue); - // TODO: Attributes - label.AddText(methodSymbol.DeclaredAccessibility.GetAccessibilityString()); - label.Pop(); + label.AddMethodAttributes(methodSymbol); + label.AddAccessibilityModifier(methodSymbol); label.AddText(" "); label.AddStaticModifier(methodSymbol); label.AddVirtualModifier(methodSymbol); @@ -54,6 +52,13 @@ public static class SymbolInfoComponents Accessibility.ProtectedAndInternal => "private protected", _ => "unknown" }; + + private static void AddAccessibilityModifier(this RichTextLabel label, IMethodSymbol methodSymbol) + { + label.PushColor(CachedColors.KeywordBlue); + label.AddText(methodSymbol.DeclaredAccessibility.GetAccessibilityString()); + label.Pop(); + } private static void AddStaticModifier(this RichTextLabel label, IMethodSymbol methodSymbol) { @@ -99,6 +104,16 @@ public static class SymbolInfoComponents } } + private static void AddMethodAttributes(this RichTextLabel label, IMethodSymbol methodSymbol) + { + var attributes = methodSymbol.GetAttributes(); + if (attributes.Length is 0) return; + foreach (var (index, attribute) in attributes.Index()) + { + label.AddAttribute(attribute, true); + } + } + private static void AddMethodReturnType(this RichTextLabel label, IMethodSymbol methodSymbol) { if (methodSymbol.ReturnsVoid) @@ -160,14 +175,7 @@ public static class SymbolInfoComponents { foreach (var (attrIndex, attribute) in attributes.Index()) { - label.AddText("["); - label.PushColor(CachedColors.ClassGreen); - var displayString = attribute.AttributeClass?.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); - if (displayString?.EndsWith("Attribute") is true) displayString = displayString[..^9]; // remove last 9 chars - label.AddText(displayString ?? "unknown"); - label.Pop(); - label.AddText("]"); - label.AddText(" "); + label.AddAttribute(attribute, false); } } if (parameterSymbol.RefKind != RefKind.None) // ref, in, out @@ -296,6 +304,19 @@ public static class SymbolInfoComponents } } } + + private static void AddAttribute(this RichTextLabel label, AttributeData attribute, bool newLines) + { + label.AddText("["); + label.PushColor(CachedColors.ClassGreen); + var displayString = attribute.AttributeClass?.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); + if (displayString?.EndsWith("Attribute") is true) displayString = displayString[..^9]; // remove last 9 chars + label.AddText(displayString ?? "unknown"); + label.Pop(); + label.AddText("]"); + if (newLines) label.Newline(); + else label.AddText(" "); + } // TODO: parse these types better? private static (string, Color) GetForMetadataName(string metadataName)