display types better
This commit is contained in:
@@ -175,6 +175,8 @@ public partial class CustomHighlighter : SyntaxHighlighter
|
||||
"xml doc comment - delimiter" => CachedColors.CommentGreen,
|
||||
"xml doc comment - name" => CachedColors.White,
|
||||
"xml doc comment - text" => CachedColors.CommentGreen,
|
||||
"xml doc comment - attribute name" => CachedColors.LightOrangeBrown,
|
||||
"xml doc comment - attribute quotes" => CachedColors.LightOrangeBrown,
|
||||
|
||||
// Misc
|
||||
"excluded code" => CachedColors.Gray,
|
||||
|
||||
@@ -353,10 +353,60 @@ public static partial class SymbolInfoComponents
|
||||
|
||||
private static void AddType(this RichTextLabel label, ITypeSymbol symbol)
|
||||
{
|
||||
var colour = symbol.GetSymbolColourByType();
|
||||
label.PushColor(colour);
|
||||
_ = symbol switch
|
||||
{
|
||||
{SpecialType: not SpecialType.None} => label.AddSpecialType(symbol),
|
||||
INamedTypeSymbol namedTypeSymbol => label.AddNamedType(namedTypeSymbol),
|
||||
ITypeParameterSymbol typeParameterSymbol => label.AddTypeParameter(typeParameterSymbol),
|
||||
_ => label.AddUnknownType(symbol)
|
||||
};
|
||||
}
|
||||
|
||||
private static RichTextLabel AddUnknownType(this RichTextLabel label, ITypeSymbol symbol)
|
||||
{
|
||||
label.PushColor(CachedColors.Orange);
|
||||
label.AddText("[UNKNOWN TYPE]");
|
||||
label.AddText(symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
|
||||
label.Pop();
|
||||
return label;
|
||||
}
|
||||
|
||||
private static RichTextLabel AddSpecialType(this RichTextLabel label, ITypeSymbol symbol)
|
||||
{
|
||||
label.PushColor(CachedColors.KeywordBlue);
|
||||
label.AddText(symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
|
||||
label.Pop();
|
||||
return label;
|
||||
}
|
||||
|
||||
private static RichTextLabel AddNamedType(this RichTextLabel label, INamedTypeSymbol symbol)
|
||||
{
|
||||
label.PushMeta("TODO", RichTextLabel.MetaUnderline.OnHover);
|
||||
var colour = symbol.GetSymbolColourByType();
|
||||
label.PushColor(colour);
|
||||
label.AddText(symbol.Name);
|
||||
label.Pop();
|
||||
if (symbol.TypeArguments.Length is not 0)
|
||||
{
|
||||
label.AddText("<");
|
||||
for (var i = 0; i < symbol.TypeArguments.Length; i++)
|
||||
{
|
||||
var typeArg = symbol.TypeArguments[i];
|
||||
label.AddType(typeArg);
|
||||
if (i < symbol.TypeArguments.Length - 1) label.AddText(", ");
|
||||
}
|
||||
label.AddText(">");
|
||||
}
|
||||
label.Pop(); // meta
|
||||
return label;
|
||||
}
|
||||
|
||||
private static RichTextLabel AddTypeParameter(this RichTextLabel label, ITypeParameterSymbol symbol)
|
||||
{
|
||||
label.PushColor(CachedColors.ClassGreen);
|
||||
label.AddText(symbol.Name);
|
||||
label.Pop();
|
||||
return label;
|
||||
}
|
||||
|
||||
// TODO: handle arrays etc, where there are multiple colours in one type
|
||||
|
||||
@@ -55,10 +55,8 @@ public static partial class SymbolInfoComponents
|
||||
label.Pop();
|
||||
return;
|
||||
}
|
||||
|
||||
label.PushColor(CachedColors.ClassGreen);
|
||||
label.AddText(methodSymbol.ReturnType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
|
||||
label.Pop();
|
||||
|
||||
label.AddType(methodSymbol.ReturnType);
|
||||
}
|
||||
|
||||
private static void AddMethodName(this RichTextLabel label, IMethodSymbol methodSymbol)
|
||||
@@ -204,7 +202,7 @@ public static partial class SymbolInfoComponents
|
||||
foreach (var (index, (typeArgument, typeParameter)) in methodSymbol.TypeArguments.Zip(typeParameters).Index())
|
||||
{
|
||||
label.PushColor(CachedColors.ClassGreen);
|
||||
label.AddText(typeParameter.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
|
||||
label.AddType(typeParameter);
|
||||
label.Pop();
|
||||
label.AddText(" is ");
|
||||
label.AddType(typeArgument);
|
||||
|
||||
Reference in New Issue
Block a user