add named type symbol display

This commit is contained in:
Matt Parker
2025-10-12 12:06:55 +10:00
parent 4732372f27
commit 2145997190
3 changed files with 105 additions and 8 deletions

View File

@@ -127,10 +127,11 @@ public partial class SharpIdeCodeEdit : CodeEdit
var symbolInfoNode = roslynSymbol switch
{
IMethodSymbol methodSymbol => SymbolInfoComponents.GetMethodSymbolInfo(methodSymbol),
INamedTypeSymbol namedTypeSymbol => new Control(),
INamedTypeSymbol namedTypeSymbol => SymbolInfoComponents.GetNamedTypeSymbolInfo(namedTypeSymbol),
IPropertySymbol propertySymbol => SymbolInfoComponents.GetPropertySymbolInfo(propertySymbol),
IFieldSymbol fieldSymbol => SymbolInfoComponents.GetFieldSymbolInfo(fieldSymbol),
IParameterSymbol parameterSymbol => SymbolInfoComponents.GetParameterSymbolInfo(parameterSymbol),
//ILocalSymbol localSymbol => SymbolInfoComponents.GetLocalSymbolInfo(localSymbol),
_ => new Control()
};
popupPanel.AddChild(symbolInfoNode);

View File

@@ -264,21 +264,32 @@ public static partial class SymbolInfoComponents
private static void AddContainingNamespaceAndClass(this RichTextLabel label, ISymbol symbol)
{
if (symbol.ContainingNamespace is null || symbol.ContainingNamespace.IsGlobalNamespace) return;
if (symbol.ContainingNamespace is null || symbol.ContainingNamespace.IsGlobalNamespace) return; // might be wrong
label.Newline();
label.AddText("in class ");
if (symbol.ContainingType is null)
{
label.AddText("in namespace ");
}
else
{
label.AddText("in class ");
}
var namespaces = symbol.ContainingNamespace.ToDisplayString().Split('.');
label.PushMeta("TODO", RichTextLabel.MetaUnderline.OnHover);
foreach (var ns in namespaces)
foreach (var (index, ns) in namespaces.Index())
{
label.PushColor(CachedColors.KeywordBlue);
label.AddText(ns);
label.Pop();
label.AddText(".");
if (index < namespaces.Length - 1) label.AddText(".");
}
if (symbol.ContainingType is not null)
{
label.AddText(".");
label.PushColor(CachedColors.ClassGreen);
label.AddText(symbol.ContainingType.Name);
label.Pop();
}
label.PushColor(CachedColors.ClassGreen);
label.AddText(symbol.ContainingType.Name);
label.Pop();
label.Pop(); // meta
}

View File

@@ -0,0 +1,85 @@
using Godot;
using Microsoft.CodeAnalysis;
namespace SharpIDE.Godot.Features.CodeEditor;
public static partial class SymbolInfoComponents
{
public static Control GetNamedTypeSymbolInfo(INamedTypeSymbol 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.AddStaticModifier(symbol);
label.AddVirtualModifier(symbol);
label.AddAbstractModifier(symbol);
label.AddOverrideModifier(symbol);
label.AddNamedTypeSymbolName(symbol);
label.AddInheritedTypes(symbol);
label.AddContainingNamespaceAndClass(symbol);
label.AddContainingPackage(symbol);
label.Newline();
label.Pop(); // font
label.AddDocs(symbol);
label.Pop();
return label;
}
private static void AddNamedTypeSymbolName(this RichTextLabel label, INamedTypeSymbol symbol)
{
label.PushColor(GetSymbolColourByType(symbol));
label.AddText(symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
label.Pop();
}
private static void AddInheritedTypes(this RichTextLabel label, INamedTypeSymbol symbol)
{
if (symbol.BaseType is not null && symbol.BaseType.SpecialType != SpecialType.System_Object)
{
label.AddText(" : ");
label.PushColor(GetSymbolColourByType(symbol.BaseType));
label.AddText(symbol.BaseType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
label.Pop();
}
if (symbol.Interfaces.Length > 0)
{
if (symbol.BaseType is null || symbol.BaseType.SpecialType == SpecialType.System_Object)
{
label.AddText(" : ");
}
else
{
label.AddText(", ");
}
for (int i = 0; i < symbol.Interfaces.Length; i++)
{
var iface = symbol.Interfaces[i];
label.PushColor(GetSymbolColourByType(iface));
label.AddText(iface.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
label.Pop();
if (i < symbol.Interfaces.Length - 1)
{
label.AddText(", ");
}
}
}
}
private static void AddContainingPackage(this RichTextLabel label, INamedTypeSymbol symbol)
{
var containingModule = symbol.ContainingModule;
if (containingModule is not null)
{
label.Newline();
label.PushColor(CachedColors.White);
label.AddText($"from module {containingModule.Name}");
label.Pop();
}
}
}