add property tooltip

This commit is contained in:
Matt Parker
2025-10-12 11:08:41 +10:00
parent b1da3b05fa
commit 2e8fc663fe
4 changed files with 111 additions and 4 deletions

View File

@@ -31,7 +31,7 @@ public static partial class SymbolInfoComponents
return label;
}
private static void AddStaticModifier(this RichTextLabel label, IFieldSymbol symbol)
private static void AddStaticModifier(this RichTextLabel label, ISymbol symbol)
{
if (symbol.IsStatic)
{

View File

@@ -0,0 +1,107 @@
using Godot;
using Microsoft.CodeAnalysis;
namespace SharpIDE.Godot.Features.CodeEditor;
public partial class SymbolInfoComponents
{
public static Control GetPropertySymbolInfo(IPropertySymbol symbol)
{
var label = new RichTextLabel();
label.FitContent = true;
label.AutowrapMode = TextServer.AutowrapMode.Off;
label.SetAnchorsPreset(Control.LayoutPreset.FullRect);
label.PushColor(CachedColors.White);
label.PushFont(MonospaceFont);
label.AddAttributes(symbol);
label.AddAccessibilityModifier(symbol);
label.AddText(" ");
label.AddStaticModifier(symbol);
label.AddReadonlyModifier(symbol);
label.AddVirtualModifier(symbol);
label.AddAbstractModifier(symbol);
label.AddOverrideModifier(symbol);
label.AddPropertyTypeName(symbol);
label.AddPropertyName(symbol);
label.AddGetSetAccessors(symbol);
label.AddContainingNamespaceAndClass(symbol);
label.Pop();
label.Pop();
return label;
}
private static void AddReadonlyModifier(this RichTextLabel label, IPropertySymbol symbol)
{
if (symbol.IsReadOnly)
{
label.PushColor(CachedColors.KeywordBlue);
label.AddText("readonly");
label.Pop();
label.AddText(" ");
}
}
private static void AddPropertyTypeName(this RichTextLabel label, IPropertySymbol symbol)
{
label.PushColor(GetSymbolColourByType(symbol.Type));
label.AddText(symbol.Type.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
label.Pop();
label.AddText(" ");
}
private static void AddPropertyName(this RichTextLabel label, IPropertySymbol symbol)
{
label.PushColor(CachedColors.White);
label.AddText(symbol.Name);
label.Pop();
}
private static void AddGetSetAccessors(this RichTextLabel label, IPropertySymbol symbol)
{
label.AddText(" { ");
if (symbol.GetMethod is not null)
{
label.PushColor(CachedColors.KeywordBlue);
label.AddText("get");
label.Pop();
label.PushColor(CachedColors.White);
label.AddText(";");
label.Pop();
label.AddText(" ");
}
if (symbol.SetMethod is {} setMethod)
{
if (setMethod.DeclaredAccessibility != symbol.DeclaredAccessibility)
{
label.PushColor(CachedColors.KeywordBlue);
label.AddText(setMethod.DeclaredAccessibility.ToString().ToLower());
label.Pop();
label.AddText(" ");
}
if (setMethod.IsInitOnly)
{
label.PushColor(CachedColors.KeywordBlue);
label.AddText("init");
label.Pop();
label.PushColor(CachedColors.White);
label.AddText(";");
label.Pop();
}
else
{
label.PushColor(CachedColors.KeywordBlue);
label.AddText("set");
label.Pop();
label.PushColor(CachedColors.White);
label.AddText(";");
label.Pop();
}
label.AddText(" ");
}
label.AddText("}");
}
}